using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using AOT; using UnityEngine; using UnityEngine.Profiling; public partial class GameModule : CallbackHandler { private void BuildCallbacks() { var callbacks = new Callbacks { SetEntityModel = CreateCallback(Callback_GameSetEntityModel), SetEntityTransform = CreateCallback(Callback_GameSetEntityTransform), RemoveEntity = CreateCallback(Callback_GameRemoveEntity), UpdateEntityAnimation = CreateCallback(Callback_GameUpdateEntityAnimation), SetEntitySkin = CreateCallback(Callback_GameSetEntitySkin), }; RegisterCallbacks(callbacks); } /// /// This matches unity_gamecalls_t from mod_uniquake.c in native code. /// [StructLayout(LayoutKind.Sequential, Pack = 0)] private class Callbacks { public IntPtr SetEntityModel; public IntPtr SetEntityTransform; public IntPtr RemoveEntity; public IntPtr UpdateEntityAnimation; public IntPtr SetEntitySkin; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameSetEntityModelCallback(IntPtr target, int entityNum, [MarshalAs(UnmanagedType.LPStr)] string modelName); [MonoPInvokeCallback(typeof(GameSetEntityModelCallback))] private static void Callback_GameSetEntityModel(IntPtr target, int entityNum, string modelName) { Profiler.BeginSample("GameSetEntityModel"); GetSelf(target).SetEntityModel(entityNum, modelName); Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameSetEntityTransformCallback(IntPtr target, int entityNum, ref QVec3 origin, ref QVec3 angles); [MonoPInvokeCallback(typeof(GameSetEntityTransformCallback))] private static void Callback_GameSetEntityTransform(IntPtr target, int entityNum, ref QVec3 origin, ref QVec3 angles) { Profiler.BeginSample("GameSetEntityTransform"); GetSelf(target).SetEntityTransform(entityNum, origin, angles); Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameRemoveEntityCallback(IntPtr target, int entityNum); [MonoPInvokeCallback(typeof(GameRemoveEntityCallback))] private static void Callback_GameRemoveEntity(IntPtr target, int entityNum) { Profiler.BeginSample("GameRemoveEntity"); GetSelf(target).RemoveEntity(entityNum); Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameUpdateEntityAnimationCallback(IntPtr target, int entityNum, int pose1, int pose2, float blend); [MonoPInvokeCallback(typeof(GameUpdateEntityAnimationCallback))] private static void Callback_GameUpdateEntityAnimation(IntPtr target, int entityNum, int pose1, int pose2, float blend) { Profiler.BeginSample("GameUpdateEntityAnimation"); GetSelf(target).UpdateEntityAnimation(entityNum, pose1, pose2, blend); Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameSetEntitySkinCallback(IntPtr target, int entityNum, int skinNum); [MonoPInvokeCallback(typeof(GameSetEntitySkinCallback))] private static void Callback_GameSetEntitySkin(IntPtr target, int entityNum, int skinNum) { Profiler.BeginSample("GameSetEntitySkin"); GetSelf(target).SetEntitySkin(entityNum, skinNum); Profiler.EndSample(); } }