-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeBundleRestarter.cs
77 lines (69 loc) · 2.41 KB
/
CodeBundleRestarter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Linq;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace CodeBundle
{
/// <summary>
/// Helper to restart application
/// </summary>
public static class CodeBundleRestarter
{
public static void Restart()
{
Debug.Log("Restarting");
var allowedPlatforms = new[]
{
RuntimePlatform.Android,
RuntimePlatform.LinuxEditor,
RuntimePlatform.LinuxPlayer,
RuntimePlatform.WindowsEditor,
RuntimePlatform.WindowsPlayer,
RuntimePlatform.OSXEditor,
RuntimePlatform.OSXPlayer
};
if (!allowedPlatforms.Contains(Application.platform))
{
throw new NotSupportedException($"Platform {Application.platform} not support");
}
if (Application.platform == RuntimePlatform.Android)
{
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
jo.Call("makeRestart");
return;
}
var players = new[]
{RuntimePlatform.WindowsPlayer, RuntimePlatform.LinuxPlayer, RuntimePlatform.OSXPlayer};
if (players.Contains(Application.platform))
{
var endings = new string[]
{
"exe", "x86", "x86_64", "app"
};
var executablePath = Application.dataPath + "/..";
foreach (string file in System.IO.Directory.GetFiles(executablePath))
{
foreach (string ending in endings)
{
if (file.ToLower().EndsWith("." + ending))
{
System.Diagnostics.Process.Start(executablePath + file);
Application.Quit();
return;
}
}
}
return;
}
#if UNITY_EDITOR
if (Application.isEditor)
{
EditorApplication.isPlaying = false;
}
#endif
}
}
}