use crate::api::cache;
use crate::structs::core::Class;
use std::ffi::c_void;
pub struct Time;
impl Time {
pub fn get_class() -> Option<Class> {
cache::coremodule().class("UnityEngine.Time")
}
pub fn get_time() -> f32 {
unsafe {
Self::get_class()
.and_then(|cls| cls.method(("get_time", 0)))
.map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(0.0))
.unwrap_or(0.0)
}
}
pub fn get_delta_time() -> f32 {
unsafe {
Self::get_class()
.and_then(|cls| cls.method(("get_deltaTime", 0)))
.map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(0.0))
.unwrap_or(0.0)
}
}
pub fn get_fixed_delta_time() -> f32 {
unsafe {
Self::get_class()
.and_then(|cls| cls.method(("get_fixedDeltaTime", 0)))
.map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(0.0))
.unwrap_or(0.0)
}
}
pub fn get_time_scale() -> f32 {
unsafe {
Self::get_class()
.and_then(|cls| cls.method(("get_timeScale", 0)))
.map(|method| method.call::<f32>(&[] as &[*mut c_void]).unwrap_or(1.0))
.unwrap_or(1.0)
}
}
pub fn set_time_scale(value: f32) {
unsafe {
if let Some(method) = Self::get_class().and_then(|cls| cls.method(("set_timeScale", 1)))
{
let _ = method.call::<()>(&[&mut { value } as *mut f32 as *mut c_void]);
}
}
}
}