diff --git a/src/Console/AutoCompleter.cs b/src/Console/AutoCompleter.cs index 902a3c0..51e93b4 100644 --- a/src/Console/AutoCompleter.cs +++ b/src/Console/AutoCompleter.cs @@ -155,6 +155,19 @@ namespace UnityExplorer.Console pos = editor.InputField.transform.TransformPoint(pos); + // fix position when scrolled down + var scrollSize = editor.InputField.verticalScrollbar.size; + var scrollValue = editor.InputField.verticalScrollbar.value; + + scrollSize += (1 - scrollSize) * (1 - scrollValue); + + if (!Mathf.Approximately(scrollSize, 1)) + { + var height = editor.InputField.textViewport.rect.height; + + pos.y += (1 / scrollSize * height) - height; + } + m_mainObj.transform.position = new Vector3(pos.x, pos.y - 3, 0); } } diff --git a/src/ExplorerBepInPlugin.cs b/src/ExplorerBepInPlugin.cs index 61d4d52..0528a81 100644 --- a/src/ExplorerBepInPlugin.cs +++ b/src/ExplorerBepInPlugin.cs @@ -33,7 +33,7 @@ namespace UnityExplorer new ExplorerCore(); - HarmonyInstance.PatchAll(); + // HarmonyInstance.PatchAll(); } internal static void DoSceneChange(Scene arg0, Scene arg1) diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index a8f9223..a885526 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -4,6 +4,7 @@ using UnityExplorer.Input; using UnityExplorer.UI; using UnityExplorer.UI.PageModel; using UnityEngine; +using UnityExplorer.Inspectors; namespace UnityExplorer { @@ -87,13 +88,20 @@ namespace UnityExplorer if (!m_doneUIInit) CheckUIInit(); - if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle)) - ShowMenu = !ShowMenu; - - if (ShowMenu) + if (MouseInspector.Enabled) { - ForceUnlockCursor.Update(); - UIManager.Update(); + MouseInspector.UpdateInspect(); + } + else + { + if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle)) + ShowMenu = !ShowMenu; + + if (ShowMenu) + { + ForceUnlockCursor.Update(); + UIManager.Update(); + } } } diff --git a/src/Inspectors/GOInspector/ChildList.cs b/src/Inspectors/GOInspector/ChildList.cs new file mode 100644 index 0000000..48a9b6a --- /dev/null +++ b/src/Inspectors/GOInspector/ChildList.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityExplorer.Helpers; +using UnityExplorer.UI; +using UnityExplorer.UI.Shared; +using TMPro; +using UnityEngine; +using UnityEngine.UI; +using UnityExplorer.Input; + +namespace UnityExplorer.Inspectors.GOInspector +{ + public class ChildList + { + internal static ChildList Instance; + + public ChildList() + { + Instance = this; + } + + public static PageHandler s_childListPageHandler; + private static GameObject[] s_allChildren = new GameObject[0]; + private static readonly List s_childrenShortlist = new List(); + private static GameObject s_childListContent; + private static readonly List s_childListTexts = new List(); + private static int s_lastChildCount; + + internal void RefreshChildObjectList() + { + var go = GameObjectInspector.ActiveInstance.TargetGO; + + s_allChildren = new GameObject[go.transform.childCount]; + for (int i = 0; i < go.transform.childCount; i++) + { + var child = go.transform.GetChild(i); + s_allChildren[i] = child.gameObject; + } + + var objects = s_allChildren; + s_childListPageHandler.ListCount = objects.Length; + + int newCount = 0; + + foreach (var itemIndex in s_childListPageHandler) + { + newCount++; + + // normalized index starting from 0 + var i = itemIndex - s_childListPageHandler.StartIndex; + + if (itemIndex >= objects.Length) + { + if (i > s_lastChildCount || i >= s_childListTexts.Count) + break; + + GameObject label = s_childListTexts[i].transform.parent.parent.gameObject; + if (label.activeSelf) + label.SetActive(false); + } + else + { + GameObject obj = objects[itemIndex]; + + if (!obj) + continue; + + if (i >= s_childrenShortlist.Count) + { + s_childrenShortlist.Add(obj); + AddChildListButton(); + } + else + { + s_childrenShortlist[i] = obj; + } + + var text = s_childListTexts[i]; + + var name = obj.name; + + if (obj.transform.childCount > 0) + name = $"[{obj.transform.childCount}] {name}"; + + text.text = name; + text.color = obj.activeSelf ? Color.green : Color.red; + + var label = text.transform.parent.parent.gameObject; + if (!label.activeSelf) + { + label.SetActive(true); + } + } + } + + s_lastChildCount = newCount; + } + + internal static void OnChildListObjectClicked(int index) + { + if (GameObjectInspector.ActiveInstance == null) + return; + + if (index >= s_childrenShortlist.Count || !s_childrenShortlist[index]) + return; + + GameObjectInspector.ActiveInstance.ChangeInspectorTarget(s_childrenShortlist[index]); + GameObjectInspector.ActiveInstance.Update(); + } + + internal static void OnChildListPageTurn() + { + if (Instance == null) + return; + + Instance.RefreshChildObjectList(); + } + + #region UI CONSTRUCTION + + internal void ConstructChildList(GameObject parent) + { + var vertGroupObj = UIFactory.CreateVerticalGroup(parent, new Color(1, 1, 1, 0)); + var vertGroup = vertGroupObj.GetComponent(); + vertGroup.childForceExpandHeight = false; + vertGroup.childForceExpandWidth = false; + vertGroup.childControlWidth = true; + vertGroup.spacing = 5; + var vertLayout = vertGroupObj.AddComponent(); + vertLayout.minWidth = 120; + vertLayout.flexibleWidth = 25000; + vertLayout.minHeight = 200; + vertLayout.flexibleHeight = 5000; + + var childTitleObj = UIFactory.CreateLabel(vertGroupObj, TextAnchor.MiddleLeft); + var childTitleText = childTitleObj.GetComponent(); + childTitleText.text = "Children"; + childTitleText.color = Color.grey; + childTitleText.fontSize = 14; + var childTitleLayout = childTitleObj.AddComponent(); + childTitleLayout.minHeight = 30; + + s_childListPageHandler = new PageHandler(); + s_childListPageHandler.ConstructUI(vertGroupObj); + s_childListPageHandler.OnPageChanged += OnChildListPageTurn; + + var childrenScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_childListContent, new Color(0.07f, 0.07f, 0.07f)); + var contentLayout = childrenScrollObj.GetComponent(); + contentLayout.minHeight = 50; + } + + internal void AddChildListButton() + { + int thisIndex = s_childListTexts.Count; + + GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_childListContent, new Color(0.1f, 0.1f, 0.1f)); + HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent(); + btnGroup.childForceExpandWidth = true; + btnGroup.childControlWidth = true; + btnGroup.childForceExpandHeight = false; + btnGroup.childControlHeight = true; + LayoutElement btnLayout = btnGroupObj.AddComponent(); + btnLayout.flexibleWidth = 320; + btnLayout.minHeight = 25; + btnLayout.flexibleHeight = 0; + btnGroupObj.AddComponent(); + + GameObject mainButtonObj = UIFactory.CreateButton(btnGroupObj); + LayoutElement mainBtnLayout = mainButtonObj.AddComponent(); + mainBtnLayout.minHeight = 25; + mainBtnLayout.flexibleHeight = 0; + mainBtnLayout.minWidth = 240; + mainBtnLayout.flexibleWidth = 0; + Button mainBtn = mainButtonObj.GetComponent