傳統的UnityPlayer.UnitySendMessage性能較差,在Android或IOS向Unity高頻對話中效率較差,所以通過Android或ios直接呼叫C#物件效果更好,
C#代碼
using System.Runtime.InteropServices;
using AOT;
using UnityEngine;
public class UnityTest : MonoBehaviour {
public delegate void DebugTest (string text); //宣告Callback型別
[DllImport ("__Internal")]
static extern void callBackInit (DebugTest debugEvent);
//Window系統去掉關鍵詞前綴[MonoPInvokeCallback (typeof (DebugTest))],ios必須此關鍵詞,
[MonoPInvokeCallback (typeof (DebugTest))] public static void DebugTestEvent (string text) {
Debug.Log (text);
}
}
向C#暴露的ios Test.h檔案
typedef void (*DebugTest)(string text);
extern "C"{
extern void callBackInit(DebugTest debugEvent);
}
Test.m 檔案
#include "Toast.h"
void callBackInit(DebugTest debugEvent){
debugEvent("呼叫成功!");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/196377.html
標籤:python
上一篇:Android 9 禁用按住電源鍵+音量加鍵進入工廠測驗(recovery模式)功能
下一篇:Flutter 插件開發
