2020-10-23 19:55:02 +11:00
|
|
|
|
using System;
|
2021-04-11 20:45:02 +10:00
|
|
|
|
using System.Collections;
|
2021-05-07 01:22:55 +10:00
|
|
|
|
using System.Collections.Generic;
|
2021-05-03 21:02:01 +10:00
|
|
|
|
using System.Diagnostics;
|
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-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.Inspectors;
|
|
|
|
|
using UnityExplorer.ObjectExplorer;
|
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-07-19 21:43:40 +10:00
|
|
|
|
public const string VERSION = "4.1.11";
|
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-05-14 02:45:59 +10:00
|
|
|
|
Log($"{NAME} {VERSION} initializing...");
|
|
|
|
|
|
2021-05-01 20:55:14 +10:00
|
|
|
|
ExplorerBehaviour.Setup();
|
|
|
|
|
|
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);
|
2021-05-14 02:45:59 +10:00
|
|
|
|
ReflectionUtility.Init();
|
2021-03-24 17:13:26 +11:00
|
|
|
|
RuntimeProvider.Init();
|
2021-07-19 21:43:40 +10:00
|
|
|
|
|
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
|
|
|
|
|
2021-04-11 20:45:02 +10:00
|
|
|
|
RuntimeProvider.Instance.StartCoroutine(SetupCoroutine());
|
2021-05-14 02:45:59 +10:00
|
|
|
|
|
|
|
|
|
Log($"Finished core setup, waiting for UI setup...");
|
2021-04-11 20:45:02 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
{
|
2021-05-11 20:23:52 +10:00
|
|
|
|
yield return null;
|
2021-04-11 20:45:02 +10:00
|
|
|
|
|
2021-05-11 20:23:52 +10:00
|
|
|
|
float start = Time.realtimeSinceStartup;
|
|
|
|
|
float delay = ConfigManager.Startup_Delay_Time.Value;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-11 20:23:52 +10:00
|
|
|
|
while (delay > 0)
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
2021-05-11 20:23:52 +10:00
|
|
|
|
float diff = Math.Max(Time.deltaTime, Time.realtimeSinceStartup - start);
|
|
|
|
|
delay -= diff;
|
|
|
|
|
yield return null;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 02:45:59 +10:00
|
|
|
|
Log($"Creating UI...");
|
2021-05-05 21:27:09 +10:00
|
|
|
|
|
2021-05-11 20:23:52 +10:00
|
|
|
|
UIManager.InitUI();
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-14 02:45:59 +10:00
|
|
|
|
Log($"{NAME} {VERSION} initialized.");
|
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-05-01 20:55:14 +10:00
|
|
|
|
public static void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
RuntimeProvider.Instance.ProcessFixedUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OnPostRender()
|
|
|
|
|
{
|
|
|
|
|
RuntimeProvider.Instance.ProcessOnPostRender();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-05 19:36:09 +10:00
|
|
|
|
#region LOGGING
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-06-05 19:36:09 +10: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
|
|
|
|
|
2021-06-05 19:36:09 +10: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
|
|
|
|
|
2021-06-05 19:36:09 +10: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-05-14 02:45:59 +10:00
|
|
|
|
LogPanel.Log(log, logType);
|
|
|
|
|
|
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);
|
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);
|
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);
|
2020-10-27 00:54:08 +11:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 20:18:03 +10:00
|
|
|
|
|
2021-06-05 19:36:09 +10:00
|
|
|
|
#endregion
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|