2021-03-30 19:50:04 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using UnityEngine.UI;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.Core.Config;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
using UnityExplorer.Core.Input;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.CSConsole;
|
|
|
|
|
using UnityExplorer.Inspectors;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
using UnityExplorer.UI.Models;
|
|
|
|
|
using UnityExplorer.UI.Panels;
|
|
|
|
|
using UnityExplorer.UI.Widgets;
|
2021-04-23 21:50:58 +10:00
|
|
|
|
using UnityExplorer.UI.Widgets.AutoComplete;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-11-03 20:59:13 +11:00
|
|
|
|
namespace UnityExplorer.UI
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
|
|
|
|
public static class UIManager
|
|
|
|
|
{
|
2021-04-23 21:50:58 +10:00
|
|
|
|
public enum Panels
|
|
|
|
|
{
|
|
|
|
|
ObjectExplorer,
|
|
|
|
|
Inspector,
|
|
|
|
|
CSConsole,
|
|
|
|
|
Options,
|
|
|
|
|
ConsoleLog,
|
2021-05-15 06:23:13 +10:00
|
|
|
|
AutoCompleter,
|
|
|
|
|
MouseInspector
|
2021-04-23 21:50:58 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 21:45:09 +10:00
|
|
|
|
public enum VerticalAnchor
|
|
|
|
|
{
|
|
|
|
|
Top,
|
|
|
|
|
Bottom
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 22:17:26 +10:00
|
|
|
|
public static bool Initializing { get; internal set; } = true;
|
2021-04-29 21:01:08 +10:00
|
|
|
|
|
2021-05-16 21:45:09 +10:00
|
|
|
|
private static readonly Dictionary<Panels, UIPanel> UIPanels = new Dictionary<Panels, UIPanel>();
|
|
|
|
|
|
|
|
|
|
public static VerticalAnchor NavbarAnchor = VerticalAnchor.Top;
|
|
|
|
|
|
|
|
|
|
// References
|
2020-10-23 01:50:33 +11:00
|
|
|
|
public static GameObject CanvasRoot { get; private set; }
|
2021-04-23 21:50:58 +10:00
|
|
|
|
public static Canvas Canvas { get; private set; }
|
2020-10-23 01:50:33 +11:00
|
|
|
|
public static EventSystem EventSys { get; private set; }
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
internal static GameObject PoolHolder { get; private set; }
|
|
|
|
|
|
2021-04-23 21:50:58 +10:00
|
|
|
|
internal static GameObject PanelHolder { get; private set; }
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2020-11-10 20:18:14 +11:00
|
|
|
|
internal static Font ConsoleFont { get; private set; }
|
2021-07-27 18:14:44 +10:00
|
|
|
|
internal static Font DefaultFont { get; private set; }
|
2020-11-25 16:40:36 +11:00
|
|
|
|
internal static Shader BackupShader { get; private set; }
|
|
|
|
|
|
2021-05-03 21:02:01 +10:00
|
|
|
|
public static RectTransform NavBarRect;
|
2021-05-28 16:39:42 +10:00
|
|
|
|
public static GameObject NavbarTabButtonHolder;
|
2021-05-15 06:23:13 +10:00
|
|
|
|
public static Dropdown MouseInspectDropdown;
|
2021-05-03 21:02:01 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static ButtonRef closeBtn;
|
|
|
|
|
private static ButtonRef pauseBtn;
|
|
|
|
|
private static InputFieldRef timeInput;
|
|
|
|
|
private static bool pauseButtonPausing;
|
|
|
|
|
private static float lastTimeScale;
|
|
|
|
|
|
2021-05-16 21:45:09 +10:00
|
|
|
|
// defaults
|
2021-05-04 20:10:46 +10:00
|
|
|
|
internal static readonly Color enabledButtonColor = new Color(0.2f, 0.4f, 0.28f);
|
|
|
|
|
internal static readonly Color disabledButtonColor = new Color(0.25f, 0.25f, 0.25f);
|
2021-04-28 23:58:13 +10:00
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public const int MAX_INPUTFIELD_CHARS = 16000;
|
2021-05-10 21:07:27 +10:00
|
|
|
|
public const int MAX_TEXT_VERTS = 65000;
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
public static bool ShowMenu
|
|
|
|
|
{
|
|
|
|
|
get => s_showMenu;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
set
|
2021-03-11 17:57:58 +11:00
|
|
|
|
{
|
2021-03-30 19:50:04 +11:00
|
|
|
|
if (s_showMenu == value || !CanvasRoot)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
s_showMenu = value;
|
|
|
|
|
CanvasRoot.SetActive(value);
|
|
|
|
|
CursorUnlocker.UpdateCursorControl();
|
2021-03-11 17:57:58 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public static bool s_showMenu = true;
|
2021-03-11 17:57:58 +11:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// Initialization
|
|
|
|
|
|
|
|
|
|
internal static void InitUI()
|
|
|
|
|
{
|
|
|
|
|
LoadBundle();
|
|
|
|
|
|
|
|
|
|
CreateRootCanvas();
|
|
|
|
|
|
|
|
|
|
// Global UI Pool Holder
|
|
|
|
|
PoolHolder = new GameObject("PoolHolder");
|
|
|
|
|
PoolHolder.transform.parent = CanvasRoot.transform;
|
|
|
|
|
PoolHolder.SetActive(false);
|
|
|
|
|
|
|
|
|
|
CreateTopNavBar();
|
|
|
|
|
|
|
|
|
|
UIPanels.Add(Panels.AutoCompleter, new AutoCompleteModal());
|
|
|
|
|
UIPanels.Add(Panels.ObjectExplorer, new ObjectExplorerPanel());
|
|
|
|
|
UIPanels.Add(Panels.Inspector, new InspectorPanel());
|
|
|
|
|
UIPanels.Add(Panels.CSConsole, new CSConsolePanel());
|
|
|
|
|
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
|
|
|
|
|
UIPanels.Add(Panels.Options, new OptionsPanel());
|
|
|
|
|
UIPanels.Add(Panels.MouseInspector, new InspectUnderMouse());
|
|
|
|
|
|
|
|
|
|
foreach (var panel in UIPanels.Values)
|
|
|
|
|
panel.ConstructUI();
|
|
|
|
|
|
|
|
|
|
ConsoleController.Init();
|
|
|
|
|
|
|
|
|
|
ShowMenu = !ConfigManager.Hide_On_Startup.Value;
|
|
|
|
|
|
|
|
|
|
lastScreenWidth = Screen.width;
|
|
|
|
|
lastScreenHeight = Screen.height;
|
|
|
|
|
|
2021-07-11 18:11:14 +10:00
|
|
|
|
// Failsafe fix
|
|
|
|
|
foreach (var dropdown in CanvasRoot.GetComponentsInChildren<Dropdown>(true))
|
|
|
|
|
dropdown.RefreshShownValue();
|
|
|
|
|
timeInput.Text = string.Empty;
|
|
|
|
|
timeInput.Text = Time.timeScale.ToString();
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
Initializing = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Main UI Update loop
|
|
|
|
|
|
|
|
|
|
private static int lastScreenWidth;
|
|
|
|
|
private static int lastScreenHeight;
|
|
|
|
|
|
|
|
|
|
public static void Update()
|
|
|
|
|
{
|
|
|
|
|
if (!CanvasRoot || Initializing)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// if doing Mouse Inspect, update that and return.
|
|
|
|
|
if (InspectUnderMouse.Inspecting)
|
|
|
|
|
{
|
|
|
|
|
InspectUnderMouse.Instance.UpdateInspect();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check master toggle
|
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Master_Toggle.Value))
|
|
|
|
|
ShowMenu = !ShowMenu;
|
|
|
|
|
|
|
|
|
|
// return if menu closed
|
|
|
|
|
if (!ShowMenu)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Check forceUnlockMouse toggle
|
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Force_Unlock_Toggle.Value))
|
|
|
|
|
CursorUnlocker.Unlock = !CursorUnlocker.Unlock;
|
|
|
|
|
|
|
|
|
|
// check event system state
|
|
|
|
|
if (!ConfigManager.Disable_EventSystem_Override.Value && EventSystem.current != EventSys)
|
|
|
|
|
CursorUnlocker.SetEventSystem();
|
|
|
|
|
|
|
|
|
|
// update focused panel
|
|
|
|
|
UIPanel.UpdateFocus();
|
|
|
|
|
// update UI model instances
|
|
|
|
|
PanelDragger.UpdateInstances();
|
|
|
|
|
InputFieldRef.UpdateInstances();
|
|
|
|
|
UIBehaviourModel.UpdateInstances();
|
|
|
|
|
|
2021-05-28 18:48:55 +10:00
|
|
|
|
// update the timescale value
|
|
|
|
|
if (!timeInput.Component.isFocused && lastTimeScale != Time.timeScale)
|
|
|
|
|
{
|
|
|
|
|
if (pauseButtonPausing && Time.timeScale != 0.0f)
|
|
|
|
|
{
|
|
|
|
|
pauseButtonPausing = false;
|
|
|
|
|
OnPauseButtonToggled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pauseButtonPausing)
|
|
|
|
|
{
|
|
|
|
|
timeInput.Text = Time.timeScale.ToString("F2");
|
|
|
|
|
lastTimeScale = Time.timeScale;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// check screen dimension change
|
|
|
|
|
if (Screen.width != lastScreenWidth || Screen.height != lastScreenHeight)
|
|
|
|
|
OnScreenDimensionsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 23:03:30 +10:00
|
|
|
|
// Panels
|
2021-03-11 17:57:58 +11:00
|
|
|
|
|
2021-05-13 23:03:30 +10:00
|
|
|
|
public static UIPanel GetPanel(Panels panel)
|
|
|
|
|
{
|
|
|
|
|
return UIPanels[panel];
|
|
|
|
|
}
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2021-05-13 23:03:30 +10:00
|
|
|
|
public static T GetPanel<T>(Panels panel) where T : UIPanel
|
|
|
|
|
{
|
|
|
|
|
return (T)UIPanels[panel];
|
2021-03-30 19:50:04 +11:00
|
|
|
|
}
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
2021-04-24 04:03:33 +10:00
|
|
|
|
public static void TogglePanel(Panels panel)
|
|
|
|
|
{
|
|
|
|
|
var uiPanel = GetPanel(panel);
|
|
|
|
|
SetPanelActive(panel, !uiPanel.Enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetPanelActive(Panels panel, bool active)
|
|
|
|
|
{
|
2021-04-25 00:21:12 +10:00
|
|
|
|
var obj = GetPanel(panel);
|
2021-04-28 23:58:13 +10:00
|
|
|
|
SetPanelActive(obj, active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetPanelActive(UIPanel panel, bool active)
|
|
|
|
|
{
|
|
|
|
|
panel.SetActive(active);
|
2021-04-25 00:21:12 +10:00
|
|
|
|
if (active)
|
|
|
|
|
{
|
2021-04-28 23:58:13 +10:00
|
|
|
|
panel.UIRoot.transform.SetAsLastSibling();
|
2021-04-25 00:21:12 +10:00
|
|
|
|
UIPanel.InvokeOnPanelsReordered();
|
|
|
|
|
}
|
2021-04-28 23:58:13 +10:00
|
|
|
|
}
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-04-28 23:58:13 +10:00
|
|
|
|
internal static void SetPanelActive(Transform transform, bool value)
|
|
|
|
|
{
|
|
|
|
|
if (UIPanel.transformToPanelDict.TryGetValue(transform.GetInstanceID(), out UIPanel panel))
|
|
|
|
|
SetPanelActive(panel, value);
|
2021-04-24 04:03:33 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// navbar
|
2021-05-18 19:55:27 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
public static void SetNavBarAnchor()
|
2021-05-13 23:03:30 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
switch (NavbarAnchor)
|
2021-05-15 06:23:13 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
case VerticalAnchor.Top:
|
|
|
|
|
NavBarRect.anchorMin = new Vector2(0.5f, 1f);
|
|
|
|
|
NavBarRect.anchorMax = new Vector2(0.5f, 1f);
|
|
|
|
|
NavBarRect.anchoredPosition = new Vector2(NavBarRect.anchoredPosition.x, 0);
|
|
|
|
|
NavBarRect.sizeDelta = new Vector2(1000f, 35f);
|
|
|
|
|
break;
|
2021-05-13 23:03:30 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
case VerticalAnchor.Bottom:
|
|
|
|
|
NavBarRect.anchorMin = new Vector2(0.5f, 0f);
|
|
|
|
|
NavBarRect.anchorMax = new Vector2(0.5f, 0f);
|
|
|
|
|
NavBarRect.anchoredPosition = new Vector2(NavBarRect.anchoredPosition.x, 35);
|
|
|
|
|
NavBarRect.sizeDelta = new Vector2(1000f, 35f);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-13 23:03:30 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// listeners
|
2021-05-13 23:03:30 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void OnScreenDimensionsChanged()
|
|
|
|
|
{
|
|
|
|
|
lastScreenWidth = Screen.width;
|
|
|
|
|
lastScreenHeight = Screen.height;
|
2021-05-18 19:55:27 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
foreach (var panel in UIPanels)
|
2021-05-18 19:55:27 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
panel.Value.EnsureValidSize();
|
|
|
|
|
UIPanel.EnsureValidPosition(panel.Value.Rect);
|
|
|
|
|
panel.Value.Dragger.OnEndResize();
|
2021-05-18 19:55:27 +10:00
|
|
|
|
}
|
2021-05-13 23:03:30 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void OnCloseButtonClicked()
|
2021-04-24 04:03:33 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
ShowMenu = false;
|
|
|
|
|
}
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void Master_Toggle_OnValueChanged(KeyCode val)
|
|
|
|
|
{
|
|
|
|
|
closeBtn.ButtonText.text = val.ToString();
|
|
|
|
|
}
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void OnTimeInputEndEdit(string val)
|
|
|
|
|
{
|
|
|
|
|
if (pauseButtonPausing)
|
|
|
|
|
return;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
if (float.TryParse(val, out float f))
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = f;
|
|
|
|
|
lastTimeScale = f;
|
|
|
|
|
}
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
timeInput.Text = Time.timeScale.ToString("F2");
|
|
|
|
|
}
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void OnPauseButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
pauseButtonPausing = !pauseButtonPausing;
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 18:48:55 +10:00
|
|
|
|
Time.timeScale = pauseButtonPausing ? 0f : lastTimeScale;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-28 18:48:55 +10:00
|
|
|
|
OnPauseButtonToggled();
|
|
|
|
|
}
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 18:48:55 +10:00
|
|
|
|
private static void OnPauseButtonToggled()
|
|
|
|
|
{
|
|
|
|
|
timeInput.Component.text = Time.timeScale.ToString("F2");
|
2021-05-28 16:39:42 +10:00
|
|
|
|
timeInput.Component.readOnly = pauseButtonPausing;
|
|
|
|
|
timeInput.Component.textComponent.color = pauseButtonPausing ? Color.grey : Color.white;
|
2021-05-18 19:55:27 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
Color color = pauseButtonPausing ? new Color(0.3f, 0.3f, 0.2f) : new Color(0.2f, 0.2f, 0.2f);
|
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(pauseBtn.Component, color, color * 1.2f, color * 0.7f);
|
|
|
|
|
pauseBtn.ButtonText.text = pauseButtonPausing ? "►" : "||";
|
2021-04-24 04:03:33 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// UI Construction
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
private static void CreateRootCanvas()
|
|
|
|
|
{
|
|
|
|
|
CanvasRoot = new GameObject("ExplorerCanvas");
|
|
|
|
|
UnityEngine.Object.DontDestroyOnLoad(CanvasRoot);
|
|
|
|
|
CanvasRoot.hideFlags |= HideFlags.HideAndDontSave;
|
|
|
|
|
CanvasRoot.layer = 5;
|
|
|
|
|
CanvasRoot.transform.position = new Vector3(0f, 0f, 1f);
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
EventSys = CanvasRoot.AddComponent<EventSystem>();
|
|
|
|
|
InputManager.AddUIModule();
|
|
|
|
|
|
2021-04-23 21:50:58 +10:00
|
|
|
|
Canvas = CanvasRoot.AddComponent<Canvas>();
|
|
|
|
|
Canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
|
|
|
|
Canvas.referencePixelsPerUnit = 100;
|
|
|
|
|
Canvas.sortingOrder = 999;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
|
|
|
|
CanvasScaler scaler = CanvasRoot.AddComponent<CanvasScaler>();
|
|
|
|
|
scaler.referenceResolution = new Vector2(1920, 1080);
|
|
|
|
|
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
|
|
|
|
|
|
|
|
|
|
CanvasRoot.AddComponent<GraphicRaycaster>();
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
|
|
|
|
PanelHolder = new GameObject("PanelHolder");
|
|
|
|
|
PanelHolder.transform.SetParent(CanvasRoot.transform, false);
|
|
|
|
|
PanelHolder.layer = 5;
|
|
|
|
|
var rect = PanelHolder.AddComponent<RectTransform>();
|
|
|
|
|
rect.sizeDelta = Vector2.zero;
|
|
|
|
|
rect.anchoredPosition = Vector2.zero;
|
|
|
|
|
rect.pivot = new Vector2(0.5f, 0.5f);
|
|
|
|
|
rect.anchorMin = Vector2.zero;
|
|
|
|
|
rect.anchorMax = Vector2.one;
|
|
|
|
|
PanelHolder.transform.SetAsFirstSibling();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 23:58:13 +10:00
|
|
|
|
private static void CreateTopNavBar()
|
2021-04-23 21:50:58 +10:00
|
|
|
|
{
|
2021-04-28 23:58:13 +10:00
|
|
|
|
var navbarPanel = UIFactory.CreateUIObject("MainNavbar", CanvasRoot);
|
2021-05-28 16:39:42 +10:00
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(navbarPanel, false, false, true, true, 5, 4, 4, 4, 4, TextAnchor.MiddleCenter);
|
2021-04-28 23:58:13 +10:00
|
|
|
|
navbarPanel.AddComponent<Image>().color = new Color(0.1f, 0.1f, 0.1f);
|
2021-05-03 21:02:01 +10:00
|
|
|
|
NavBarRect = navbarPanel.GetComponent<RectTransform>();
|
|
|
|
|
NavBarRect.pivot = new Vector2(0.5f, 1f);
|
2021-05-16 21:45:09 +10:00
|
|
|
|
|
|
|
|
|
NavbarAnchor = ConfigManager.Main_Navbar_Anchor.Value;
|
|
|
|
|
SetNavBarAnchor();
|
2021-06-05 19:36:09 +10:00
|
|
|
|
ConfigManager.Main_Navbar_Anchor.OnValueChanged += (VerticalAnchor val) =>
|
2021-05-16 21:45:09 +10:00
|
|
|
|
{
|
|
|
|
|
NavbarAnchor = val;
|
|
|
|
|
SetNavBarAnchor();
|
|
|
|
|
};
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-04-28 23:58:13 +10:00
|
|
|
|
// UnityExplorer title
|
|
|
|
|
|
2021-04-23 21:50:58 +10:00
|
|
|
|
string titleTxt = $"{ExplorerCore.NAME} <i><color=grey>{ExplorerCore.VERSION}</color></i>";
|
2021-05-28 16:39:42 +10:00
|
|
|
|
var title = UIFactory.CreateLabel(navbarPanel, "Title", titleTxt, TextAnchor.MiddleLeft, default, true, 17);
|
|
|
|
|
UIFactory.SetLayoutElement(title.gameObject, minWidth: 170, flexibleWidth: 0);
|
2021-05-03 21:02:01 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// panel tabs
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
NavbarTabButtonHolder = UIFactory.CreateUIObject("NavTabButtonHolder", navbarPanel);
|
|
|
|
|
UIFactory.SetLayoutElement(NavbarTabButtonHolder, minHeight: 25, flexibleHeight: 999, flexibleWidth: 999);
|
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(NavbarTabButtonHolder, false, true, true, true, 4, 2, 2, 2, 2);
|
|
|
|
|
|
|
|
|
|
// Time controls
|
|
|
|
|
|
|
|
|
|
var timeLabel = UIFactory.CreateLabel(navbarPanel, "TimeLabel", "Time:", TextAnchor.MiddleRight, Color.grey);
|
|
|
|
|
UIFactory.SetLayoutElement(timeLabel.gameObject, minHeight: 25, minWidth: 50);
|
|
|
|
|
|
|
|
|
|
timeInput = UIFactory.CreateInputField(navbarPanel, "TimeInput", "timeScale");
|
|
|
|
|
UIFactory.SetLayoutElement(timeInput.Component.gameObject, minHeight: 25, minWidth: 40);
|
|
|
|
|
timeInput.Text = Time.timeScale.ToString("F2");
|
2021-06-21 19:26:05 +10:00
|
|
|
|
timeInput.Component.GetOnEndEdit().AddListener(OnTimeInputEndEdit);
|
2021-05-28 16:39:42 +10:00
|
|
|
|
|
|
|
|
|
pauseBtn = UIFactory.CreateButton(navbarPanel, "PauseButton", "||", new Color(0.2f, 0.2f, 0.2f));
|
|
|
|
|
UIFactory.SetLayoutElement(pauseBtn.Component.gameObject, minHeight: 25, minWidth: 25);
|
|
|
|
|
pauseBtn.OnClick += OnPauseButtonClicked;
|
2021-05-15 06:23:13 +10:00
|
|
|
|
|
|
|
|
|
// Inspect under mouse dropdown
|
|
|
|
|
|
|
|
|
|
var mouseDropdown = UIFactory.CreateDropdown(navbarPanel, out MouseInspectDropdown, "Mouse Inspect", 14,
|
|
|
|
|
InspectUnderMouse.OnDropdownSelect);
|
|
|
|
|
UIFactory.SetLayoutElement(mouseDropdown, minHeight: 25, minWidth: 140);
|
|
|
|
|
MouseInspectDropdown.options.Add(new Dropdown.OptionData("Mouse Inspect"));
|
|
|
|
|
MouseInspectDropdown.options.Add(new Dropdown.OptionData("World"));
|
|
|
|
|
MouseInspectDropdown.options.Add(new Dropdown.OptionData("UI"));
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-04-28 23:58:13 +10:00
|
|
|
|
// Hide menu button
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
closeBtn = UIFactory.CreateButton(navbarPanel, "CloseButton", ConfigManager.Master_Toggle.Value.ToString());
|
2021-05-11 19:18:27 +10:00
|
|
|
|
UIFactory.SetLayoutElement(closeBtn.Component.gameObject, minHeight: 25, minWidth: 80, flexibleWidth: 0);
|
|
|
|
|
RuntimeProvider.Instance.SetColorBlock(closeBtn.Component, new Color(0.63f, 0.32f, 0.31f),
|
2021-04-23 21:50:58 +10:00
|
|
|
|
new Color(0.81f, 0.25f, 0.2f), new Color(0.6f, 0.18f, 0.16f));
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
ConfigManager.Master_Toggle.OnValueChanged += Master_Toggle_OnValueChanged;
|
|
|
|
|
closeBtn.OnClick += OnCloseButtonClicked;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 18:11:14 +10:00
|
|
|
|
// UI AssetBundle
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-01-02 19:38:01 +01:00
|
|
|
|
private static void LoadBundle()
|
|
|
|
|
{
|
2021-07-15 05:19:48 +10:00
|
|
|
|
AssetBundle bundle;
|
2021-01-02 19:38:01 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-07-11 23:12:17 +10:00
|
|
|
|
// Get the Major and Minor of the Unity version
|
|
|
|
|
var split = Application.unityVersion.Split('.');
|
|
|
|
|
int major = int.Parse(split[0]);
|
|
|
|
|
int minor = int.Parse(split[1]);
|
2021-07-11 18:11:14 +10:00
|
|
|
|
|
|
|
|
|
// Use appropriate AssetBundle for Unity version
|
2021-07-27 18:14:44 +10:00
|
|
|
|
// >= 2017
|
|
|
|
|
if (major >= 2017)
|
2021-07-11 18:11:14 +10:00
|
|
|
|
bundle = LoadBundle("modern");
|
2021-07-27 18:14:44 +10:00
|
|
|
|
// 5.6.0 to <2017
|
|
|
|
|
else if (major == 5 && minor >= 6)
|
2021-07-11 18:11:14 +10:00
|
|
|
|
bundle = LoadBundle("legacy.5.6");
|
|
|
|
|
// < 5.6.0
|
|
|
|
|
else
|
|
|
|
|
bundle = LoadBundle("legacy");
|
|
|
|
|
}
|
2021-07-15 05:19:48 +10:00
|
|
|
|
catch
|
2021-07-11 18:11:14 +10:00
|
|
|
|
{
|
2021-07-15 05:19:48 +10:00
|
|
|
|
ExplorerCore.LogWarning($"Exception parsing Unity version, falling back to old AssetBundle load method...");
|
|
|
|
|
bundle = LoadBundle("modern") ?? LoadBundle("legacy.5.6") ?? LoadBundle("legacy");
|
2021-07-11 18:11:14 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AssetBundle LoadBundle(string id)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.Log($"Loading {id} bundle for Unity {Application.unityVersion}");
|
|
|
|
|
|
|
|
|
|
return AssetBundle.LoadFromMemory(ReadFully(typeof(ExplorerCore)
|
|
|
|
|
.Assembly
|
|
|
|
|
.GetManifestResourceStream($"UnityExplorer.Resources.{id}.bundle")));
|
2021-01-02 19:38:01 +01:00
|
|
|
|
}
|
2020-11-20 17:12:40 +11:00
|
|
|
|
|
2021-01-02 19:38:01 +01:00
|
|
|
|
if (bundle == null)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning("Could not load the ExplorerUI Bundle!");
|
2021-03-26 19:49:53 +11:00
|
|
|
|
ConsoleFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
|
2021-07-27 18:14:44 +10:00
|
|
|
|
DefaultFont = ConsoleFont;
|
2021-01-02 19:38:01 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-11-20 17:12:40 +11:00
|
|
|
|
|
2021-07-27 18:14:44 +10:00
|
|
|
|
// Bundle loaded
|
|
|
|
|
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
|
|
|
|
|
DefaultFont = bundle.LoadAsset<Font>("arial");
|
2020-11-20 17:12:40 +11:00
|
|
|
|
|
2021-07-27 18:14:44 +10:00
|
|
|
|
BackupShader = bundle.LoadAsset<Shader>("DefaultUI");
|
2021-01-02 19:38:01 +01:00
|
|
|
|
// Fix for games which don't ship with 'UI/Default' shader.
|
|
|
|
|
if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default")
|
2020-11-20 17:12:40 +11:00
|
|
|
|
{
|
2021-01-02 19:38:01 +01:00
|
|
|
|
ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader...");
|
|
|
|
|
Graphic.defaultGraphicMaterial.shader = BackupShader;
|
2020-11-20 17:12:40 +11:00
|
|
|
|
}
|
2021-04-05 16:28:30 +10:00
|
|
|
|
else
|
|
|
|
|
BackupShader = Graphic.defaultGraphicMaterial.shader;
|
2021-01-02 19:38:01 +01:00
|
|
|
|
|
2020-11-20 17:12:40 +11:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
private static byte[] ReadFully(Stream input)
|
2021-03-26 19:49:53 +11:00
|
|
|
|
{
|
|
|
|
|
using (var ms = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
byte[] buffer = new byte[81920];
|
|
|
|
|
int read;
|
|
|
|
|
while ((read = input.Read(buffer, 0, buffer.Length)) != 0)
|
|
|
|
|
ms.Write(buffer, 0, read);
|
|
|
|
|
return ms.ToArray();
|
|
|
|
|
}
|
2020-10-23 01:50:33 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|