Skip to main content

unity_native_plugin/
log.rs

1use crate::interface::UnityInterface;
2use std::ffi::CStr;
3use unity_native_plugin_sys::*;
4
5#[repr(u32)]
6#[derive(Copy, Clone, PartialEq, Eq, Debug)]
7pub enum LogType {
8    Error = UnityLogType_kUnityLogTypeError,
9    Warning = UnityLogType_kUnityLogTypeWarning,
10    Log = UnityLogType_kUnityLogTypeLog,
11    Exception = UnityLogType_kUnityLogTypeException,
12}
13
14define_unity_interface!(
15    UnityLog,
16    unity_native_plugin_sys::IUnityLog,
17    0x9E7507FA5B444D5D_u64,
18    0x92FB979515EA83FC_u64
19);
20
21pub trait UnityLogInterface {
22    fn log(&self, log_type: LogType, message: &CStr, file_name: &CStr, file_line: i32);
23}
24
25pub use UnityLogInterface as IUnityLog;
26
27impl UnityLogInterface for UnityLog {
28    fn log(&self, log_type: LogType, message: &CStr, file_name: &CStr, file_line: i32) {
29        unsafe {
30            self.interface().Log.expect("Log")(
31                log_type as UnityLogType,
32                message.as_ptr(),
33                file_name.as_ptr(),
34                file_line,
35            );
36        }
37    }
38}