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), }; 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; } [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); } }