iOS开发之Unity调用OC

unity调用OC

OC类代码

// testUnity.h

extern "C"{
    //声明一个方法
    void testUnityFunction(int index, const char *userName);
}
// testUnity.m

extern "C"{
    void testUnityFunction(int index, const char *userName) {
        NSLog(@"接收到来自unity的传参");
    }
}

unity的C#文件代码

#if UNITY_IOS
    //引入声明
    [DllImport("__Internal")]
    static extern void testUnityFunction (int index, string str);
#endif

//实现方法
void Start() 
{
    #if UNITY_IOS    
    testUnityFunction(1, "hello World");
    #endif
}

 

posted @ 2020-05-06 14:07  kawerd  阅读(805)  评论(0编辑  收藏  举报