mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-01 19:13:03 +08:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
c7ccdf387c | |||
bb46d77a02 | |||
c38155ab04 |
@ -15,7 +15,7 @@ namespace UnityExplorer
|
||||
public class ExplorerCore
|
||||
{
|
||||
public const string NAME = "UnityExplorer";
|
||||
public const string VERSION = "3.0.2";
|
||||
public const string VERSION = "3.0.3";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.unityexplorer";
|
||||
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
|
||||
|
@ -211,6 +211,8 @@ namespace UnityExplorer.Helpers
|
||||
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
public static bool LoadModule(string module) => true;
|
||||
#endif
|
||||
|
||||
public static bool IsEnumerable(Type t)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
{
|
||||
@ -11,5 +12,12 @@ namespace UnityExplorer.Input
|
||||
|
||||
bool GetMouseButtonDown(int btn);
|
||||
bool GetMouseButton(int btn);
|
||||
|
||||
BaseInputModule UIModule { get; }
|
||||
|
||||
PointerEventData InputPointerEvent { get; }
|
||||
|
||||
void AddUIInputModule();
|
||||
void ActivateModule();
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,24 @@
|
||||
using UnityEngine;
|
||||
using UnityExplorer.Helpers;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using UnityEngine.EventSystems;
|
||||
#if CPP
|
||||
using UnhollowerBaseLib;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
{
|
||||
public enum InputType
|
||||
{
|
||||
InputSystem,
|
||||
Legacy,
|
||||
None
|
||||
}
|
||||
|
||||
public static class InputManager
|
||||
{
|
||||
public static InputType CurrentType { get; private set; }
|
||||
|
||||
private static IHandleInput m_inputModule;
|
||||
|
||||
public static Vector3 MousePosition => m_inputModule.MousePosition;
|
||||
@ -20,23 +30,35 @@ namespace UnityExplorer.Input
|
||||
public static bool GetMouseButtonDown(int btn) => m_inputModule.GetMouseButtonDown(btn);
|
||||
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
|
||||
|
||||
public static BaseInputModule UIInput => m_inputModule.UIModule;
|
||||
public static PointerEventData InputPointerEvent => m_inputModule.InputPointerEvent;
|
||||
|
||||
public static void ActivateUIModule() => m_inputModule.ActivateModule();
|
||||
|
||||
public static void AddUIModule()
|
||||
{
|
||||
m_inputModule.AddUIInputModule();
|
||||
ActivateUIModule();
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
#if CPP
|
||||
if (InputSystem.TKeyboard != null || (ReflectionHelpers.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
|
||||
{
|
||||
m_inputModule = new InputSystem();
|
||||
CurrentType = InputType.InputSystem;
|
||||
}
|
||||
else if (LegacyInput.TInput != null || (ReflectionHelpers.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
|
||||
{
|
||||
m_inputModule = new LegacyInput();
|
||||
CurrentType = InputType.Legacy;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_inputModule == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not find any Input module!");
|
||||
m_inputModule = new NoInput();
|
||||
CurrentType = InputType.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
{
|
||||
@ -64,24 +67,46 @@ namespace UnityExplorer.Input
|
||||
private static PropertyInfo m_positionProp;
|
||||
private static MethodInfo m_readVector2InputMethod;
|
||||
|
||||
public Vector2 MousePosition => (Vector2)m_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]);
|
||||
|
||||
public bool GetKeyDown(KeyCode key)
|
||||
public Vector2 MousePosition
|
||||
{
|
||||
var parsedKey = Enum.Parse(TKey, key.ToString());
|
||||
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsedKey });
|
||||
|
||||
return (bool)m_btnWasPressedProp.GetValue(actualKey, null);
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Vector2)m_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetKey(KeyCode key)
|
||||
{
|
||||
var parsed = Enum.Parse(TKey, key.ToString());
|
||||
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });
|
||||
internal static Dictionary<KeyCode, object> ActualKeyDict = new Dictionary<KeyCode, object>();
|
||||
|
||||
return (bool)m_btnIsPressedProp.GetValue(actualKey, null);
|
||||
internal object GetActualKey(KeyCode key)
|
||||
{
|
||||
if (!ActualKeyDict.ContainsKey(key))
|
||||
{
|
||||
var s = key.ToString();
|
||||
if (s.Contains("Control"))
|
||||
s = s.Replace("Control", "Ctrl");
|
||||
else if (s.Contains("Return"))
|
||||
s = "Enter";
|
||||
|
||||
var parsed = Enum.Parse(TKey, s);
|
||||
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });
|
||||
|
||||
ActualKeyDict.Add(key, actualKey);
|
||||
}
|
||||
|
||||
return ActualKeyDict[key];
|
||||
}
|
||||
|
||||
public bool GetKeyDown(KeyCode key) => (bool)m_btnWasPressedProp.GetValue(GetActualKey(key), null);
|
||||
|
||||
public bool GetKey(KeyCode key) => (bool)m_btnIsPressedProp.GetValue(GetActualKey(key), null);
|
||||
|
||||
public bool GetMouseButtonDown(int btn)
|
||||
{
|
||||
switch (btn)
|
||||
@ -103,5 +128,44 @@ namespace UnityExplorer.Input
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
// UI Input
|
||||
|
||||
//public Type TInputSystemUIInputModule
|
||||
// => m_tUIInputModule
|
||||
// ?? (m_tUIInputModule = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
|
||||
//internal Type m_tUIInputModule;
|
||||
|
||||
public BaseInputModule UIModule => null; // m_newInputModule;
|
||||
//internal BaseInputModule m_newInputModule;
|
||||
|
||||
public PointerEventData InputPointerEvent => null;
|
||||
|
||||
public void AddUIInputModule()
|
||||
{
|
||||
// if (TInputSystemUIInputModule != null)
|
||||
// {
|
||||
//#if CPP
|
||||
// // m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
|
||||
//#else
|
||||
// m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
|
||||
//#endif
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ExplorerCore.LogWarning("New input system: Could not find type by name 'UnityEngine.InputSystem.UI.InputSystemUIInputModule'");
|
||||
// }
|
||||
}
|
||||
|
||||
public void ActivateModule()
|
||||
{
|
||||
//#if CPP
|
||||
// // m_newInputModule.ActivateModule();
|
||||
//#else
|
||||
// m_newInputModule.ActivateModule();
|
||||
//#endif
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
{
|
||||
@ -36,5 +38,27 @@ namespace UnityExplorer.Input
|
||||
public bool GetMouseButton(int btn) => (bool)m_getMouseButtonMethod.Invoke(null, new object[] { btn });
|
||||
|
||||
public bool GetMouseButtonDown(int btn) => (bool)m_getMouseButtonDownMethod.Invoke(null, new object[] { btn });
|
||||
|
||||
// UI Input module
|
||||
|
||||
public BaseInputModule UIModule => m_inputModule;
|
||||
internal StandaloneInputModule m_inputModule;
|
||||
|
||||
public PointerEventData InputPointerEvent =>
|
||||
#if CPP
|
||||
m_inputModule.m_InputPointerEvent;
|
||||
#else
|
||||
null;
|
||||
#endif
|
||||
|
||||
public void AddUIInputModule()
|
||||
{
|
||||
m_inputModule = UIManager.CanvasRoot.gameObject.AddComponent<StandaloneInputModule>();
|
||||
}
|
||||
|
||||
public void ActivateModule()
|
||||
{
|
||||
m_inputModule.ActivateModule();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityExplorer.Input
|
||||
{
|
||||
@ -13,5 +14,10 @@ namespace UnityExplorer.Input
|
||||
|
||||
public bool GetMouseButton(int btn) => false;
|
||||
public bool GetMouseButtonDown(int btn) => false;
|
||||
|
||||
public BaseInputModule UIModule => null;
|
||||
public PointerEventData InputPointerEvent => null;
|
||||
public void ActivateModule() { }
|
||||
public void AddUIInputModule() { }
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ namespace UnityExplorer.Inspectors.GameObjects
|
||||
{
|
||||
var vertGroupObj = UIFactory.CreateVerticalGroup(parent, new Color(1, 1, 1, 0));
|
||||
var vertGroup = vertGroupObj.GetComponent<VerticalLayoutGroup>();
|
||||
vertGroup.childForceExpandHeight = false;
|
||||
vertGroup.childForceExpandHeight = true;
|
||||
vertGroup.childForceExpandWidth = false;
|
||||
vertGroup.childControlWidth = true;
|
||||
vertGroup.spacing = 5;
|
||||
|
@ -136,7 +136,7 @@ namespace UnityExplorer.Inspectors.GameObjects
|
||||
{
|
||||
var vertGroupObj = UIFactory.CreateVerticalGroup(parent, new Color(1, 1, 1, 0));
|
||||
var vertGroup = vertGroupObj.GetComponent<VerticalLayoutGroup>();
|
||||
vertGroup.childForceExpandHeight = false;
|
||||
vertGroup.childForceExpandHeight = true;
|
||||
vertGroup.childForceExpandWidth = false;
|
||||
vertGroup.childControlWidth = true;
|
||||
vertGroup.spacing = 5;
|
||||
@ -157,6 +157,7 @@ namespace UnityExplorer.Inspectors.GameObjects
|
||||
var compScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_compListContent, out SliderScrollbar scroller, new Color(0.07f, 0.07f, 0.07f));
|
||||
var contentLayout = compScrollObj.AddComponent<LayoutElement>();
|
||||
contentLayout.minHeight = 50;
|
||||
contentLayout.flexibleHeight = 5000;
|
||||
|
||||
s_compListPageHandler = new PageHandler(scroller);
|
||||
s_compListPageHandler.ConstructUI(vertGroupObj);
|
||||
|
@ -164,7 +164,7 @@ namespace UnityExplorer.Inspectors
|
||||
m_layerDropdown.value = TargetGO.layer;
|
||||
}
|
||||
|
||||
if (m_lastScene != TargetGO.scene.name)
|
||||
if (string.IsNullOrEmpty(m_lastScene) || m_lastScene != TargetGO.scene.name)
|
||||
{
|
||||
m_lastScene = TargetGO.scene.name;
|
||||
|
||||
@ -217,10 +217,20 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
s_content = UIFactory.CreateScrollView(parent, out GameObject scrollContent, out _, new Color(0.1f, 0.1f, 0.1f));
|
||||
|
||||
var parentLayout = scrollContent.transform.parent.gameObject.AddComponent<VerticalLayoutGroup>();
|
||||
parentLayout.childForceExpandWidth = true;
|
||||
parentLayout.childControlWidth = true;
|
||||
parentLayout.childForceExpandHeight = true;
|
||||
parentLayout.childControlHeight = true;
|
||||
|
||||
var scrollGroup = scrollContent.GetComponent<VerticalLayoutGroup>();
|
||||
scrollGroup.childForceExpandHeight = true;
|
||||
scrollGroup.childControlHeight = true;
|
||||
scrollGroup.childForceExpandWidth = true;
|
||||
scrollGroup.childControlWidth = true;
|
||||
scrollGroup.spacing = 5;
|
||||
var contentFitter = scrollContent.GetComponent<ContentSizeFitter>();
|
||||
contentFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained;
|
||||
|
||||
ConstructTopArea(scrollContent);
|
||||
|
||||
@ -230,6 +240,9 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
s_childList.ConstructChildList(midGroupObj);
|
||||
s_compList.ConstructCompList(midGroupObj);
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(s_content.GetComponent<RectTransform>());
|
||||
Canvas.ForceUpdateCanvases();
|
||||
}
|
||||
|
||||
private void ConstructTopArea(GameObject scrollContent)
|
||||
@ -431,11 +444,10 @@ namespace UnityExplorer.Inspectors
|
||||
midGroup.childControlWidth = true;
|
||||
midGroup.childForceExpandHeight = true;
|
||||
midGroup.childControlHeight = true;
|
||||
var midlayout = midGroupObj.AddComponent<LayoutElement>();
|
||||
midlayout.minHeight = 350;
|
||||
midlayout.flexibleHeight = 10000;
|
||||
midlayout.minWidth = 200;
|
||||
midlayout.flexibleWidth = 25000;
|
||||
|
||||
var midLayout = midGroupObj.AddComponent<LayoutElement>();
|
||||
midLayout.minHeight = 300;
|
||||
midLayout.flexibleHeight = 5000;
|
||||
|
||||
return midGroupObj;
|
||||
}
|
||||
|
@ -230,84 +230,6 @@ namespace UnityExplorer.Inspectors
|
||||
invisGroup.padding.right = 2;
|
||||
invisGroup.spacing = 10;
|
||||
|
||||
// // time scale group
|
||||
|
||||
// var timeGroupObj = UIFactory.CreateHorizontalGroup(invisObj, new Color(1, 1, 1, 0));
|
||||
// var timeGroup = timeGroupObj.GetComponent<HorizontalLayoutGroup>();
|
||||
// timeGroup.childForceExpandWidth = false;
|
||||
// timeGroup.childControlWidth = true;
|
||||
// timeGroup.childForceExpandHeight = false;
|
||||
// timeGroup.childControlHeight = true;
|
||||
// timeGroup.padding.top = 2;
|
||||
// timeGroup.padding.left = 5;
|
||||
// timeGroup.padding.right = 2;
|
||||
// timeGroup.padding.bottom = 2;
|
||||
// timeGroup.spacing = 5;
|
||||
// timeGroup.childAlignment = TextAnchor.MiddleCenter;
|
||||
// var timeGroupLayout = timeGroupObj.AddComponent<LayoutElement>();
|
||||
// timeGroupLayout.minWidth = 100;
|
||||
// timeGroupLayout.flexibleWidth = 300;
|
||||
// timeGroupLayout.minHeight = 25;
|
||||
// timeGroupLayout.flexibleHeight = 0;
|
||||
|
||||
// // time scale title
|
||||
|
||||
// var timeTitleObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
|
||||
// var timeTitle = timeTitleObj.GetComponent<Text>();
|
||||
// timeTitle.text = "Time Scale:";
|
||||
// timeTitle.color = new Color(21f / 255f, 192f / 255f, 235f / 255f);
|
||||
// var titleLayout = timeTitleObj.AddComponent<LayoutElement>();
|
||||
// titleLayout.minHeight = 25;
|
||||
// titleLayout.minWidth = 80;
|
||||
// titleLayout.flexibleHeight = 0;
|
||||
// timeTitle.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
|
||||
// // actual active time label
|
||||
|
||||
// var timeLabelObj = UIFactory.CreateLabel(timeGroupObj, TextAnchor.MiddleLeft);
|
||||
// var timeLabelLayout = timeLabelObj.AddComponent<LayoutElement>();
|
||||
// timeLabelLayout.minWidth = 40;
|
||||
// timeLabelLayout.minHeight = 25;
|
||||
// timeLabelLayout.flexibleHeight = 0;
|
||||
|
||||
// // todo make static and update
|
||||
// var s_timeText = timeLabelObj.GetComponent<Text>();
|
||||
// s_timeText.text = Time.timeScale.ToString("F1");
|
||||
|
||||
// // time scale input
|
||||
|
||||
// var timeInputObj = UIFactory.CreateInputField(timeGroupObj);
|
||||
// var timeInput = timeInputObj.GetComponent<InputField>();
|
||||
// timeInput.characterValidation = InputField.CharacterValidation.Decimal;
|
||||
// var timeInputLayout = timeInputObj.AddComponent<LayoutElement>();
|
||||
// timeInputLayout.minWidth = 90;
|
||||
// timeInputLayout.flexibleWidth = 0;
|
||||
// timeInputLayout.minHeight = 25;
|
||||
// timeInputLayout.flexibleHeight = 0;
|
||||
|
||||
// // time scale apply button
|
||||
|
||||
// var applyBtnObj = UIFactory.CreateButton(timeGroupObj);
|
||||
// var applyBtn = applyBtnObj.GetComponent<Button>();
|
||||
|
||||
// applyBtn.onClick.AddListener(SetTimeScale);
|
||||
|
||||
// var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||
// applyText.text = "Apply";
|
||||
// applyText.fontSize = 14;
|
||||
// var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
|
||||
// applyLayout.minWidth = 50;
|
||||
// applyLayout.minHeight = 25;
|
||||
// applyLayout.flexibleHeight = 0;
|
||||
|
||||
// void SetTimeScale()
|
||||
// {
|
||||
// var scale = float.Parse(timeInput.text);
|
||||
// Time.timeScale = scale;
|
||||
// s_timeText.text = Time.timeScale.ToString("F1");
|
||||
// }
|
||||
|
||||
|
||||
// inspect under mouse button
|
||||
|
||||
var inspectObj = UIFactory.CreateButton(topRowObj);
|
||||
|
@ -96,7 +96,10 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
private void SetValueFromDropdown()
|
||||
{
|
||||
var type = Value?.GetType() ?? FallbackType;
|
||||
var value = Enum.Parse(type, m_dropdownText.text);
|
||||
var index = m_dropdown.value;
|
||||
|
||||
var value = Enum.Parse(type, s_enumNamesCache[type][index].Value);
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
Value = value;
|
||||
|
@ -100,7 +100,7 @@ namespace UnityExplorer.UI
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.Log($"Exception on CursorControl.Init! {e.GetType()}, {e.Message}");
|
||||
ExplorerCore.Log($"Exception on ForceUnlockCursor.Init! {e.GetType()}, {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,13 +164,20 @@ namespace UnityExplorer.UI
|
||||
|
||||
public static void SetEventSystem()
|
||||
{
|
||||
if (InputManager.CurrentType == InputType.InputSystem)
|
||||
return;
|
||||
|
||||
m_settingEventSystem = true;
|
||||
UIManager.SetEventSystem();
|
||||
EventSystem.current = UIManager.EventSys;
|
||||
InputManager.ActivateUIModule();
|
||||
m_settingEventSystem = false;
|
||||
}
|
||||
|
||||
public static void ReleaseEventSystem()
|
||||
{
|
||||
if (InputManager.CurrentType == InputType.InputSystem)
|
||||
return;
|
||||
|
||||
if (m_lastEventSystem)
|
||||
{
|
||||
m_settingEventSystem = true;
|
||||
|
@ -178,13 +178,9 @@ namespace UnityExplorer.UI
|
||||
|
||||
Image image = groupObj.AddComponent<Image>();
|
||||
if (color != default)
|
||||
{
|
||||
image.color = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
image.color = new Color(44f / 255f, 44f / 255f, 44f / 255f);
|
||||
}
|
||||
|
||||
return groupObj;
|
||||
}
|
||||
@ -657,16 +653,16 @@ namespace UnityExplorer.UI
|
||||
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
||||
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
|
||||
var contentLayout = content.AddComponent<VerticalLayoutGroup>();
|
||||
contentLayout.childForceExpandHeight = true;
|
||||
contentLayout.childControlHeight = true;
|
||||
contentLayout.childForceExpandWidth = true;
|
||||
contentLayout.childControlWidth = true;
|
||||
contentLayout.padding.left = 5;
|
||||
contentLayout.padding.right = 5;
|
||||
contentLayout.padding.top = 5;
|
||||
contentLayout.padding.bottom = 5;
|
||||
contentLayout.spacing = 5;
|
||||
var contentGroup = content.AddComponent<VerticalLayoutGroup>();
|
||||
contentGroup.childForceExpandHeight = true;
|
||||
contentGroup.childControlHeight = true;
|
||||
contentGroup.childForceExpandWidth = true;
|
||||
contentGroup.childControlWidth = true;
|
||||
contentGroup.padding.left = 5;
|
||||
contentGroup.padding.right = 5;
|
||||
contentGroup.padding.top = 5;
|
||||
contentGroup.padding.bottom = 5;
|
||||
contentGroup.spacing = 5;
|
||||
|
||||
GameObject scrollBarObj = CreateUIObject("DynamicScrollbar", mainObj);
|
||||
|
||||
|
@ -8,6 +8,7 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.UI.Shared;
|
||||
using UnityExplorer.Input;
|
||||
#if CPP
|
||||
using UnityExplorer.Unstrip;
|
||||
#endif
|
||||
@ -18,37 +19,13 @@ namespace UnityExplorer.UI
|
||||
{
|
||||
public static GameObject CanvasRoot { get; private set; }
|
||||
public static EventSystem EventSys { get; private set; }
|
||||
public static StandaloneInputModule InputModule { get; private set; }
|
||||
|
||||
//internal static Material UIMaterial { get; private set; }
|
||||
internal static Sprite ResizeCursor { get; private set; }
|
||||
internal static Font ConsoleFont { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\explorerui.bundle";
|
||||
if (File.Exists(bundlePath))
|
||||
{
|
||||
var bundle = AssetBundle.LoadFromFile(bundlePath);
|
||||
|
||||
// Fix for games which don't ship with 'UI/Default' shader.
|
||||
if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default")
|
||||
{
|
||||
ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader...");
|
||||
Graphic.defaultGraphicMaterial.shader = bundle.LoadAsset<Shader>("DefaultUI");
|
||||
}
|
||||
|
||||
ResizeCursor = bundle.LoadAsset<Sprite>("cursor");
|
||||
|
||||
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
|
||||
|
||||
ExplorerCore.Log("Loaded UI bundle");
|
||||
}
|
||||
else
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not find the ExplorerUI Bundle! It should exist at '" + bundlePath + "'");
|
||||
return;
|
||||
}
|
||||
LoadBundle();
|
||||
|
||||
// Create core UI Canvas and Event System handler
|
||||
CreateRootCanvas();
|
||||
@ -62,12 +39,6 @@ namespace UnityExplorer.UI
|
||||
Canvas.ForceUpdateCanvases();
|
||||
}
|
||||
|
||||
public static void SetEventSystem()
|
||||
{
|
||||
EventSystem.current = EventSys;
|
||||
InputModule.ActivateModule();
|
||||
}
|
||||
|
||||
public static void OnSceneChange()
|
||||
{
|
||||
SceneExplorer.Instance?.OnSceneChange();
|
||||
@ -78,23 +49,20 @@ namespace UnityExplorer.UI
|
||||
{
|
||||
MainMenu.Instance?.Update();
|
||||
|
||||
if (EventSys && InputModule)
|
||||
if (EventSys)
|
||||
{
|
||||
if (EventSystem.current != EventSys)
|
||||
{
|
||||
ForceUnlockCursor.SetEventSystem();
|
||||
//ForceUnlockCursor.Unlock = true;
|
||||
}
|
||||
|
||||
// Fix for games which override the InputModule pointer events (eg, VRChat)
|
||||
#if CPP
|
||||
if (InputModule.m_InputPointerEvent != null)
|
||||
// Fix for games which override the InputModule pointer events (eg, VRChat)
|
||||
var evt = InputManager.InputPointerEvent;
|
||||
if (evt != null)
|
||||
{
|
||||
PointerEventData evt = InputModule.m_InputPointerEvent;
|
||||
if (!evt.eligibleForClick && evt.selectedObject)
|
||||
{
|
||||
evt.eligibleForClick = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -125,6 +93,33 @@ namespace UnityExplorer.UI
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadBundle()
|
||||
{
|
||||
var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\explorerui.bundle";
|
||||
if (File.Exists(bundlePath))
|
||||
{
|
||||
var bundle = AssetBundle.LoadFromFile(bundlePath);
|
||||
|
||||
// Fix for games which don't ship with 'UI/Default' shader.
|
||||
if (Graphic.defaultGraphicMaterial.shader?.name != "UI/Default")
|
||||
{
|
||||
ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader...");
|
||||
Graphic.defaultGraphicMaterial.shader = bundle.LoadAsset<Shader>("DefaultUI");
|
||||
}
|
||||
|
||||
ResizeCursor = bundle.LoadAsset<Sprite>("cursor");
|
||||
|
||||
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
|
||||
|
||||
ExplorerCore.Log("Loaded UI bundle");
|
||||
}
|
||||
else
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not find the ExplorerUI Bundle! It should exist at '" + bundlePath + "'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static GameObject CreateRootCanvas()
|
||||
{
|
||||
GameObject rootObj = new GameObject("ExplorerCanvas");
|
||||
@ -135,8 +130,7 @@ namespace UnityExplorer.UI
|
||||
CanvasRoot.transform.position = new Vector3(0f, 0f, 1f);
|
||||
|
||||
EventSys = rootObj.AddComponent<EventSystem>();
|
||||
InputModule = rootObj.AddComponent<StandaloneInputModule>();
|
||||
InputModule.ActivateModule();
|
||||
InputManager.AddUIModule();
|
||||
|
||||
Canvas canvas = rootObj.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
|
Reference in New Issue
Block a user