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# 腳本中的方法

參數一:場景中游戲體名稱

參數二:腳本中方法名

參數三:傳遞參數


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章