il2cpp_bridge_rs/structs/components/rendering/
renderer.rs1use super::material::Material;
3use crate::structs::collections::Il2cppArray;
4use crate::structs::components::{Component, ComponentTrait};
5use crate::structs::math::Bounds;
6use std::ffi::c_void;
7use std::ops::Deref;
8
9#[repr(C)]
10#[derive(Debug, Clone, Copy)]
11pub struct Renderer {
12 pub component: Component,
14}
15
16impl ComponentTrait for Renderer {
17 fn from_ptr(ptr: *mut c_void) -> Self {
18 Self {
19 component: Component::from_ptr(ptr),
20 }
21 }
22}
23
24impl Deref for Renderer {
25 type Target = Component;
26 fn deref(&self) -> &Self::Target {
27 &self.component
28 }
29}
30
31impl Renderer {
32 pub fn get_bounds(&self) -> Result<Bounds, String> {
37 let mut bounds = Bounds::default();
38 unsafe {
39 self.method("get_bounds_Injected")
40 .ok_or("Method 'get_bounds_Injected' not found")?
41 .call::<()>(&[&mut bounds as *mut Bounds as *mut c_void])?;
42 }
43 Ok(bounds)
44 }
45
46 pub fn get_material(&self) -> Result<Material, String> {
51 unsafe {
52 let ptr = self
53 .method(("get_material", 0))
54 .ok_or("Method 'get_material' not found")?
55 .call::<*mut c_void>(&[])?;
56 if ptr.is_null() {
57 return Err("Material is null".to_string());
58 }
59 Ok(Material::from_ptr(ptr))
60 }
61 }
62
63 pub fn set_material(&self, material: Material) -> Result<(), String> {
71 unsafe {
72 self.method(("set_material", 1))
73 .ok_or("Method 'set_material' not found")?
74 .call::<()>(&[material.object.ptr as *mut c_void])?;
75 }
76 Ok(())
77 }
78
79 pub fn get_materials(&self) -> Result<Vec<Material>, String> {
84 unsafe {
85 let ptr = self
86 .method(("get_materials", 0))
87 .ok_or("Method 'get_materials' not found")?
88 .call::<*mut Il2cppArray<*mut c_void>>(&[])?;
89
90 if ptr.is_null() {
91 return Ok(Vec::new());
92 }
93
94 Ok((*ptr)
95 .to_vector()
96 .into_iter()
97 .filter(|&p| !p.is_null())
98 .map(Material::from_ptr)
99 .collect())
100 }
101 }
102}