From e4d38af4f5271e626da0c0f3258fc15486fca28f Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Wed, 11 Nov 2020 20:16:43 +1100 Subject: [PATCH] Lots of fixes, everything basically done except Reflection Inspector --- src/Console/AutoCompleter.cs | 36 +--- src/Console/CSharpLexer.cs | 4 +- src/Console/CodeEditor.cs | 87 ++-------- src/Console/ScriptInteraction.cs | 2 +- src/ExplorerCore.cs | 2 +- src/Inspectors/GameObjectInspector.cs | 4 +- src/Inspectors/InspectorManager.cs | 2 +- .../Reflection/CacheObject/CacheFactory.cs | 4 +- .../Reflection/CacheObject/CacheField.cs | 16 +- .../Reflection/CacheObject/CacheMember.cs | 119 ++++++++++---- .../Reflection/CacheObject/CacheMethod.cs | 78 +-------- .../Reflection/CacheObject/CacheObjectBase.cs | 154 +++++++++--------- .../Reflection/CacheObject/CacheProperty.cs | 20 +-- .../InteractiveValue/InteractiveValue.cs | 55 ++++++- src/Inspectors/ReflectionInspector.cs | 92 ++++++++--- src/Inspectors/SceneExplorer.cs | 2 +- src/UI/MainMenu.cs | 28 +++- src/UI/{PageModel => Modules}/ConsolePage.cs | 27 ++- src/UI/{PageModel => Modules}/DebugConsole.cs | 71 ++++---- src/UI/{PageModel => Modules}/HomePage.cs | 2 +- src/UI/{PageModel => Modules}/OptionsPage.cs | 2 +- src/UI/{PageModel => Modules}/SearchPage.cs | 2 +- src/UI/Shared/InputFieldScroller.cs | 108 ++++++++++++ src/UI/Shared/SliderScrollbar.cs | 4 +- src/UI/UIFactory.cs | 42 +++-- src/UI/UIManager.cs | 23 ++- src/UnityExplorer.csproj | 11 +- 27 files changed, 569 insertions(+), 428 deletions(-) rename src/UI/{PageModel => Modules}/ConsolePage.cs (86%) rename src/UI/{PageModel => Modules}/DebugConsole.cs (80%) rename src/UI/{PageModel => Modules}/HomePage.cs (97%) rename src/UI/{PageModel => Modules}/OptionsPage.cs (99%) rename src/UI/{PageModel => Modules}/SearchPage.cs (99%) create mode 100644 src/UI/Shared/InputFieldScroller.cs diff --git a/src/Console/AutoCompleter.cs b/src/Console/AutoCompleter.cs index 39e7254..58e3a45 100644 --- a/src/Console/AutoCompleter.cs +++ b/src/Console/AutoCompleter.cs @@ -5,7 +5,7 @@ using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using UnityExplorer.UI; -using UnityExplorer.UI.PageModel; +using UnityExplorer.UI.Modules; namespace UnityExplorer.Console { @@ -132,44 +132,22 @@ namespace UnityExplorer.Console try { var editor = ConsolePage.Instance.m_codeEditor; - var textGen = editor.InputText.cachedTextGenerator; - - //if (textGen.characters.Count < 1) - // return; - int caretPos = editor.InputField.caretPosition; - if (caretPos >= 1) - caretPos--; - - if (caretPos < 0 || caretPos == m_lastCaretPos) + if (caretPos == m_lastCaretPos) return; m_lastCaretPos = caretPos; + if (caretPos >= 1) + caretPos--; + var pos = textGen.characters[caretPos].cursorPos; - // todo this calculation isnt the right one to use. It's wrong if we hide the Debug Console. + pos = editor.InputField.transform.TransformPoint(pos); - var posOffset = MainMenu.Instance.MainPanel.transform.position; - - pos = (Vector2)posOffset + pos + new Vector2(25, 35); - - //// 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); + m_mainObj.transform.position = new Vector3(pos.x + 10, pos.y - 20, 0); } catch //(Exception e) { diff --git a/src/Console/CSharpLexer.cs b/src/Console/CSharpLexer.cs index 87b653c..479f207 100644 --- a/src/Console/CSharpLexer.cs +++ b/src/Console/CSharpLexer.cs @@ -27,8 +27,8 @@ namespace UnityExplorer.Console private int currentIndex; private int currentLookaheadIndex; - public char Current { get; private set; } = ' '; - public char Previous { get; private set; } = ' '; + public char Current { get; private set; } + public char Previous { get; private set; } public bool EndOfStream => currentLookaheadIndex >= inputString.Length; diff --git a/src/Console/CodeEditor.cs b/src/Console/CodeEditor.cs index c8d1cc0..996932e 100644 --- a/src/Console/CodeEditor.cs +++ b/src/Console/CodeEditor.cs @@ -7,9 +7,10 @@ using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using UnityExplorer.UI; -using UnityExplorer.UI.PageModel; +using UnityExplorer.UI.Modules; using System.Collections.Generic; using System.Reflection; +using UnityExplorer.UI.Shared; #if CPP using UnityExplorer.Unstrip; using UnityExplorer.Helpers; @@ -26,11 +27,9 @@ namespace UnityExplorer.Console public Text InputText { get; internal set; } public int CurrentIndent { get; private set; } - private Text inputHighlightText; - private Image background; - private Image scrollbar; - public string HighlightedText => inputHighlightText.text; + private Text inputHighlightText; + private readonly CSharpLexer highlightLexer; private readonly StringBuilder sbHighlight; @@ -68,7 +67,6 @@ The following helper methods are available: ConstructUI(); - // subscribe to text input changing #if CPP InputField.onValueChanged.AddListener(new Action((string s) => { OnInputChanged(s); })); #else @@ -364,51 +362,20 @@ The following helper methods are available: #region CONSOLE INPUT - var consoleBase = UIFactory.CreateUIObject("CodeEditor", ConsolePage.Instance.Content); + int fontSize = 16; - var consoleLayout = consoleBase.AddComponent(); - consoleLayout.preferredHeight = 500; - consoleLayout.flexibleHeight = 50; + var inputObj = UIFactory.CreateSrollInputField(ConsolePage.Instance.Content, out InputFieldScroller consoleScroll, fontSize); - consoleBase.AddComponent(); - - var mainRect = consoleBase.GetComponent(); - mainRect.pivot = Vector2.one * 0.5f; - mainRect.anchorMin = Vector2.zero; - mainRect.anchorMax = Vector2.one; - mainRect.offsetMin = Vector2.zero; - mainRect.offsetMax = Vector2.zero; - - var mainBg = UIFactory.CreateUIObject("MainBackground", consoleBase); - - var mainBgRect = mainBg.GetComponent(); - mainBgRect.pivot = new Vector2(0, 1); - mainBgRect.anchorMin = Vector2.zero; - mainBgRect.anchorMax = Vector2.one; - mainBgRect.offsetMin = Vector2.zero; - mainBgRect.offsetMax = Vector2.zero; - - var mainBgImage = mainBg.AddGraphic(); - - var inputObj = UIFactory.CreateInputField(consoleBase, 14, 0); - - var inputField = inputObj.GetComponent(); - //inputField.richText = false; - //inputField.restoreOriginalTextOnEscape = false; - - var inputRect = inputObj.GetComponent(); - inputRect.pivot = new Vector2(0, 1); - inputRect.anchorMin = Vector2.zero; - inputRect.anchorMax = Vector2.one; - inputRect.offsetMin = new Vector2(20, 0); - inputRect.offsetMax = new Vector2(14, 0); + var inputField = consoleScroll.inputField; var mainTextObj = inputField.textComponent.gameObject; - - var mainTextInput = mainTextObj.GetComponent(); + var mainTextInput = inputField.textComponent; + mainTextInput.supportRichText = false; + mainTextInput.color = new Color(1, 1, 1, 0.5f); var placeHolderText = inputField.placeholder.GetComponent(); placeHolderText.text = STARTUP_TEXT; + placeHolderText.fontSize = fontSize; var highlightTextObj = UIFactory.CreateUIObject("HighlightText", mainTextObj.gameObject); var highlightTextRect = highlightTextObj.GetComponent(); @@ -420,25 +387,7 @@ The following helper methods are available: var highlightTextInput = highlightTextObj.AddGraphic(); highlightTextInput.supportRichText = true; - - var scroll = UIFactory.CreateScrollbar(consoleBase); - - var scrollRect = scroll.GetComponent(); - scrollRect.anchorMin = new Vector2(1, 0); - scrollRect.anchorMax = new Vector2(1, 1); - scrollRect.pivot = new Vector2(0.5f, 1); - scrollRect.offsetMin = new Vector2(-25f, 0); - - var scroller = scroll.GetComponent(); - scroller.direction = Scrollbar.Direction.TopToBottom; - var scrollColors = scroller.colors; - scrollColors.normalColor = new Color(0.6f, 0.6f, 0.6f, 1.0f); - scroller.colors = scrollColors; - - var scrollImage = scroll.GetComponent(); - - inputField.GetComponentInChildren().enabled = false; - inputObj.GetComponent().enabled = false; + highlightTextInput.fontSize = fontSize; #endregion @@ -475,9 +424,10 @@ The following helper methods are available: #endregion - mainTextInput.supportRichText = false; + //mainTextInput.supportRichText = false; mainTextInput.font = UIManager.ConsoleFont; + placeHolderText.font = UIManager.ConsoleFont; highlightTextInput.font = UIManager.ConsoleFont; // reset this after formatting finalized @@ -492,15 +442,6 @@ The following helper methods are available: this.InputText = mainTextInput; this.inputHighlightText = highlightTextInput; - this.background = mainBgImage; - this.scrollbar = scrollImage; - - // set some colors - InputField.caretColor = Color.white; - InputText.color = new Color(1, 1, 1, 0.51f); - inputHighlightText.color = Color.white; - background.color = new Color32(37, 37, 37, 255); - scrollbar.color = new Color32(45, 50, 50, 255); } } } diff --git a/src/Console/ScriptInteraction.cs b/src/Console/ScriptInteraction.cs index 040d287..ad235a7 100644 --- a/src/Console/ScriptInteraction.cs +++ b/src/Console/ScriptInteraction.cs @@ -1,7 +1,7 @@ using System; using Mono.CSharp; using UnityExplorer.UI; -using UnityExplorer.UI.PageModel; +using UnityExplorer.UI.Modules; using UnityExplorer.Inspectors; namespace UnityExplorer.Console diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 5ffc0d0..7a57c7a 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -2,7 +2,7 @@ using UnityExplorer.Config; using UnityExplorer.Input; using UnityExplorer.UI; -using UnityExplorer.UI.PageModel; +using UnityExplorer.UI.Modules; using UnityEngine; using UnityExplorer.Inspectors; using System.IO; diff --git a/src/Inspectors/GameObjectInspector.cs b/src/Inspectors/GameObjectInspector.cs index 38213cf..7538633 100644 --- a/src/Inspectors/GameObjectInspector.cs +++ b/src/Inspectors/GameObjectInspector.cs @@ -63,7 +63,7 @@ namespace UnityExplorer.Inspectors if (!TargetGO) { - ExplorerCore.LogWarning("GameObjectInspector cctor: Target GameObject is null!"); + ExplorerCore.LogWarning("Target GameObject is null!"); return; } @@ -292,6 +292,7 @@ namespace UnityExplorer.Inspectors m_pathInput = pathInputObj.GetComponent(); m_pathInput.text = TargetGO.transform.GetTransformPath(); m_pathInput.readOnly = true; + m_pathInput.lineType = InputField.LineType.MultiLineNewline; var pathInputLayout = pathInputObj.AddComponent(); pathInputLayout.minHeight = 25; pathInputLayout.flexibleHeight = 75; @@ -337,7 +338,6 @@ namespace UnityExplorer.Inspectors nameInputRect.sizeDelta = new Vector2(nameInputRect.sizeDelta.x, 25); m_nameInput = nameInputObj.GetComponent(); m_nameInput.text = TargetGO.name; - m_nameInput.lineType = InputField.LineType.SingleLine; var applyNameBtnObj = UIFactory.CreateButton(nameRowObj); var applyNameBtn = applyNameBtnObj.GetComponent