UnityExplorer/src/ExplorerCore.cs

127 lines
3.1 KiB
C#
Raw Normal View History

using System;
2020-11-23 18:23:25 +11:00
using System.IO;
using System.Reflection;
2020-11-23 18:23:25 +11:00
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityExplorer.Core.Config;
using UnityExplorer.Core.Unity;
using UnityExplorer.Core.Input;
using UnityExplorer.Core.Inspectors;
using UnityExplorer.Core.Runtime;
using UnityExplorer.UI;
using UnityExplorer.UI.Main;
using UnityExplorer.UI.Utility;
2020-08-07 22:19:03 +10:00
namespace UnityExplorer
2020-08-07 22:19:03 +10:00
{
public class ExplorerCore
2020-08-07 22:19:03 +10:00
{
public const string NAME = "UnityExplorer";
2021-03-23 16:16:09 +11:00
public const string VERSION = "3.2.7";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer";
2021-01-02 19:38:01 +01:00
2021-03-11 17:57:58 +11:00
public static ExplorerCore Instance { get; private set; }
2021-03-16 18:12:39 +11:00
public static IExplorerLoader Loader =>
2021-01-02 19:38:01 +01:00
#if ML
2021-03-16 18:12:39 +11:00
ExplorerMelonMod.Instance;
2021-01-02 19:38:01 +01:00
#elif BIE
2021-03-16 18:12:39 +11:00
ExplorerBepInPlugin.Instance;
#elif STANDALONE
2021-03-16 18:12:39 +11:00
ExplorerStandalone.Instance;
2021-01-02 19:38:01 +01:00
#endif
2021-03-16 18:12:39 +11:00
public static string EXPLORER_FOLDER => Loader.ExplorerFolder;
public ExplorerCore()
2020-08-07 22:19:03 +10:00
{
if (Instance != null)
{
Log("An instance of Explorer is already active!");
return;
}
2020-08-07 22:19:03 +10:00
Instance = this;
2021-03-16 18:12:39 +11:00
RuntimeProvider.Init();
2021-03-16 18:12:39 +11:00
if (!Directory.Exists(EXPLORER_FOLDER))
Directory.CreateDirectory(EXPLORER_FOLDER);
2021-03-11 17:57:58 +11:00
ExplorerConfig.OnLoad();
InputManager.Init();
CursorUnlocker.Init();
2021-03-11 17:57:58 +11:00
UIManager.ShowMenu = true;
2020-10-08 06:15:42 +11:00
Log($"{NAME} {VERSION} initialized.");
}
public static void Update()
2020-08-07 22:19:03 +10:00
{
2021-03-11 17:57:58 +11:00
UIManager.CheckUIInit();
if (InspectUnderMouse.Enabled)
InspectUnderMouse.UpdateInspect();
else
2021-03-11 17:57:58 +11:00
UIManager.Update();
}
2021-03-16 18:12:39 +11:00
public void OnUnityLog(string message, string stackTrace, LogType type)
{
if (!DebugConsole.LogUnity)
return;
message = $"[UNITY] {message}";
switch (type)
{
case LogType.Assert:
case LogType.Log:
Log(message, true);
break;
case LogType.Warning:
LogWarning(message, true);
break;
case LogType.Exception:
case LogType.Error:
LogError(message, true);
break;
}
}
public static void Log(object message, bool unity = false)
{
DebugConsole.Log(message?.ToString());
if (unity)
return;
2021-03-11 17:57:58 +11:00
Loader.OnLogMessage(message);
}
public static void LogWarning(object message, bool unity = false)
{
DebugConsole.Log(message?.ToString(), "FFFF00");
if (unity)
return;
2021-03-11 17:57:58 +11:00
Loader.OnLogWarning(message);
}
public static void LogError(object message, bool unity = false)
{
DebugConsole.Log(message?.ToString(), "FF0000");
if (unity)
return;
2021-03-11 17:57:58 +11:00
Loader.OnLogError(message);
}
2020-08-07 22:19:03 +10:00
}
}