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-04-28 20:47:48 +10:00
|
|
|
|
using UnityEngine.UI;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
using UnityExplorer.Core;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.Core.Config;
|
|
|
|
|
using UnityExplorer.Core.Input;
|
|
|
|
|
using UnityExplorer.Core.Runtime;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
using UnityExplorer.Tests;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.UI;
|
2021-04-28 20:47:48 +10:00
|
|
|
|
using UnityExplorer.UI.Inspectors;
|
2021-04-22 17:53:29 +10:00
|
|
|
|
using UnityExplorer.UI.Panels;
|
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
|
|
|
|
{
|
2021-04-28 20:47:48 +10:00
|
|
|
|
public static 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-29 21:01:08 +10:00
|
|
|
|
public const string VERSION = "4.0.0";
|
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-30 19:50:04 +11:00
|
|
|
|
public static IExplorerLoader Loader { get; private set; }
|
2021-04-15 20:18:03 +10:00
|
|
|
|
public static RuntimeContext Context { get; internal set; }
|
2020-11-08 21:04:41 +11:00
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize UnityExplorer with the provided Loader implementation.
|
|
|
|
|
/// </summary>
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public static void Init(IExplorerLoader loader)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2021-04-28 20:47:48 +10:00
|
|
|
|
if (Loader != null)
|
2020-10-11 22:57:46 +11:00
|
|
|
|
{
|
2021-04-28 20:47:48 +10:00
|
|
|
|
LogWarning("UnityExplorer is already loaded!");
|
2020-10-11 22:57:46 +11:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
Loader = loader;
|
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();
|
2021-04-15 20:18:03 +10:00
|
|
|
|
SceneHandler.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).");
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
|
|
|
|
UIManager.InitUI();
|
2021-04-11 20:45:02 +10:00
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
// TEMP DEBUG TEST FOR TRANSFORM TREE
|
|
|
|
|
|
|
|
|
|
var stressTest = new GameObject("StressTest");
|
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
|
|
|
{
|
|
|
|
|
var obj = new GameObject($"Parent_{i}");
|
|
|
|
|
obj.transform.parent = stressTest.transform;
|
|
|
|
|
for (int j = 0; j < 100; j++)
|
|
|
|
|
{
|
|
|
|
|
var obj2 = new GameObject($"Child_{j}");
|
|
|
|
|
obj2.transform.parent = obj.transform;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// END
|
|
|
|
|
|
|
|
|
|
//InspectorManager.Inspect(typeof(TestClass));
|
|
|
|
|
InspectorManager.Inspect(UIManager.CanvasRoot.gameObject.GetComponent<GraphicRaycaster>());
|
2021-04-28 20:47:48 +10:00
|
|
|
|
//InspectorManager.InspectType(typeof(ReflectionUtility));
|
2020-09-27 22:04:23 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Should be called once per frame.
|
|
|
|
|
/// </summary>
|
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-04-16 18:24:31 +10:00
|
|
|
|
#region LOGGING
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public static void Log(object message)
|
2021-04-22 19:12:16 +10:00
|
|
|
|
=> Log(message, LogType.Log);
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
|
|
|
|
public static void LogWarning(object message)
|
2021-04-22 19:12:16 +10:00
|
|
|
|
=> Log(message, LogType.Warning);
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
|
|
|
|
public static void LogError(object message)
|
2021-04-22 19:12:16 +10:00
|
|
|
|
=> Log(message, LogType.Error);
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
2021-04-22 19:12:16 +10:00
|
|
|
|
public static void LogUnity(object message, LogType logType)
|
2020-10-27 00:54:08 +11:00
|
|
|
|
{
|
2021-04-22 19:12:16 +10:00
|
|
|
|
if (!ConfigManager.Log_Unity_Debug.Value)
|
2020-10-27 00:54:08 +11:00
|
|
|
|
return;
|
|
|
|
|
|
2021-04-22 19:12:16 +10:00
|
|
|
|
Log($"[Unity] {message}", logType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Log(object message, LogType logType)
|
|
|
|
|
{
|
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);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
//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);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
//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);
|
2021-04-15 20:18:03 +10:00
|
|
|
|
//DebugConsole.Log(log, Color.red);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-04-16 18:24:31 +10:00
|
|
|
|
#endregion
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|