unity_native_plugin/
interface.rs1use unity_native_plugin_sys::*;
2
3pub trait UnityInterface {
4 fn get_interface_guid() -> UnityInterfaceGUID;
5 fn new(interface: *const IUnityInterface) -> Self;
6}
7
8static mut UNITY_INTERFACES: Option<UnityInterfaces> = None;
9
10pub struct UnityInterfaces {
11 interfaces: *mut unity_native_plugin_sys::IUnityInterfaces,
12}
13
14impl UnityInterfaces {
15 pub fn get() -> &'static UnityInterfaces {
16 unsafe { UNITY_INTERFACES.as_ref().unwrap() }
17 }
18
19 pub fn set_native_unity_interfaces(interfaces: *mut unity_native_plugin_sys::IUnityInterfaces) {
20 unsafe {
21 UNITY_INTERFACES = if !interfaces.is_null() {
22 Some(UnityInterfaces { interfaces })
23 } else {
24 None
25 }
26 }
27 }
28
29 pub fn interface<T: UnityInterface>(&self) -> Option<T> {
30 unsafe {
31 if let Some(intf) = (&*self.interfaces).GetInterfaceSplit {
32 let guid = T::get_interface_guid();
33 let r = intf(guid.m_GUIDHigh, guid.m_GUIDLow);
34 if !r.is_null() {
35 return Some(T::new(r));
36 }
37 }
38 None
39 }
40 }
41}