il2cpp_bridge_rs/api/wrappers/
time.rs1use crate::api::cache;
7use crate::structs::core::Class;
8use std::ffi::c_void;
9
10pub struct Time;
12
13impl Time {
14 pub fn get_class() -> Option<Class> {
16 cache::coremodule().class("UnityEngine.Time")
17 }
18
19 pub fn get_time() -> f32 {
21 unsafe {
22 Self::get_class()
23 .and_then(|cls| cls.method(("get_time", 0)))
24 .map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(0.0))
25 .unwrap_or(0.0)
26 }
27 }
28
29 pub fn get_delta_time() -> f32 {
31 unsafe {
32 Self::get_class()
33 .and_then(|cls| cls.method(("get_deltaTime", 0)))
34 .map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(0.0))
35 .unwrap_or(0.0)
36 }
37 }
38
39 pub fn get_fixed_delta_time() -> f32 {
41 unsafe {
42 Self::get_class()
43 .and_then(|cls| cls.method(("get_fixedDeltaTime", 0)))
44 .map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(0.0))
45 .unwrap_or(0.0)
46 }
47 }
48
49 pub fn get_time_scale() -> f32 {
51 unsafe {
52 Self::get_class()
53 .and_then(|cls| cls.method(("get_timeScale", 0)))
54 .map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(1.0))
55 .unwrap_or(1.0)
56 }
57 }
58
59 pub fn set_time_scale(value: f32) {
61 unsafe {
62 if let Some(method) = Self::get_class().and_then(|cls| cls.method(("set_timeScale", 1)))
63 {
64 let _ = method.call::<()>(&[&mut { value } as *mut f32 as *mut c_void]);
65 }
66 }
67 }
68}