using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using AOT; using UnityEngine; public partial class GameModule : CallbackHandler { private void BuildCallbacks() { var callbacks = new Callbacks { target = TargetPtr, 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 target; 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) { GetSelf(target).SetEntityModel(entityNum, modelName); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameSetEntityTransformCallback(IntPtr target, int entityNum, QVec3 origin, QVec3 angles); [MonoPInvokeCallback(typeof(GameSetEntityTransformCallback))] private static void Callback_GameSetEntityTransform(IntPtr target, int entityNum, QVec3 origin, QVec3 angles) { GetSelf(target).SetEntityTransform(entityNum, origin, angles); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameRemoveEntityCallback(IntPtr target, int entityNum); [MonoPInvokeCallback(typeof(GameRemoveEntityCallback))] private static void Callback_GameRemoveEntity(IntPtr target, int entityNum) { GetSelf(target).RemoveEntity(entityNum); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void GameUpdateEntityAnimationCallback(IntPtr target, int entityNum, float frameNum); [MonoPInvokeCallback(typeof(GameUpdateEntityAnimationCallback))] private static void Callback_GameUpdateEntityAnimation(IntPtr target, int entityNum, float frameNum) { GetSelf(target).UpdateEntityAnimation(entityNum, frameNum); } [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) { GetSelf(target).SetEntitySkin(entityNum, skinNum); } }