You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
986 B
28 lines
986 B
using UnityEngine;
|
|
|
|
public static class AndroidJava
|
|
{
|
|
#if PLATFORM_ANDROID
|
|
static readonly string _pluginInstanceName = "PluginInstance";
|
|
|
|
public static bool InitPluginInstance(string packageName, out AndroidJavaObject result)
|
|
{
|
|
Debug.Log("try get unity player");
|
|
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
|
{
|
|
Debug.Log("get unity player success");
|
|
Debug.Log("try get unity activity");
|
|
using (var unityActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
|
|
{
|
|
Debug.Log("get unity activity success");
|
|
using (result = new AndroidJavaObject(packageName + "." + _pluginInstanceName))
|
|
{
|
|
if (result is null) return false;
|
|
result.CallStatic("SetUnityActivity", unityActivity);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|