Unity安卓端重启游戏
关掉游戏,然后再重新启动。不是重新加载入口场景public void RestartAndroid(){if (Application.isEditor) return;using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){const int kIntent_FLAG_ACTIVITY_CL
·
关掉游戏,然后再重新启动。不是重新加载入口场景
public void RestartAndroid()
{
if (Application.isEditor) return;
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
currentActivity.Call("startActivity", intent);
currentActivity.Call("finish");
var process = new AndroidJavaClass("android.os.Process");
int pid = process.CallStatic<int>("myPid");
process.CallStatic("killProcess", pid);
}
}
Sample工程:https://download.csdn.net/download/qq_33205561/80270378
更多推荐
已为社区贡献2条内容
所有评论(0)