il2cpp_bridge_rs/structs/components/physics/
collider.rs1use crate::structs::components::{Component, ComponentTrait};
3use crate::structs::math::Bounds;
4use crate::structs::Vector3;
5use std::ffi::c_void;
6use std::ops::Deref;
7
8#[repr(C)]
9#[derive(Debug, Clone, Copy)]
10pub struct Collider {
11 pub component: Component,
13}
14
15impl ComponentTrait for Collider {
16 fn from_ptr(ptr: *mut c_void) -> Self {
17 Self {
18 component: Component::from_ptr(ptr),
19 }
20 }
21}
22
23impl Deref for Collider {
24 type Target = Component;
25 fn deref(&self) -> &Self::Target {
26 &self.component
27 }
28}
29
30impl Collider {
31 pub unsafe fn from_ptr(ptr: *mut c_void) -> Self {
39 <Self as ComponentTrait>::from_ptr(ptr)
40 }
41
42 pub fn get_bounds(&self) -> Result<Bounds, String> {
47 let mut bounds = Bounds::default();
48 unsafe {
49 self.method("get_bounds_Injected")
50 .ok_or("Method 'get_bounds_Injected' not found")?
51 .call::<()>(&[&mut bounds as *mut Bounds as *mut c_void])?;
52 }
53 Ok(bounds)
54 }
55 pub fn get_enabled(&self) -> Result<bool, String> {
60 unsafe {
61 self.method("get_enabled")
62 .ok_or("Method 'get_enabled' not found")?
63 .call::<bool>(&[])
64 }
65 }
66
67 pub fn set_enabled(&self, value: bool) -> Result<(), String> {
75 unsafe {
76 let mut value_cp = value;
77 self.method("set_enabled")
78 .ok_or("Method 'set_enabled' not found")?
79 .call::<()>(&[&mut value_cp as *mut bool as *mut c_void])?;
80 Ok(())
81 }
82 }
83
84 pub fn get_is_trigger(&self) -> Result<bool, String> {
89 unsafe {
90 self.method("get_isTrigger")
91 .ok_or("Method 'get_isTrigger' not found")?
92 .call::<bool>(&[])
93 }
94 }
95
96 pub fn set_is_trigger(&self, value: bool) -> Result<(), String> {
104 unsafe {
105 let mut value_cp = value;
106 self.method("set_isTrigger")
107 .ok_or("Method 'set_isTrigger' not found")?
108 .call::<()>(&[&mut value_cp as *mut bool as *mut c_void])?;
109 Ok(())
110 }
111 }
112
113 pub fn get_attached_rigidbody(&self) -> Result<super::rigidbody::Rigidbody, String> {
118 unsafe {
119 let ptr = self
120 .method("get_attachedRigidbody")
121 .ok_or("Method 'get_attachedRigidbody' not found")?
122 .call::<*mut c_void>(&[])?;
123
124 if ptr.is_null() {
125 return Err("No attached Rigidbody".to_string());
126 }
127
128 Ok(super::rigidbody::Rigidbody::from_ptr(ptr))
129 }
130 }
131
132 pub fn closest_point(&self, position: Vector3) -> Result<Vector3, String> {
140 unsafe {
141 let mut pos_cp = position;
142 let result = self
143 .method("ClosestPoint")
144 .ok_or("Method 'ClosestPoint' not found")?
145 .call::<Vector3>(&[&mut pos_cp as *mut Vector3 as *mut c_void])?;
146 Ok(result)
147 }
148 }
149}