UnityExplorer/src/ExplorerCore.cs

132 lines
3.8 KiB
C#
Raw Normal View History

using System;
2021-04-11 20:45:02 +10:00
using System.Collections;
using System.Collections.Generic;
2020-11-23 18:23:25 +11:00
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
using UnityExplorer.UI;
using UnityExplorer.ObjectExplorer;
using UnityExplorer.UI.Panels;
using UnityExplorer.Runtime;
2021-12-02 18:35:46 +11:00
using UniverseLib.Input;
2020-08-07 22:19:03 +10:00
namespace UnityExplorer
2020-08-07 22:19:03 +10:00
{
public static class ExplorerCore
2020-08-07 22:19:03 +10:00
{
public const string NAME = "UnityExplorer";
public const string VERSION = "4.5.0";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer";
2021-01-02 19:38:01 +01:00
public static IExplorerLoader Loader { get; private set; }
public static HarmonyLib.Harmony Harmony { get; } = new HarmonyLib.Harmony(GUID);
/// <summary>
/// Initialize UnityExplorer with the provided Loader implementation.
/// </summary>
public static void Init(IExplorerLoader loader)
2020-08-07 22:19:03 +10:00
{
if (Loader != null)
{
LogWarning("UnityExplorer is already loaded!");
return;
}
Loader = loader;
2020-08-07 22:19:03 +10:00
Log($"{NAME} {VERSION} initializing...");
if (!Directory.Exists(Loader.ExplorerFolder))
Directory.CreateDirectory(Loader.ExplorerFolder);
ConfigManager.Init(Loader.ConfigHandler);
2021-12-02 18:35:46 +11:00
RuntimeHelper.Init();
ExplorerBehaviour.Setup();
2022-01-08 17:56:33 +11:00
UniverseLib.Universe.Init(ConfigManager.Startup_Delay_Time.Value, LateInit, Log, new()
2021-12-02 18:35:46 +11:00
{
Disable_EventSystem_Override = ConfigManager.Disable_EventSystem_Override.Value,
Force_Unlock_Mouse = ConfigManager.Force_Unlock_Mouse.Value,
Unhollowed_Modules_Folder = loader.UnhollowedModulesFolder
});
2021-04-11 20:45:02 +10:00
}
// Do a delayed setup so that objects aren't destroyed instantly.
// This can happen for a multitude of reasons.
// Default delay is 1 second which is usually enough.
2021-12-02 18:35:46 +11:00
private static void LateInit()
2021-04-11 20:45:02 +10:00
{
2021-12-02 18:35:46 +11:00
Log($"Setting up late core features...");
SceneHandler.Init();
2021-04-30 21:34:50 +10:00
Log($"Creating UI...");
2021-05-05 21:27:09 +10:00
2021-05-11 20:23:52 +10:00
UIManager.InitUI();
2021-04-30 21:34:50 +10:00
Log($"{NAME} {VERSION} initialized.");
//InspectorManager.Inspect(typeof(Tests.TestClass));
}
/// <summary>
/// Should be called once per frame.
/// </summary>
public static void Update()
2020-08-07 22:19:03 +10:00
{
UIManager.Update();
2021-12-02 18:35:46 +11:00
// check master toggle
if (InputManager.GetKeyDown(ConfigManager.Master_Toggle.Value))
UIManager.ShowMenu = !UIManager.ShowMenu;
}
2021-06-05 19:36:09 +10:00
#region LOGGING
2021-06-05 19:36:09 +10:00
public static void Log(object message)
2021-04-22 19:12:16 +10:00
=> Log(message, LogType.Log);
2021-06-05 19:36:09 +10:00
public static void LogWarning(object message)
2021-04-22 19:12:16 +10:00
=> Log(message, LogType.Warning);
2021-06-05 19:36:09 +10:00
public static void LogError(object message)
2021-04-22 19:12:16 +10:00
=> Log(message, LogType.Error);
2021-04-22 19:12:16 +10:00
public static void LogUnity(object message, LogType logType)
{
2021-04-22 19:12:16 +10:00
if (!ConfigManager.Log_Unity_Debug.Value)
return;
2021-04-22 19:12:16 +10:00
Log($"[Unity] {message}", logType);
}
private static void Log(object message, LogType logType)
{
string log = message?.ToString() ?? "";
LogPanel.Log(log, logType);
switch (logType)
{
case LogType.Assert:
case LogType.Log:
Loader.OnLogMessage(log);
break;
case LogType.Warning:
Loader.OnLogWarning(log);
break;
case LogType.Error:
case LogType.Exception:
Loader.OnLogError(log);
break;
}
}
2021-06-05 19:36:09 +10:00
#endregion
2020-08-07 22:19:03 +10:00
}
}