UnityExplorer/src/ExplorerCore.cs

148 lines
3.6 KiB
C#
Raw Normal View History

2020-10-14 20:47:19 +11:00
using System.Collections;
using System.Linq;
using ExplorerBeta.Config;
using ExplorerBeta.Input;
using ExplorerBeta.UI;
2020-10-08 06:15:42 +11:00
using UnityEngine;
using UnityEngine.EventSystems;
2020-08-07 22:19:03 +10:00
namespace ExplorerBeta
2020-08-07 22:19:03 +10:00
{
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 = "3.0.0b";
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 static bool ShowMenu
{
get => m_showMenu;
set => SetShowMenu(value);
}
public static bool m_showMenu;
private static bool m_doneUIInit;
private static float m_startupTime;
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();
// Temporary? Need a small delay after OnApplicationStart before we can safely make our GameObject.
// Can't use Threads (crash), can't use Coroutine (no BepInEx support yet).
m_startupTime = Time.realtimeSinceStartup;
2020-08-07 22:19:03 +10:00
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
private static void SetShowMenu(bool show)
{
m_showMenu = show;
if (UIManager.CanvasRoot)
{
UIManager.CanvasRoot.SetActive(show);
if (show)
{
ForceUnlockCursor.SetEventSystem();
}
else
{
ForceUnlockCursor.ReleaseEventSystem();
}
}
2020-10-08 06:15:42 +11:00
ForceUnlockCursor.UpdateCursorControl();
}
public static void Update()
2020-08-07 22:19:03 +10:00
{
// Temporary delay before UIManager.Init
if (!m_doneUIInit && Time.realtimeSinceStartup - m_startupTime > 1f)
{
UIManager.Init();
Log("Initialized Explorer UI.");
m_doneUIInit = true;
}
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
2020-08-07 22:19:03 +10:00
{
ShowMenu = !ShowMenu;
}
if (ShowMenu)
{
ForceUnlockCursor.Update();
UIManager.Update();
//// TODO:
//InspectUnderMouse.Update();
}
}
public static void OnSceneChange()
{
UIManager.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
}
}