我统一制作了一个ios插件
//c代码
#include <stdio.h>
typedef int (*callback_t) (int a, int b);
static callback_t my_callback;
void RegisterCallback (callback_t cb)
{
my_callback = cb;
}
int InvokeManagedCode (int a, int b)
{
if (my_callback == NULL){
printf ("Managed code has not initialized this library yet");
abort ();
}
return (*my_callback) (a, b);
}
//C# 统一
public class PluginImport : MonoBehaviour {
delegate int MyCallback1 (int a, int b);
[DllImport ("__Internal")]
extern static void RegisterCallback (MyCallback1 callback1);
[DllImport ("__Internal")]
extern static int InvokeManagedCode (int a, int b);
void Start () {
RegisterCallback(Add); //register call back
int i=InvokeManagedCode(44,4);
Debug.Log("in ios?"+i);
}
static int Add (int a, int b) { return a + b; } //my delegate in C#
static int Sub (int a, int b) { return a - b; }
}
在统一上运行良好,但在 ios 上抛出错误 ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) PluginImport:Add (int,int)' while running with --aot-only。
在(包装器托管到本机)PluginImport:RegisterCallback(PluginImport / MyCallback1)在PluginImport.Start()[0x00000] in:0
(文件名:行:-1)如何在 iOS 设备上的 Unity 内部进行反向原生回调?请帮帮我。</p>