using System; using System.IO; using System.Linq; using System.Runtime.InteropServices; using AOT; using UnityEngine; public class ModCalls : CallbackHandler { private readonly UniQuake uq; public ModCalls(UniQuake uniQuake) { uq = uniQuake; var callbacks = new Callbacks { target = SelfPtr, ModUploadModel = CreateCallback(Callback_ModUploadModel), }; RegisterCallbacks(callbacks); } /// /// This matches struct unity_syscalls_s from uniquake.h in native code. /// [StructLayout(LayoutKind.Sequential, Pack = 0)] private class Callbacks { public IntPtr target; public IntPtr ModUploadModel; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void ModUploadModelCallback(IntPtr target, QModel model, QAliasHeader header, IntPtr frames); [MonoPInvokeCallback(typeof(ModUploadModelCallback))] private static void Callback_ModUploadModel(IntPtr target, QModel model, QAliasHeader header, IntPtr frames) { if (header != null) header.frames = frames.ToStructArray(header.numFrames); GetSelf(target).UploadModel(model, header); } private void UploadModel(QModel model, QAliasHeader header) { Debug.Log($"Model '{model?.name}' of type {model?.type}, num frames = {header?.numFrames}"); if (header?.frames != null) { string str = string.Join(", ", header.frames.Select(f => f.name)); Debug.Log($"Frame list: {str}"); } } }