From d1f4f74d3219143bd3b4b1b027601f71c71cd8b3 Mon Sep 17 00:00:00 2001 From: Sinai Date: Fri, 22 Jan 2021 21:56:00 +1100 Subject: [PATCH] some ui cleanups (minor) --- .../InteractiveValue/InteractiveValue.cs | 4 - src/UI/Modules/SearchPage.cs | 8 +- src/UI/Shared/InputFieldScroller.cs | 13 + src/UI/Shared/SliderScrollbar.cs | 263 +++++++++--------- src/UI/UIManager.cs | 2 +- 5 files changed, 152 insertions(+), 138 deletions(-) diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs index b231822..db46a8e 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs @@ -229,13 +229,9 @@ namespace UnityExplorer.Inspectors.Reflection string toString; if (m_toStringFormatMethod != null) - { toString = (string)m_toStringFormatMethod.Invoke(Value, new object[] { "F3" }); - } else - { toString = (string)m_toStringMethod.Invoke(Value, new object[0]); - } var fullnametemp = valueType.ToString(); if (fullnametemp.StartsWith("Il2CppSystem")) diff --git a/src/UI/Modules/SearchPage.cs b/src/UI/Modules/SearchPage.cs index 396feca..f071ab8 100644 --- a/src/UI/Modules/SearchPage.cs +++ b/src/UI/Modules/SearchPage.cs @@ -153,7 +153,7 @@ namespace UnityExplorer.UI.Modules { var name = UISyntaxHighlight.ParseFullSyntax(obj.GetActualType(), true); - if (unityObj && m_context != SearchContext.Singleton && m_context != SearchContext.StaticClass) + if (unityObj && m_context != SearchContext.Singleton) { if (unityObj && !string.IsNullOrEmpty(unityObj.name)) name += $": {unityObj.name}"; @@ -301,8 +301,8 @@ namespace UnityExplorer.UI.Modules foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { - // All non-static classes - foreach (var type in asm.TryGetTypes().Where(it => !it.IsSealed && !it.IsAbstract)) + // Search all non-static, non-enum classes. + foreach (var type in asm.TryGetTypes().Where(it => !(it.IsSealed && it.IsAbstract) && !it.IsEnum)) { try { @@ -336,7 +336,7 @@ namespace UnityExplorer.UI.Modules if (instance != null) { instances.Add(instance); - continue; + break; } } } diff --git a/src/UI/Shared/InputFieldScroller.cs b/src/UI/Shared/InputFieldScroller.cs index 5c1524a..a50add6 100644 --- a/src/UI/Shared/InputFieldScroller.cs +++ b/src/UI/Shared/InputFieldScroller.cs @@ -33,6 +33,8 @@ namespace UnityExplorer.UI.Shared this.sliderScroller = sliderScroller; this.inputField = inputField; + sliderScroller.m_parentInputScroller = this; + inputField.onValueChanged.AddListener(OnTextChanged); inputRect = inputField.GetComponent(); @@ -68,6 +70,17 @@ namespace UnityExplorer.UI.Shared } } + internal bool CheckDestroyed() + { + if (sliderScroller == null || sliderScroller.CheckDestroyed()) + { + Instances.Remove(this); + return true; + } + + return false; + } + internal void OnTextChanged(string text) { m_lastText = text; diff --git a/src/UI/Shared/SliderScrollbar.cs b/src/UI/Shared/SliderScrollbar.cs index 0f4c4e8..833d9db 100644 --- a/src/UI/Shared/SliderScrollbar.cs +++ b/src/UI/Shared/SliderScrollbar.cs @@ -8,150 +8,154 @@ using UnityExplorer; using UnityExplorer.Helpers; using UnityExplorer.UI; -// Basically just to fix an issue with Scrollbars, instead we use a Slider as the scrollbar. -public class SliderScrollbar +namespace UnityExplorer.UI.Shared { - internal static readonly List Instances = new List(); - - public bool IsActive { get; private set; } - - internal readonly Scrollbar m_scrollbar; - internal readonly Slider m_slider; - internal readonly RectTransform m_scrollRect; - - public SliderScrollbar(Scrollbar scrollbar, Slider slider) + // Basically just to fix an issue with Scrollbars, instead we use a Slider as the scrollbar. + public class SliderScrollbar { - Instances.Add(this); + internal static readonly List Instances = new List(); - this.m_scrollbar = scrollbar; - this.m_slider = slider; - this.m_scrollRect = scrollbar.transform.parent.GetComponent(); + public bool IsActive { get; private set; } - this.m_scrollbar.onValueChanged.AddListener(this.OnScrollbarValueChanged); - this.m_slider.onValueChanged.AddListener(this.OnSliderValueChanged); + internal readonly Scrollbar m_scrollbar; + internal readonly Slider m_slider; + internal readonly RectTransform m_scrollRect; - this.RefreshVisibility(); - this.m_slider.Set(1f, false); - } + internal InputFieldScroller m_parentInputScroller; - internal bool CheckDestroyed() - { - if (!m_slider || !m_scrollbar) + public SliderScrollbar(Scrollbar scrollbar, Slider slider) { - Instances.Remove(this); - return true; + Instances.Add(this); + + this.m_scrollbar = scrollbar; + this.m_slider = slider; + this.m_scrollRect = scrollbar.transform.parent.GetComponent(); + + this.m_scrollbar.onValueChanged.AddListener(this.OnScrollbarValueChanged); + this.m_slider.onValueChanged.AddListener(this.OnSliderValueChanged); + + this.RefreshVisibility(); + this.m_slider.Set(1f, false); } - return false; - } - - internal void Update() - { - this.RefreshVisibility(); - } - - internal void RefreshVisibility() - { - if (!m_slider.gameObject.activeInHierarchy) + internal bool CheckDestroyed() { - IsActive = false; - return; + if (!m_slider || !m_scrollbar) + { + Instances.Remove(this); + return true; + } + + return false; } - bool shouldShow = !Mathf.Approximately(this.m_scrollbar.size, 1); - var obj = this.m_slider.handleRect.gameObject; - - if (IsActive != shouldShow) + internal void Update() { - IsActive = shouldShow; - obj.SetActive(IsActive); - - if (IsActive) - this.m_slider.Set(this.m_scrollbar.value, false); - else - m_slider.Set(1f, false); + this.RefreshVisibility(); } + + internal void RefreshVisibility() + { + if (!m_slider.gameObject.activeInHierarchy) + { + IsActive = false; + return; + } + + bool shouldShow = !Mathf.Approximately(this.m_scrollbar.size, 1); + var obj = this.m_slider.handleRect.gameObject; + + if (IsActive != shouldShow) + { + IsActive = shouldShow; + obj.SetActive(IsActive); + + if (IsActive) + this.m_slider.Set(this.m_scrollbar.value, false); + else + m_slider.Set(1f, false); + } + } + + public void OnScrollbarValueChanged(float _value) + { + if (this.m_slider.value != _value) + this.m_slider.Set(_value, false); + } + + public void OnSliderValueChanged(float _value) + { + this.m_scrollbar.value = _value; + } + + #region UI CONSTRUCTION + + public static GameObject CreateSliderScrollbar(GameObject parent, out Slider slider) + { + GameObject sliderObj = UIFactory.CreateUIObject("Slider", parent, UIFactory.thinSize); + + GameObject bgObj = UIFactory.CreateUIObject("Background", sliderObj); + GameObject fillAreaObj = UIFactory.CreateUIObject("Fill Area", sliderObj); + GameObject fillObj = UIFactory.CreateUIObject("Fill", fillAreaObj); + GameObject handleSlideAreaObj = UIFactory.CreateUIObject("Handle Slide Area", sliderObj); + GameObject handleObj = UIFactory.CreateUIObject("Handle", handleSlideAreaObj); + + Image bgImage = bgObj.AddComponent(); + bgImage.type = Image.Type.Sliced; + bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f); + + RectTransform bgRect = bgObj.GetComponent(); + bgRect.anchorMin = Vector2.zero; + bgRect.anchorMax = Vector2.one; + bgRect.sizeDelta = Vector2.zero; + bgRect.offsetMax = new Vector2(-10f, 0f); + + RectTransform fillAreaRect = fillAreaObj.GetComponent(); + fillAreaRect.anchorMin = new Vector2(0f, 0.25f); + fillAreaRect.anchorMax = new Vector2(1f, 0.75f); + fillAreaRect.anchoredPosition = new Vector2(-5f, 0f); + fillAreaRect.sizeDelta = new Vector2(-20f, 0f); + + Image fillImage = fillObj.AddComponent(); + fillImage.type = Image.Type.Sliced; + fillImage.color = Color.clear; + + fillObj.GetComponent().sizeDelta = new Vector2(10f, 0f); + + RectTransform handleSlideRect = handleSlideAreaObj.GetComponent(); + handleSlideRect.anchorMin = new Vector2(0f, 0f); + handleSlideRect.anchorMax = new Vector2(1f, 1f); + handleSlideRect.offsetMin = new Vector2(15f, 30f); + handleSlideRect.offsetMax = new Vector2(-15f, 0f); + handleSlideRect.sizeDelta = new Vector2(-30f, -30f); + + Image handleImage = handleObj.AddComponent(); + handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f); + + var handleRect = handleObj.GetComponent(); + handleRect.sizeDelta = new Vector2(15f, 30f); + handleRect.offsetMin = new Vector2(-13f, -28f); + handleRect.offsetMax = new Vector2(3f, -2f); + + var sliderBarLayout = sliderObj.AddComponent(); + sliderBarLayout.minWidth = 25; + sliderBarLayout.flexibleWidth = 0; + sliderBarLayout.minHeight = 30; + sliderBarLayout.flexibleHeight = 5000; + + slider = sliderObj.AddComponent(); + slider.fillRect = fillObj.GetComponent(); + slider.handleRect = handleObj.GetComponent(); + slider.targetGraphic = handleImage; + slider.direction = Slider.Direction.BottomToTop; + UIFactory.SetDefaultColorTransitionValues(slider); + + return sliderObj; + } + + #endregion } - public void OnScrollbarValueChanged(float _value) - { - if (this.m_slider.value != _value) - this.m_slider.Set(_value, false); - } - - public void OnSliderValueChanged(float _value) - { - this.m_scrollbar.value = _value; - } - - #region UI CONSTRUCTION - - public static GameObject CreateSliderScrollbar(GameObject parent, out Slider slider) - { - GameObject sliderObj = UIFactory.CreateUIObject("Slider", parent, UIFactory.thinSize); - - GameObject bgObj = UIFactory.CreateUIObject("Background", sliderObj); - GameObject fillAreaObj = UIFactory.CreateUIObject("Fill Area", sliderObj); - GameObject fillObj = UIFactory.CreateUIObject("Fill", fillAreaObj); - GameObject handleSlideAreaObj = UIFactory.CreateUIObject("Handle Slide Area", sliderObj); - GameObject handleObj = UIFactory.CreateUIObject("Handle", handleSlideAreaObj); - - Image bgImage = bgObj.AddComponent(); - bgImage.type = Image.Type.Sliced; - bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f); - - RectTransform bgRect = bgObj.GetComponent(); - bgRect.anchorMin = Vector2.zero; - bgRect.anchorMax = Vector2.one; - bgRect.sizeDelta = Vector2.zero; - bgRect.offsetMax = new Vector2(-10f, 0f); - - RectTransform fillAreaRect = fillAreaObj.GetComponent(); - fillAreaRect.anchorMin = new Vector2(0f, 0.25f); - fillAreaRect.anchorMax = new Vector2(1f, 0.75f); - fillAreaRect.anchoredPosition = new Vector2(-5f, 0f); - fillAreaRect.sizeDelta = new Vector2(-20f, 0f); - - Image fillImage = fillObj.AddComponent(); - fillImage.type = Image.Type.Sliced; - fillImage.color = Color.clear; - - fillObj.GetComponent().sizeDelta = new Vector2(10f, 0f); - - RectTransform handleSlideRect = handleSlideAreaObj.GetComponent(); - handleSlideRect.anchorMin = new Vector2(0f, 0f); - handleSlideRect.anchorMax = new Vector2(1f, 1f); - handleSlideRect.offsetMin = new Vector2(15f, 30f); - handleSlideRect.offsetMax = new Vector2(-15f, 0f); - handleSlideRect.sizeDelta = new Vector2(-30f, -30f); - - Image handleImage = handleObj.AddComponent(); - handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f); - - var handleRect = handleObj.GetComponent(); - handleRect.sizeDelta = new Vector2(15f, 30f); - handleRect.offsetMin = new Vector2(-13f, -28f); - handleRect.offsetMax = new Vector2(3f, -2f); - - var sliderBarLayout = sliderObj.AddComponent(); - sliderBarLayout.minWidth = 25; - sliderBarLayout.flexibleWidth = 0; - sliderBarLayout.minHeight = 30; - sliderBarLayout.flexibleHeight = 5000; - - slider = sliderObj.AddComponent(); - slider.fillRect = fillObj.GetComponent(); - slider.handleRect = handleObj.GetComponent(); - slider.targetGraphic = handleImage; - slider.direction = Slider.Direction.BottomToTop; - UIFactory.SetDefaultColorTransitionValues(slider); - - return sliderObj; - } - - #endregion -} - #if MONO public static class SliderExtensions { @@ -175,4 +179,5 @@ public static class SliderExtensions SetMethod.Invoke(slider, new object[] { value, invokeCallback }); } } -#endif \ No newline at end of file +#endif +} \ No newline at end of file diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 7d0146a..b1432e1 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -81,7 +81,7 @@ namespace UnityExplorer.UI { var input = InputFieldScroller.Instances[i]; - if (input.sliderScroller.CheckDestroyed()) + if (input.CheckDestroyed()) i--; else input.Update();