From a5a07a0a23bf0af8944f9d28bc093d59bb67a845 Mon Sep 17 00:00:00 2001 From: Sinai Date: Sat, 10 Apr 2021 18:25:13 +1000 Subject: [PATCH] Add RuntimeProvider method for setting Selectable.colors --- src/Core/Runtime/Il2Cpp/Il2CppProvider.cs | 35 +++++++++++++++---- src/Core/Runtime/Mono/MonoProvider.cs | 11 ++++-- src/Core/Runtime/RuntimeProvider.cs | 4 ++- src/UI/CacheObject/CacheMember.cs | 19 +++++----- src/UI/Inspectors/GameObjects/ChildList.cs | 10 +++--- .../Inspectors/GameObjects/ComponentList.cs | 10 +++--- .../GameObjects/GameObjectControls.cs | 2 +- src/UI/Inspectors/InspectorManager.cs | 4 +-- .../Reflection/InstanceInspector.cs | 8 ++--- .../Reflection/ReflectionInspector.cs | 8 ++--- src/UI/Main/CSConsole/AutoCompleter.cs | 6 ++-- src/UI/Main/Home/SceneExplorer.cs | 20 +++++------ src/UI/Main/MainMenu.cs | 22 +++++------- src/UI/Main/Search/SearchPage.cs | 12 +++---- src/UI/UIFactory.cs | 31 ++++++---------- 15 files changed, 102 insertions(+), 100 deletions(-) diff --git a/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs b/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs index 7d20ed20..52f28680 100644 --- a/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs +++ b/src/Core/Runtime/Il2Cpp/Il2CppProvider.cs @@ -160,20 +160,22 @@ public static int GetRootCount(int handle) .Invoke(handle); } - internal static bool triedToGetProperties; + internal static bool triedToGetColorBlockProps; internal static PropertyInfo _normalColorProp; internal static PropertyInfo _highlightColorProp; internal static PropertyInfo _pressedColorProp; - public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null) + public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null) { + var colors = selectable.colors; + colors.colorMultiplier = 1; object boxed = (object)colors; - if (!triedToGetProperties) + if (!triedToGetColorBlockProps) { - triedToGetProperties = true; + triedToGetColorBlockProps = true; if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor") is PropertyInfo norm && norm.CanWrite) _normalColorProp = norm; @@ -209,11 +211,32 @@ public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null fi.SetValue(boxed, (Color)pressed); } } - catch { } + catch (Exception ex) + { + ExplorerCore.Log(ex); + } colors = (ColorBlock)boxed; - return colors; + SetColorBlock(selectable, colors); + } + + public override void SetColorBlock(Selectable selectable, ColorBlock _colorBlock) + { + try + { + selectable = selectable.TryCast(); + + ReflectionUtility.GetPropertyInfo(typeof(Selectable), "m_Colors") + .SetValue(selectable, _colorBlock, null); + + ReflectionUtility.GetMethodInfo(typeof(Selectable), "OnSetProperty", new Type[0]) + .Invoke(selectable, new object[0]); + } + catch (Exception ex) + { + ExplorerCore.Log(ex); + } } public override void FindSingleton(string[] possibleNames, Type type, BF flags, List instances) diff --git a/src/Core/Runtime/Mono/MonoProvider.cs b/src/Core/Runtime/Mono/MonoProvider.cs index e3c6a5f6..52a293b4 100644 --- a/src/Core/Runtime/Mono/MonoProvider.cs +++ b/src/Core/Runtime/Mono/MonoProvider.cs @@ -86,8 +86,10 @@ public override int GetRootCount(Scene scene) return scene.rootCount; } - public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null) + public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null) { + var colors = selectable.colors; + if (normal != null) colors.normalColor = (Color)normal; @@ -97,7 +99,12 @@ public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null if (pressed != null) colors.pressedColor = (Color)pressed; - return colors; + SetColorBlock(selectable, colors); + } + + public override void SetColorBlock(Selectable selectable, ColorBlock colors) + { + selectable.colors = colors; } } } diff --git a/src/Core/Runtime/RuntimeProvider.cs b/src/Core/Runtime/RuntimeProvider.cs index 7b6c8175..c97d3bc7 100644 --- a/src/Core/Runtime/RuntimeProvider.cs +++ b/src/Core/Runtime/RuntimeProvider.cs @@ -62,7 +62,9 @@ public static void Init() => public abstract int GetRootCount(Scene scene); - public abstract ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null); + public abstract void SetColorBlock(Selectable selectable, ColorBlock colors); + + public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null); public virtual void FindSingleton(string[] s_instanceNames, Type type, BindingFlags flags, List instances) { diff --git a/src/UI/CacheObject/CacheMember.cs b/src/UI/CacheObject/CacheMember.cs index a2eaa754..df5cbe8a 100644 --- a/src/UI/CacheObject/CacheMember.cs +++ b/src/UI/CacheObject/CacheMember.cs @@ -319,15 +319,13 @@ internal void ConstructEvaluateButtons(GameObject argsHolder) default, new Color(1, 1, 1, 0)); UIFactory.SetLayoutElement(evalGroupObj, minHeight: 25, flexibleHeight: 0, flexibleWidth: 5000); - var colors = new ColorBlock(); - colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f), - new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f)); - var evalButton = UIFactory.CreateButton(evalGroupObj, "EvalButton", $"Evaluate ({ParamCount})", - null, - colors); + null); + + RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f), + new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f)); UIFactory.SetLayoutElement(evalButton.gameObject, minWidth: 100, minHeight: 22, flexibleWidth: 0); @@ -345,7 +343,7 @@ internal void ConstructEvaluateButtons(GameObject argsHolder) argsHolder.SetActive(true); m_isEvaluating = true; evalText.text = "Evaluate"; - evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.3f, 0.6f, 0.3f)); + RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.3f, 0.6f, 0.3f)); cancelButton.gameObject.SetActive(true); } @@ -365,18 +363,17 @@ internal void ConstructEvaluateButtons(GameObject argsHolder) m_isEvaluating = false; evalText.text = $"Evaluate ({ParamCount})"; - evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.4f, 0.4f, 0.4f)); + RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f)); }); } else if (this is CacheMethod) { // simple method evaluate button - var colors = new ColorBlock(); - colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f), + var evalButton = UIFactory.CreateButton(m_rightGroup, "EvalButton", "Evaluate", () => { (this as CacheMethod).Evaluate(); }); + RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f), new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f)); - var evalButton = UIFactory.CreateButton(m_rightGroup, "EvalButton", "Evaluate", () => { (this as CacheMethod).Evaluate(); }, colors); UIFactory.SetLayoutElement(evalButton.gameObject, minWidth: 100, minHeight: 22, flexibleWidth: 0); } } diff --git a/src/UI/Inspectors/GameObjects/ChildList.cs b/src/UI/Inspectors/GameObjects/ChildList.cs index 6372674a..28b72763 100644 --- a/src/UI/Inspectors/GameObjects/ChildList.cs +++ b/src/UI/Inspectors/GameObjects/ChildList.cs @@ -168,15 +168,13 @@ internal void AddChildListButton() s_childListToggles.Add(toggle); toggle.onValueChanged.AddListener((bool val) => { OnToggleClicked(thisIndex, val); }); - ColorBlock mainColors = new ColorBlock(); - mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.07f, 0.07f, 0.07f), - new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f)); - var mainBtn = UIFactory.CreateButton(btnGroupObj, "MainButton", "", - () => { OnChildListObjectClicked(thisIndex); }, - mainColors); + () => { OnChildListObjectClicked(thisIndex); }); + + RuntimeProvider.Instance.SetColorBlock(mainBtn, new Color(0.07f, 0.07f, 0.07f), + new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f)); UIFactory.SetLayoutElement(mainBtn.gameObject, minHeight: 25, flexibleHeight: 0, minWidth: 25, flexibleWidth: 9999); diff --git a/src/UI/Inspectors/GameObjects/ComponentList.cs b/src/UI/Inspectors/GameObjects/ComponentList.cs index 8d29b210..869a66af 100644 --- a/src/UI/Inspectors/GameObjects/ComponentList.cs +++ b/src/UI/Inspectors/GameObjects/ComponentList.cs @@ -165,15 +165,13 @@ internal void AddCompListButton() // Main component button - ColorBlock mainColors = new ColorBlock(); - mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.07f, 0.07f, 0.07f), - new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f)); - var mainBtn = UIFactory.CreateButton(groupObj, "MainButton", "", - () => { OnCompListObjectClicked(thisIndex); }, - mainColors); + () => { OnCompListObjectClicked(thisIndex); }); + + RuntimeProvider.Instance.SetColorBlock(mainBtn, new Color(0.07f, 0.07f, 0.07f), + new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f)); UIFactory.SetLayoutElement(mainBtn.gameObject, minHeight: 25, flexibleHeight: 0, minWidth: 25, flexibleWidth: 999); diff --git a/src/UI/Inspectors/GameObjects/GameObjectControls.cs b/src/UI/Inspectors/GameObjects/GameObjectControls.cs index 6dcc577a..bd9bc668 100644 --- a/src/UI/Inspectors/GameObjects/GameObjectControls.cs +++ b/src/UI/Inspectors/GameObjects/GameObjectControls.cs @@ -408,7 +408,7 @@ internal GameObject ConstructEditorRow(GameObject parent, ControlEditor editor, var sliderObj = UIFactory.CreateSlider(rowObject, "VectorSlider", out Slider slider); UIFactory.SetLayoutElement(sliderObj, minHeight: 20, flexibleHeight: 0, minWidth: 200, flexibleWidth: 9000); sliderObj.transform.Find("Fill Area").gameObject.SetActive(false); - slider.colors = RuntimeProvider.Instance.SetColorBlock(slider.colors, new Color(0.65f, 0.65f, 0.65f)); + RuntimeProvider.Instance.SetColorBlock(slider, new Color(0.65f, 0.65f, 0.65f)); slider.minValue = -2; slider.maxValue = 2; slider.value = 0; diff --git a/src/UI/Inspectors/InspectorManager.cs b/src/UI/Inspectors/InspectorManager.cs index c371411b..739a193f 100644 --- a/src/UI/Inspectors/InspectorManager.cs +++ b/src/UI/Inspectors/InspectorManager.cs @@ -130,12 +130,12 @@ public void UnsetInspectorTab() public void OnSetInspectorTab(InspectorBase inspector) { Color activeColor = new Color(0, 0.25f, 0, 1); - inspector.m_tabButton.colors = RuntimeProvider.Instance.SetColorBlock(inspector.m_tabButton.colors, activeColor, activeColor); + RuntimeProvider.Instance.SetColorBlock(inspector.m_tabButton, activeColor, activeColor); } public void OnUnsetInspectorTab() { - m_activeInspector.m_tabButton.colors = RuntimeProvider.Instance.SetColorBlock(m_activeInspector.m_tabButton.colors, + RuntimeProvider.Instance.SetColorBlock(m_activeInspector.m_tabButton, new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.1f, 0.3f, 0.1f, 1)); } diff --git a/src/UI/Inspectors/Reflection/InstanceInspector.cs b/src/UI/Inspectors/Reflection/InstanceInspector.cs index d2de92e8..8806b4ae 100644 --- a/src/UI/Inspectors/Reflection/InstanceInspector.cs +++ b/src/UI/Inspectors/Reflection/InstanceInspector.cs @@ -30,12 +30,12 @@ public InstanceInspector(object target) : base(target) { } internal void OnScopeFilterClicked(MemberScopes type, Button button) { if (m_lastActiveScopeButton) - m_lastActiveScopeButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton.colors, new Color(0.2f, 0.2f, 0.2f)); + RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton, new Color(0.2f, 0.2f, 0.2f)); m_scopeFilter = type; m_lastActiveScopeButton = button; - m_lastActiveScopeButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton.colors, new Color(0.2f, 0.6f, 0.2f)); + RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton, new Color(0.2f, 0.6f, 0.2f)); FilterMembers(null, true); m_sliderScroller.m_slider.value = 1f; @@ -240,11 +240,11 @@ private void AddFilterButton(GameObject parent, MemberScopes type, bool setEnabl btn.onClick.AddListener(() => { OnScopeFilterClicked(type, btn); }); - btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, highlighted: new Color(0.3f, 0.7f, 0.3f)); + RuntimeProvider.Instance.SetColorBlock(btn, highlighted: new Color(0.3f, 0.7f, 0.3f)); if (setEnabled) { - btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, new Color(0.2f, 0.6f, 0.2f)); + RuntimeProvider.Instance.SetColorBlock(btn, new Color(0.2f, 0.6f, 0.2f)); m_scopeFilter = type; m_lastActiveScopeButton = btn; } diff --git a/src/UI/Inspectors/Reflection/ReflectionInspector.cs b/src/UI/Inspectors/Reflection/ReflectionInspector.cs index a48e58b9..07874772 100644 --- a/src/UI/Inspectors/Reflection/ReflectionInspector.cs +++ b/src/UI/Inspectors/Reflection/ReflectionInspector.cs @@ -241,12 +241,12 @@ public override void Update() internal void OnMemberFilterClicked(MemberTypes type, Button button) { if (m_lastActiveMemButton) - m_lastActiveMemButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton.colors, new Color(0.2f, 0.2f, 0.2f)); + RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton, new Color(0.2f, 0.2f, 0.2f)); m_memberFilter = type; m_lastActiveMemButton = button; - m_lastActiveMemButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton.colors, new Color(0.2f, 0.6f, 0.2f)); + RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton, new Color(0.2f, 0.6f, 0.2f)); FilterMembers(null, true); m_sliderScroller.m_slider.value = 1f; @@ -461,11 +461,11 @@ private void AddFilterButton(GameObject parent, MemberTypes type, bool setEnable UIFactory.SetLayoutElement(btn.gameObject, minHeight: 25, minWidth: 70); btn.onClick.AddListener(() => { OnMemberFilterClicked(type, btn); }); - btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, highlighted: new Color(0.3f, 0.7f, 0.3f)); + RuntimeProvider.Instance.SetColorBlock(btn, highlighted: new Color(0.3f, 0.7f, 0.3f)); if (setEnabled) { - btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, new Color(0.2f, 0.6f, 0.2f)); + RuntimeProvider.Instance.SetColorBlock(btn, new Color(0.2f, 0.6f, 0.2f)); m_memberFilter = type; m_lastActiveMemButton = btn; } diff --git a/src/UI/Main/CSConsole/AutoCompleter.cs b/src/UI/Main/CSConsole/AutoCompleter.cs index 168ca578..281ff124 100644 --- a/src/UI/Main/CSConsole/AutoCompleter.cs +++ b/src/UI/Main/CSConsole/AutoCompleter.cs @@ -271,12 +271,10 @@ private static void ConstructUI() mainGroup.childForceExpandHeight = false; mainGroup.childForceExpandWidth = true; - ColorBlock btnColors = new ColorBlock(); - RuntimeProvider.Instance.SetColorBlock(btnColors, new Color(0, 0, 0, 0), highlighted: new Color(0.2f, 0.2f, 0.2f, 1.0f)); - for (int i = 0; i < MAX_LABELS; i++) { - var btn = UIFactory.CreateButton(content, "AutoCompleteButton", "", null, btnColors); + var btn = UIFactory.CreateButton(content, "AutoCompleteButton", "", null); + RuntimeProvider.Instance.SetColorBlock(btn, new Color(0, 0, 0, 0), highlighted: new Color(0.2f, 0.2f, 0.2f, 1.0f)); var nav = btn.navigation; nav.mode = Navigation.Mode.Vertical; diff --git a/src/UI/Main/Home/SceneExplorer.cs b/src/UI/Main/Home/SceneExplorer.cs index 3e97d208..ee6a5f6c 100644 --- a/src/UI/Main/Home/SceneExplorer.cs +++ b/src/UI/Main/Home/SceneExplorer.cs @@ -522,15 +522,13 @@ private void AddObjectListButton() m_shortListToggles.Add(toggle); toggle.onValueChanged.AddListener((bool val) => { OnToggleClicked(thisIndex, val); }); - ColorBlock mainColors = new ColorBlock(); - mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.1f, 0.1f, 0.1f), - new Color(0.2f, 0.2f, 0.2f), new Color(0.05f, 0.05f, 0.05f)); - var mainButton = UIFactory.CreateButton(btnGroupObj, "MainButton", "", - () => { SceneListObjectClicked(thisIndex); }, - mainColors); + () => { SceneListObjectClicked(thisIndex); }); + + RuntimeProvider.Instance.SetColorBlock(mainButton, new Color(0.1f, 0.1f, 0.1f), + new Color(0.2f, 0.2f, 0.2f), new Color(0.05f, 0.05f, 0.05f)); UIFactory.SetLayoutElement(mainButton.gameObject, minHeight: 25, minWidth: 230); @@ -539,15 +537,13 @@ private void AddObjectListButton() mainText.horizontalOverflow = HorizontalWrapMode.Overflow; m_shortListTexts.Add(mainText); - ColorBlock inspectColors = new ColorBlock(); - inspectColors = RuntimeProvider.Instance.SetColorBlock(inspectColors, new Color(0.15f, 0.15f, 0.15f), - new Color(0.2f, 0.2f, 0.2f), new Color(0.1f, 0.1f, 0.1f)); - var inspectButton = UIFactory.CreateButton(btnGroupObj, "InspectButton", "Inspect", - () => { InspectorManager.Instance.Inspect(m_shortList[thisIndex]); }, - inspectColors); + () => { InspectorManager.Instance.Inspect(m_shortList[thisIndex]); }); + + RuntimeProvider.Instance.SetColorBlock(inspectButton, new Color(0.15f, 0.15f, 0.15f), + new Color(0.2f, 0.2f, 0.2f), new Color(0.1f, 0.1f, 0.1f)); UIFactory.SetLayoutElement(inspectButton.gameObject, minWidth: 60, minHeight: 25); } diff --git a/src/UI/Main/MainMenu.cs b/src/UI/Main/MainMenu.cs index 2c5ba360..cac610bb 100644 --- a/src/UI/Main/MainMenu.cs +++ b/src/UI/Main/MainMenu.cs @@ -141,12 +141,12 @@ public void SetPage(BaseMenuPage page) internal void SetButtonActiveColors(Button button) { - button.colors = RuntimeProvider.Instance.SetColorBlock(button.colors, m_navButtonSelected); + RuntimeProvider.Instance.SetColorBlock(button, m_navButtonSelected); } internal void SetButtonInactiveColors(Button button) { - button.colors = RuntimeProvider.Instance.SetColorBlock(button.colors, m_navButtonNormal); + RuntimeProvider.Instance.SetColorBlock(button, m_navButtonNormal); } #region UI Construction @@ -184,15 +184,13 @@ private void ConstructTitleBar(GameObject content) // Hide button - ColorBlock colorBlock = new ColorBlock(); - colorBlock = RuntimeProvider.Instance.SetColorBlock(colorBlock, new Color(65f / 255f, 23f / 255f, 23f / 255f), - new Color(35f / 255f, 10f / 255f, 10f / 255f), new Color(156f / 255f, 0f, 0f)); - var hideButton = UIFactory.CreateButton(titleBar, "HideButton", $"Hide ({ConfigManager.Main_Menu_Toggle.Value})", - () => { UIManager.ShowMenu = false; }, - colorBlock); + () => { UIManager.ShowMenu = false; }); + + RuntimeProvider.Instance.SetColorBlock(hideButton, new Color(65f / 255f, 23f / 255f, 23f / 255f), + new Color(35f / 255f, 10f / 255f, 10f / 255f), new Color(156f / 255f, 0f, 0f)); UIFactory.SetLayoutElement(hideButton.gameObject, minWidth: 90, flexibleWidth: 0); @@ -213,16 +211,14 @@ private void ConstructNavbar(GameObject content) GameObject navbarObj = UIFactory.CreateHorizontalGroup(content, "MainNavBar", true, true, true, true, 5); UIFactory.SetLayoutElement(navbarObj, minHeight: 25, flexibleHeight: 0); - ColorBlock colorBlock = new ColorBlock(); - colorBlock = RuntimeProvider.Instance.SetColorBlock(colorBlock, m_navButtonNormal, m_navButtonHighlight, m_navButtonSelected); - foreach (var page in Pages) { Button btn = UIFactory.CreateButton(navbarObj, $"Button_{page.Name}", page.Name, - () => { SetPage(page); }, - colorBlock); + () => { SetPage(page); }); + + RuntimeProvider.Instance.SetColorBlock(btn, m_navButtonNormal, m_navButtonHighlight, m_navButtonSelected); page.RefNavbarButton = btn; } diff --git a/src/UI/Main/Search/SearchPage.cs b/src/UI/Main/Search/SearchPage.cs index 32e9c006..25f43d64 100644 --- a/src/UI/Main/Search/SearchPage.cs +++ b/src/UI/Main/Search/SearchPage.cs @@ -261,7 +261,7 @@ internal void OnContextButtonClicked(SearchContext context) m_selectedContextButton = button; - m_selectedContextButton.colors = RuntimeProvider.Instance.SetColorBlock(m_selectedContextButton.colors, + RuntimeProvider.Instance.SetColorBlock(m_selectedContextButton, new Color(0.35f, 0.7f, 0.35f), new Color(0.35f, 0.7f, 0.35f)); m_context = context; @@ -439,15 +439,13 @@ internal void AddResultButton() UIFactory.SetLayoutElement(btnGroupObj, flexibleWidth: 320, minHeight: 25, flexibleHeight: 0); btnGroupObj.AddComponent(); - var mainColors = new ColorBlock(); - RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.1f, 0.1f, 0.1f), - new Color(0.2f, 0.2f, 0.2f), new Color(0.05f, 0.05f, 0.05f)); - var mainButton = UIFactory.CreateButton(btnGroupObj, "ResultButton", "", - () => { OnResultClicked(thisIndex); }, - mainColors); + () => { OnResultClicked(thisIndex); }); + + RuntimeProvider.Instance.SetColorBlock(mainButton, new Color(0.1f, 0.1f, 0.1f), + new Color(0.2f, 0.2f, 0.2f), new Color(0.05f, 0.05f, 0.05f)); UIFactory.SetLayoutElement(mainButton.gameObject, minHeight: 25, flexibleHeight: 0, minWidth: 320, flexibleWidth: 0); diff --git a/src/UI/UIFactory.cs b/src/UI/UIFactory.cs index 212c0d64..18da679d 100644 --- a/src/UI/UIFactory.cs +++ b/src/UI/UIFactory.cs @@ -52,7 +52,7 @@ internal static void SetDefaultTextValues(Text text) internal static void SetDefaultSelectableColors(Selectable selectable) { - selectable.colors = RuntimeProvider.Instance.SetColorBlock(selectable.colors, new Color(0.2f, 0.2f, 0.2f), + RuntimeProvider.Instance.SetColorBlock(selectable, new Color(0.2f, 0.2f, 0.2f), new Color(0.3f, 0.3f, 0.3f), new Color(0.15f, 0.15f, 0.15f)); // Deselect all Buttons after they are clicked. @@ -60,19 +60,6 @@ internal static void SetDefaultSelectableColors(Selectable selectable) button.onClick.AddListener(() => { button.OnDeselect(null); }); } - //public static void SetColorBlockValues(ref this ColorBlock colorBlock, Color? normal = null, Color? highlighted = null, - // Color? pressed = null) - //{ - // if (normal != null) - // colorBlock.normalColor = (Color)normal; - - // if (highlighted != null) - // colorBlock.highlightedColor = (Color)highlighted; - - // if (pressed != null) - // colorBlock.pressedColor = (Color)pressed; - //} - /// /// Get and/or Add a LayoutElement component to the GameObject, and set any of the values on it. /// @@ -276,10 +263,12 @@ public static Button CreateButton(GameObject parent, string name, string text, A { var colors = new ColorBlock(); normalColor = normalColor ?? new Color(0.25f, 0.25f, 0.25f); - colors = RuntimeProvider.Instance.SetColorBlock(colors, normalColor, new Color(0.4f, 0.4f, 0.4f), - new Color(0.15f, 0.15f, 0.15f)); - return CreateButton(parent, name, text, onClick, colors); + var btn = CreateButton(parent, name, text, onClick, colors); + + RuntimeProvider.Instance.SetColorBlock(btn, normalColor, new Color(0.4f, 0.4f, 0.4f), new Color(0.15f, 0.15f, 0.15f)); + + return btn; } public static Button CreateButton(GameObject parent, string name, string text, Action onClick, ColorBlock colors) @@ -296,7 +285,7 @@ public static Button CreateButton(GameObject parent, string name, string text, A SetDefaultSelectableColors(button); colors.colorMultiplier = 1; - button.colors = colors; + RuntimeProvider.Instance.SetColorBlock(button, colors); Text textComp = textObj.AddComponent(); textComp.text = text; @@ -364,7 +353,7 @@ public static GameObject CreateSlider(GameObject parent, string name, out Slider slider.targetGraphic = handleImage; slider.direction = Slider.Direction.LeftToRight; - slider.colors = RuntimeProvider.Instance.SetColorBlock(slider.colors, new Color(0.4f, 0.4f, 0.4f), + RuntimeProvider.Instance.SetColorBlock(slider, new Color(0.4f, 0.4f, 0.4f), new Color(0.55f, 0.55f, 0.55f), new Color(0.3f, 0.3f, 0.3f)); return sliderObj; @@ -504,7 +493,7 @@ public static GameObject CreateInputField(GameObject parent, string name, string mainInput.transition = Selectable.Transition.ColorTint; mainInput.targetGraphic = mainImage; - mainInput.colors = RuntimeProvider.Instance.SetColorBlock(mainInput.colors, new Color(1, 1, 1, 1), + RuntimeProvider.Instance.SetColorBlock(mainInput, new Color(1, 1, 1, 1), new Color(0.95f, 0.95f, 0.95f, 1.0f), new Color(0.78f, 0.78f, 0.78f, 1.0f)); SetLayoutGroup(mainObj, true, true, true, true); @@ -609,7 +598,7 @@ public static GameObject CreateDropdown(GameObject parent, out Dropdown dropdown Toggle itemToggle = itemObj.AddComponent(); itemToggle.targetGraphic = itemBgImage; itemToggle.isOn = true; - itemToggle.colors = RuntimeProvider.Instance.SetColorBlock(itemToggle.colors, + RuntimeProvider.Instance.SetColorBlock(itemToggle, new Color(0.35f, 0.35f, 0.35f, 1.0f), new Color(0.25f, 0.45f, 0.25f, 1.0f)); itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });