2020-10-23 19:55:02 +11:00
|
|
|
|
using System;
|
2021-04-11 20:45:02 +10:00
|
|
|
|
using System.Collections;
|
2020-11-23 18:23:25 +11:00
|
|
|
|
using System.IO;
|
|
|
|
|
using UnityEngine;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.Core.Config;
|
|
|
|
|
using UnityExplorer.Core.Input;
|
|
|
|
|
using UnityExplorer.Core.Runtime;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.UI;
|
2021-04-04 13:44:58 +10:00
|
|
|
|
using UnityExplorer.UI.Inspectors;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.UI.Main;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-11-03 20:59:13 +11:00
|
|
|
|
namespace UnityExplorer
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-27 22:04:23 +10:00
|
|
|
|
public class ExplorerCore
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-11-13 18:46:36 +11:00
|
|
|
|
public const string NAME = "UnityExplorer";
|
2021-04-11 20:45:02 +10:00
|
|
|
|
public const string VERSION = "3.3.12";
|
2020-10-28 06:39:26 +11:00
|
|
|
|
public const string AUTHOR = "Sinai";
|
2020-11-03 20:59:13 +11:00
|
|
|
|
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-30 19:50:04 +11:00
|
|
|
|
public static IExplorerLoader Loader { get; private set; }
|
2020-11-08 21:04:41 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
// Prevent using ctor, must use Init method.
|
|
|
|
|
private ExplorerCore() { }
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public static void Init(IExplorerLoader loader)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-10-11 22:57:46 +11:00
|
|
|
|
if (Instance != null)
|
|
|
|
|
{
|
2021-03-30 19:50:04 +11:00
|
|
|
|
Log("An instance of UnityExplorer is already active!");
|
2020-10-11 22:57:46 +11:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
Loader = loader;
|
|
|
|
|
Instance = new ExplorerCore();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
if (!Directory.Exists(Loader.ExplorerFolder))
|
|
|
|
|
Directory.CreateDirectory(Loader.ExplorerFolder);
|
2020-11-08 21:04:41 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
ConfigManager.Init(Loader.ConfigHandler);
|
2020-09-10 20:31:09 +10:00
|
|
|
|
|
2021-03-24 17:13:26 +11:00
|
|
|
|
RuntimeProvider.Init();
|
|
|
|
|
|
2020-10-03 20:19:44 +10:00
|
|
|
|
InputManager.Init();
|
2020-08-27 18:05:55 +10:00
|
|
|
|
|
2020-11-13 18:46:36 +11:00
|
|
|
|
Log($"{NAME} {VERSION} initialized.");
|
2021-04-04 03:41:36 +10:00
|
|
|
|
|
2021-04-11 20:45:02 +10:00
|
|
|
|
RuntimeProvider.Instance.StartCoroutine(SetupCoroutine());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
private static IEnumerator SetupCoroutine()
|
|
|
|
|
{
|
|
|
|
|
float f = Time.realtimeSinceStartup;
|
|
|
|
|
float delay = ConfigManager.Startup_Delay_Time.Value;
|
|
|
|
|
while (Time.realtimeSinceStartup - f < delay)
|
|
|
|
|
yield return null;
|
|
|
|
|
|
|
|
|
|
Log($"Creating UI, after delay of {delay} second(s).");
|
|
|
|
|
UIManager.Init();
|
|
|
|
|
|
2021-04-07 20:54:08 +10:00
|
|
|
|
//InspectorManager.Instance.Inspect(typeof(TestClass));
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Update()
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2021-04-07 17:20:09 +10:00
|
|
|
|
RuntimeProvider.Instance.Update();
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
UIManager.Update();
|
2020-10-28 06:39:26 +11:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public static void Log(object message)
|
|
|
|
|
=> Log(message, LogType.Log, false);
|
|
|
|
|
|
|
|
|
|
public static void LogWarning(object message)
|
|
|
|
|
=> Log(message, LogType.Warning, false);
|
|
|
|
|
|
|
|
|
|
public static void LogError(object message)
|
|
|
|
|
=> Log(message, LogType.Error, false);
|
|
|
|
|
|
|
|
|
|
internal static void Log(object message, LogType logType, bool isFromUnity = false)
|
2020-10-27 00:54:08 +11:00
|
|
|
|
{
|
2021-03-30 19:50:04 +11:00
|
|
|
|
if (isFromUnity && !ConfigManager.Log_Unity_Debug.Value)
|
2020-10-27 00:54:08 +11:00
|
|
|
|
return;
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
string log = message?.ToString() ?? "";
|
2020-10-27 00:54:08 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
switch (logType)
|
2020-10-27 00:54:08 +11:00
|
|
|
|
{
|
|
|
|
|
case LogType.Assert:
|
|
|
|
|
case LogType.Log:
|
2021-03-30 19:50:04 +11:00
|
|
|
|
Loader.OnLogMessage(log);
|
|
|
|
|
DebugConsole.Log(log, Color.white);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
case LogType.Warning:
|
2021-03-30 19:50:04 +11:00
|
|
|
|
Loader.OnLogWarning(log);
|
|
|
|
|
DebugConsole.Log(log, Color.yellow);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
2020-10-27 00:54:08 +11:00
|
|
|
|
case LogType.Error:
|
2021-03-30 19:50:04 +11:00
|
|
|
|
case LogType.Exception:
|
|
|
|
|
Loader.OnLogError(log);
|
|
|
|
|
DebugConsole.Log(log, Color.red);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|