標籤:
1、Unity調iOS的方法
在首頁的viewcontroller裡面實現方法
void _PressButton3(const char *args)
{
// UnityAppController *unityapp = (UnityAppController *)[UIApplication sharedApplication].delegate;
// [unityapp ShowWindowssubview];
}
在Unity裡面 直接調用 _PressButton3(content);
2、iOS與Unity互動,傳值
UnitySendMessage("Scripts", [@"Function" UTF8String], [@"Parameters" UTF8String]);
3 . unity調android裡面的方法
在初始化UnityPlayer的Activity中添加方法,如下:
/**
* 測試Unity調用Android的方法
*/
public void testMethod(String param){
System.out.println("參數為:"+param);
}
對於提供的方法,不可以進行UI操作,因為Unity3D對於android的UI線程來說,只是個子線程,如果要進行UI操作,可以使用Handler發訊息。
.在Unity工程中,利用c#檔案來書寫,Unity調用的代碼:
public static void ActivateShareImage(string content)
{
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
_PressButton3(content);
}
else if (Application.platform == RuntimePlatform.Android)
{
UISystem.Console("test method!");
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
jo.Call("testMethod", "unity");
}
else
{
}
}
4、android與unity互動
UnityPlayer.UnitySendMessage("Scripts", "Function", "Parameters");
unity與iOS、Android互動