Unity3D 与 iOS交互

Unity C# 代码

[DllImport("__Internal")] 
// 在Unity3D中声明这个方法
private static extern void _AYVM_Init(string unityObject,string UnityFunSucces, string UnityFunFail );

Objective-C中的桥接文件

#import 

void SendMessage(const char*unityObjName,const char*successCallback,const char*msg){
  //将信息传给Unity
  UnitySendMessage(unityObjName, successCallback, msg);
}
// Unity 3D中将调用_AYVM_Init
void _AYVM_Init(const char* unityObject,const char* UnityFunSucces,const char* UnityFunFail){
  // iOS中定义的接口
  AYVM_Init(unityObject, UnityFunSucces, UnityFunFail);
  AYVM_setUnityCallBack(SendMessage);
}

Objective-C中的接口文件

typedef void (*AYVM_CALLBACK)(const char *cunityObj,const char* unityFunSucces,const char* msg);

/** init 函数 */
void AYVM_Init(const char* unityObject,const char* UnityFunSucces,const char* UnityFunFail);

/** 1.0 初始化以后,需要设置回调函数 */
void AYVM_setUnityCallBack(AYVM_CALLBACK unityMsg);

你可能感兴趣的:(Unity3D 与 iOS交互)