UnityExplorer/src/ExplorerCore.cs

140 lines
3.3 KiB
C#
Raw Normal View History

2020-10-14 20:47:19 +11:00
using System.Collections;
using System.Linq;
using Explorer.Config;
2020-10-08 06:15:42 +11:00
using Explorer.UI;
using Explorer.UI.Inspectors;
using Explorer.UI.Main;
using Explorer.UI.Shared;
using UnityEngine;
2020-08-07 22:19:03 +10:00
namespace Explorer
{
public class ExplorerCore
2020-08-07 22:19:03 +10:00
{
2020-10-08 06:15:42 +11:00
public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")";
public const string VERSION = "2.0.7";
2020-09-27 22:52:08 +10:00
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.explorer";
public const string PLATFORM =
#if CPP
2020-09-27 22:52:08 +10:00
"Il2Cpp";
#else
2020-09-27 22:52:08 +10:00
"Mono";
#endif
public const string MODLOADER =
#if ML
"MelonLoader";
#else
"BepInEx";
#endif
public static ExplorerCore Instance { get; private set; }
2020-08-07 22:19:03 +10:00
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;
ModConfig.OnLoad();
2020-08-07 22:19:03 +10:00
new MainMenu();
new WindowManager();
InputManager.Init();
2020-10-08 06:15:42 +11:00
ForceUnlockCursor.Init();
2020-10-08 06:15:42 +11:00
ShowMenu = true;
Log($"{NAME} initialized.");
2020-08-07 22:19:03 +10:00
}
public static bool ShowMenu
2020-08-07 22:19:03 +10:00
{
get => m_showMenu;
set => SetShowMenu(value);
2020-08-07 22:19:03 +10:00
}
public static bool m_showMenu;
2020-08-07 22:19:03 +10:00
private static void SetShowMenu(bool show)
{
m_showMenu = show;
2020-10-08 06:15:42 +11:00
ForceUnlockCursor.UpdateCursorControl();
}
public static void Update()
2020-08-07 22:19:03 +10:00
{
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
2020-08-07 22:19:03 +10:00
{
ShowMenu = !ShowMenu;
}
if (ShowMenu)
{
ForceUnlockCursor.Update();
InspectUnderMouse.Update();
2020-08-12 03:51:47 +10:00
2020-08-07 22:19:03 +10:00
MainMenu.Instance.Update();
WindowManager.Instance.Update();
}
}
public static void OnGUI()
2020-08-07 22:19:03 +10:00
{
if (!ShowMenu) return;
var origSkin = GUI.skin;
GUI.skin = UIStyles.WindowSkin;
2020-08-07 22:19:03 +10:00
MainMenu.Instance.OnGUI();
WindowManager.Instance.OnGUI();
InspectUnderMouse.OnGUI();
if (!ResizeDrag.IsMouseInResizeArea && WindowManager.IsMouseInWindow)
{
InputManager.ResetInputAxes();
}
GUI.skin = origSkin;
}
public static void OnSceneChange()
{
ScenePage.Instance?.OnSceneChange();
SearchPage.Instance?.OnSceneChange();
}
2020-10-08 06:15:42 +11:00
public static void Log(object message)
{
#if ML
MelonLoader.MelonLogger.Log(message?.ToString());
#else
ExplorerBepInPlugin.Logging?.LogMessage(message?.ToString());
#endif
}
2020-10-08 06:15:42 +11:00
public static void LogWarning(object message)
{
#if ML
MelonLoader.MelonLogger.LogWarning(message?.ToString());
#else
ExplorerBepInPlugin.Logging?.LogWarning(message?.ToString());
#endif
}
2020-10-08 06:15:42 +11:00
public static void LogError(object message)
{
#if ML
MelonLoader.MelonLogger.LogError(message?.ToString());
#else
ExplorerBepInPlugin.Logging?.LogError(message?.ToString());
#endif
}
2020-08-07 22:19:03 +10:00
}
}