近来 在做AR
初次接触到 Unity3D ,C# 语言写的,也不是很懂
经过近2天的摸索,终于搞通了两者的交互,特整理此文,以备注
直接上代码
c#
void OnClick(){
AndroidJavaClass androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass jc = new AndroidJavaClass("com.fanoi.ARshuiguo.UnityEntranceActivity");
jo.CallStatic("UnityCallAndroid",jo);
}
java
public static void UnityCallAndroid(Activity activity)
{
Log.d("=======================", "testetstest");
// Creating an intent with the current activity and the activity we wish to start
Intent myIntent = new Intent(activity, EntranceActivity.class);
activity.startActivity(myIntent);
}
AndroidManifest.xml
<activity
android:name="com.fanoi.ARshuiguo.UnityEntranceActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
android:screenOrientation="portrait"
android:launchMode="singleTask"
>
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
<meta-data
android:name="unityplayer.ForwardNativeEventsToDalvik"
android:value="false" />
</activity>