il2cpp_bridge_rs/structs/components/rendering/
shader.rs1use crate::api::cache;
2use crate::structs::collections::Il2cppString;
3use crate::structs::core::Object;
4use std::ffi::c_void;
5use std::ops::Deref;
6
7#[repr(C)]
8#[derive(Debug, Clone, Copy)]
9pub struct Shader {
10 pub object: Object,
11}
12
13impl Shader {
14 pub fn from_ptr(ptr: *mut c_void) -> Self {
15 Self {
16 object: unsafe { Object::from_ptr(ptr) },
17 }
18 }
19}
20
21impl Deref for Shader {
22 type Target = Object;
23 fn deref(&self) -> &Self::Target {
24 &self.object
25 }
26}
27
28impl Shader {
29 pub fn get_class() -> Option<crate::structs::core::Class> {
34 cache::coremodule().class("UnityEngine.Shader")
35 }
36
37 pub fn find(name: &str) -> Option<Self> {
45 unsafe {
46 let string_new_ptr = Il2cppString::new(name);
47 Self::get_class()
48 .and_then(|cls| cls.method(("Find", 1)))
49 .and_then(|method| {
50 method
51 .call::<*mut c_void>(&[string_new_ptr as *mut c_void])
52 .ok()
53 })
54 .filter(|ptr| !ptr.is_null())
55 .map(Self::from_ptr)
56 }
57 }
58
59 pub fn property_to_id(name: &str) -> i32 {
67 unsafe {
68 let string_new_ptr = Il2cppString::new(name);
69 Self::get_class()
70 .and_then(|cls| cls.method(("PropertyToID", 1)))
71 .and_then(|method| method.call::<i32>(&[string_new_ptr as *mut c_void]).ok())
72 .unwrap_or(0)
73 }
74 }
75}