2022-05-26 06:19:50 +10:00
|
|
|
|
using UnityExplorer.UI;
|
2021-05-01 20:55:14 +10:00
|
|
|
|
#if CPP
|
2022-06-23 06:03:58 +10:00
|
|
|
|
#if UNHOLLOWER
|
2021-05-01 20:55:14 +10:00
|
|
|
|
using UnhollowerRuntimeLib;
|
2022-06-23 06:03:58 +10:00
|
|
|
|
#else
|
|
|
|
|
using Il2CppInterop.Runtime.Injection;
|
|
|
|
|
#endif
|
2021-05-01 20:55:14 +10:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer
|
|
|
|
|
{
|
|
|
|
|
public class ExplorerBehaviour : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
internal static ExplorerBehaviour Instance { get; private set; }
|
|
|
|
|
|
2022-04-09 18:58:56 +10:00
|
|
|
|
#if CPP
|
2022-04-12 05:20:35 +10:00
|
|
|
|
public ExplorerBehaviour(System.IntPtr ptr) : base(ptr) { }
|
2022-04-09 18:58:56 +10:00
|
|
|
|
#endif
|
|
|
|
|
|
2021-05-01 20:55:14 +10:00
|
|
|
|
internal static void Setup()
|
|
|
|
|
{
|
|
|
|
|
#if CPP
|
|
|
|
|
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-04-09 18:58:56 +10:00
|
|
|
|
GameObject obj = new("ExplorerBehaviour");
|
|
|
|
|
DontDestroyOnLoad(obj);
|
|
|
|
|
obj.hideFlags = HideFlags.HideAndDontSave;
|
2021-05-01 20:55:14 +10:00
|
|
|
|
Instance = obj.AddComponent<ExplorerBehaviour>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void Update()
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.Update();
|
|
|
|
|
}
|
2022-04-24 05:56:47 +10:00
|
|
|
|
|
|
|
|
|
// For editor, to clean up objects
|
|
|
|
|
|
|
|
|
|
internal void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
OnApplicationQuit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal bool quitting;
|
|
|
|
|
|
|
|
|
|
internal void OnApplicationQuit()
|
|
|
|
|
{
|
|
|
|
|
if (quitting) return;
|
|
|
|
|
quitting = true;
|
|
|
|
|
|
|
|
|
|
TryDestroy(UIManager.UIRoot?.transform.root.gameObject);
|
|
|
|
|
|
|
|
|
|
TryDestroy((typeof(Universe).Assembly.GetType("UniverseLib.UniversalBehaviour")
|
|
|
|
|
.GetProperty("Instance", BindingFlags.Static | BindingFlags.NonPublic)
|
|
|
|
|
.GetValue(null, null)
|
|
|
|
|
as Component).gameObject);
|
|
|
|
|
|
|
|
|
|
TryDestroy(this.gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void TryDestroy(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (obj)
|
|
|
|
|
Destroy(obj);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
2021-05-01 20:55:14 +10:00
|
|
|
|
}
|
|
|
|
|
}
|