unity提供AndroidJavaClass(https://docs.unity3d.com/ScriptReference/AndroidJavaClass.html点击打开链接)和AndroidJavaObject(https://docs.unity3d.com/ScriptReference/AndroidJavaObject.html点击打开链接)类让我们使用
1.unity调用java
(1)获取JavaObject对象
#if UNITY_ANDROID && !UNITY_EDITOR
private static AndroidJavaClass androidJavaClass = null;
private static AndroidJavaObject androidJavaObject = null;
androidJavaClass=new AndroidJavaClass("com.example.MyClass"); //android包名类名
androidJavaObject = androidJavaClass.GetStatic<AndroidJavaObject>("Instance");
#endif
(2)调用JAVA方法
#if UNITY_ANDROID && !UNITY_EDITOR
if(androidJavaObject!=null)
{
androidJavaObject.Call("JavaMethod",strParam,intParam);
}
#endif
如需安卓二次开发,需在安卓工程中import com.unity3d.player.UnityPlayer 而这个类在Unity的AndroidPlayer的classes.jar中,在unity安装目录找到此jar放到安卓工程中
打包成安卓工程需勾选此选项