当前位置:网站首页>C # uses monopinvokecallback to directly call back C # function
C # uses monopinvokecallback to directly call back C # function
2022-06-30 05:10:00 【Shannan HSY】
iOS Code :Test.mm
char* TestMakeCString(NSString *str) { const char* string = [str UTF8String]; if (string == NULL) { return NULL; } char* res = (char*)malloc(strlen(string) + 1); strcpy(res, string); return res; } extern "C"{ typedef void (*TestCallback)(const char*eventName); TestCallback _myCallback; void _TestInit(TestCallback callback){ _myCallback=callback; } } @implementation Test -(void) test{ _myCallback(TestMakeCString(@"complete")); } @end
C# Code :test.csusing System.Runtime.InteropServices; public class Test{ public delegate void EventHandler(string eventName, string msg); public event EventHandler callbackHandler; internal delegate void TestCallBack(string eventName); [DllImport("__Internal")] private static extern void _TestInit(TestCallBack callback); [MonoPInvokeCallback(typeof(TestCallBack))] public static void onCallBack(string eventName){ if(eventName=="complete"){ //do something if(callbackHandler!=null)callbackHandler(eventName,"HIJK"); } } public static Test _instance; public static Test getInstance(){ if(_instance==null){ _instance=new Test(); } return _instance; } // Initial interface public void init(){ _TestInit(onCallBack); } }
test demo:Test test=Test.getInstance() test.init(); test.callbackHandler+=handler; void handler(string eventName,string msg){ //do something }
边栏推荐
- Some books you should not miss when you are new to the workplace
- MinGW-w64下载文件失败the file has been downloaded incorrectly!
- Li Kou 2049: count the number of nodes with the highest score
- Force buckle 349 Intersection of two arrays
- Draw on screen border in Commodore 64
- The file has been downloaded incorrectly!
- Unity + hololens publishing settings
- LXC 和 LXD 容器总结
- Pytorchcnn image recognition and classification model training framework
- Unity publishing /build settings
猜你喜欢

Harbor API 2.0 query

Unity publishing /build settings
![[vcs+verdi joint simulation] ~ take the counter as an example](/img/fb/214a4e65c53503ecbc38a5e43523cf.png)
[vcs+verdi joint simulation] ~ take the counter as an example

Records of some problems encountered during unity development (continuously updated)

Unity script life cycle and execution sequence

力扣209. 长度最小的子数组

redis集群概念

Unity is associated with vs. there is a compiler problem when opening

Parkour demo

力扣704. 二分查找
随机推荐
力扣59. 螺旋矩阵 II
PWN入门(2)栈溢出基础
Create transfer generation point
Tcp/ip protocol details Volume I (Reading Guide)
Force buckle 59 Spiral matrix II
Force buckle 349 Intersection of two arrays
Unity project hosting platform plasticscm (learn to use 2)
Ugui uses its own function to realize reverse mask
Unity project hosting platform plasticscm (learn to use 1)
Revit二次開發---未打開項目使用面板功能
力扣589:N 叉树的前序遍历
JPA composite primary key usage
Unity a* road finding force planning
Under what conditions does the Z-index attribute expire?
Special folders in unity3d and their meanings
Unity packaging and publishing webgl error reason exception: failed building webgl player
ParticleSystem in the official Manual of unity_ Collision module
Unity animator does not clip animation to play animation in segments
Unity scroll view element drag and drop to automatically adsorb centering and card effect
Revit二次开发---未打开项目使用面板功能