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
}

 

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-05-31
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2021-06-19
相关资源
相似解决方案