il2cpp_bridge_rs/structs/components/physics/
rigidbody.rs1use crate::structs::components::{Component, ComponentTrait};
3use crate::structs::Vector3;
4use std::ffi::c_void;
5use std::ops::Deref;
6
7#[repr(C)]
8#[derive(Debug, Clone, Copy)]
9pub struct Rigidbody {
10 pub component: Component,
12}
13
14impl ComponentTrait for Rigidbody {
15 fn from_ptr(ptr: *mut c_void) -> Self {
16 Self {
17 component: Component::from_ptr(ptr),
18 }
19 }
20}
21
22impl Deref for Rigidbody {
23 type Target = Component;
24 fn deref(&self) -> &Self::Target {
25 &self.component
26 }
27}
28
29#[repr(i32)]
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
31pub enum ForceMode {
32 Force = 0,
34 Acceleration = 5,
36 Impulse = 1,
38 VelocityChange = 2,
40}
41
42impl Rigidbody {
43 pub fn get_detect_collisions(&self) -> Result<bool, String> {
48 unsafe {
49 let result = self
50 .method("get_detectCollisions")
51 .ok_or("Method 'get_detectCollisions' not found")?
52 .call::<bool>(&[])?;
53 Ok(result)
54 }
55 }
56
57 pub fn set_detect_collisions(&self, value: bool) -> Result<(), String> {
65 unsafe {
66 self.method("set_detectCollisions")
67 .ok_or("Method 'set_detectCollisions' not found")?
68 .call::<()>(&[&value as *const bool as *mut c_void])?;
69 Ok(())
70 }
71 }
72
73 pub fn get_velocity(&self) -> Result<Vector3, String> {
78 unsafe {
79 let result = self
80 .method("get_velocity")
81 .ok_or("Method 'get_velocity' not found")?
82 .call::<Vector3>(&[])?;
83 Ok(result)
84 }
85 }
86
87 pub fn set_velocity(&self, value: Vector3) -> Result<(), String> {
95 unsafe {
96 self.method("set_velocity")
97 .ok_or("Method 'set_velocity' not found")?
98 .call::<()>(&[&value as *const Vector3 as *mut c_void])?;
99 Ok(())
100 }
101 }
102 pub fn add_force(&self, force: Vector3, mode: ForceMode) -> Result<(), String> {
111 unsafe {
112 let mut force_cp = force;
113 let mut mode_cp = mode as i32;
114 let params = &[
115 &mut force_cp as *mut Vector3 as *mut c_void,
116 &mut mode_cp as *mut i32 as *mut c_void,
117 ];
118 self.method(("AddForce", 2))
119 .ok_or("Method 'AddForce' not found")?
120 .call::<()>(params)?;
121 Ok(())
122 }
123 }
124
125 pub fn get_mass(&self) -> Result<f32, String> {
130 unsafe {
131 self.method("get_mass")
132 .ok_or("Method 'get_mass' not found")?
133 .call::<f32>(&[])
134 }
135 }
136
137 pub fn set_mass(&self, value: f32) -> Result<(), String> {
145 unsafe {
146 let mut value_cp = value;
147 self.method("set_mass")
148 .ok_or("Method 'set_mass' not found")?
149 .call::<()>(&[&mut value_cp as *mut f32 as *mut c_void])?;
150 Ok(())
151 }
152 }
153
154 pub fn get_drag(&self) -> Result<f32, String> {
159 unsafe {
160 self.method("get_drag")
161 .ok_or("Method 'get_drag' not found")?
162 .call::<f32>(&[])
163 }
164 }
165
166 pub fn set_drag(&self, value: f32) -> Result<(), String> {
174 unsafe {
175 let mut value_cp = value;
176 self.method("set_drag")
177 .ok_or("Method 'set_drag' not found")?
178 .call::<()>(&[&mut value_cp as *mut f32 as *mut c_void])?;
179 Ok(())
180 }
181 }
182
183 pub fn get_angular_drag(&self) -> Result<f32, String> {
188 unsafe {
189 self.method("get_angularDrag")
190 .ok_or("Method 'get_angularDrag' not found")?
191 .call::<f32>(&[])
192 }
193 }
194
195 pub fn set_angular_drag(&self, value: f32) -> Result<(), String> {
203 unsafe {
204 let mut value_cp = value;
205 self.method("set_angularDrag")
206 .ok_or("Method 'set_angularDrag' not found")?
207 .call::<()>(&[&mut value_cp as *mut f32 as *mut c_void])?;
208 Ok(())
209 }
210 }
211
212 pub fn get_is_kinematic(&self) -> Result<bool, String> {
217 unsafe {
218 self.method("get_isKinematic")
219 .ok_or("Method 'get_isKinematic' not found")?
220 .call::<bool>(&[])
221 }
222 }
223
224 pub fn set_is_kinematic(&self, value: bool) -> Result<(), String> {
232 unsafe {
233 let mut value_cp = value;
234 self.method("set_isKinematic")
235 .ok_or("Method 'set_isKinematic' not found")?
236 .call::<()>(&[&mut value_cp as *mut bool as *mut c_void])?;
237 Ok(())
238 }
239 }
240
241 pub fn get_use_gravity(&self) -> Result<bool, String> {
246 unsafe {
247 self.method("get_useGravity")
248 .ok_or("Method 'get_useGravity' not found")?
249 .call::<bool>(&[])
250 }
251 }
252
253 pub fn set_use_gravity(&self, value: bool) -> Result<(), String> {
261 unsafe {
262 let mut value_cp = value;
263 self.method("set_useGravity")
264 .ok_or("Method 'set_useGravity' not found")?
265 .call::<()>(&[&mut value_cp as *mut bool as *mut c_void])?;
266 Ok(())
267 }
268 }
269}