Unity iOS 通讯

C#可以调用C,OC也可以调用C,所以大家通过C代码来互相调用;


Unity --> OC

C#

	#if UNITY_IPHONE
	[DllImport ("__Internal")]    
	private static extern bool FunctionInOC();
	#endif

	public void OnButtonClicked ()
	{
		#if UNITY_IPHONE
		FunctionInOC();
		#endif
	}

Object-C

#if defined (__cplusplus)
extern "C"
{
#endif
    
    void FunctionInOC()
    {
        NSLog(@"FunctionInOC is called.");        
    }
    
#if defined (__cplusplus)
}
#endif



OC --> Unity

- (void)thisIsAnOCFunction {
    UnitySendMessage("GameObjectName", "FunctionName", "Parameter");
}

在任意 Object-C 代码中使用 UnitySendMessage 可直接调用 C# 脚本中的方法

参数一:场景中游戏体名称

参数二:脚本中方法名

参数三:传递参数


你可能感兴趣的:(Unity)