From 7f9e009e00fd8adc1ef6fa3dfd14aba23363d8f7 Mon Sep 17 00:00:00 2001 From: asdfCYBER Date: Sat, 18 Feb 2023 20:41:29 +0100 Subject: [PATCH] Fix UI layout --- Heatmap.Unity/Properties/AssemblyInfo.cs | 4 +-- Heatmap/Logging/Logging.cs | 35 ++++++++++++++++++++++++ Heatmap/Properties/AssemblyInfo.cs | 4 +-- Heatmap/UI/SettingsPanel.cs | 2 +- Heatmap/UI/ToolbarButton.cs | 8 +----- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Heatmap.Unity/Properties/AssemblyInfo.cs b/Heatmap.Unity/Properties/AssemblyInfo.cs index 3d8d493..15f896c 100644 --- a/Heatmap.Unity/Properties/AssemblyInfo.cs +++ b/Heatmap.Unity/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("1.5.2.0")] +[assembly: AssemblyFileVersion("1.5.2.0")] diff --git a/Heatmap/Logging/Logging.cs b/Heatmap/Logging/Logging.cs index d003777..c552d17 100644 --- a/Heatmap/Logging/Logging.cs +++ b/Heatmap/Logging/Logging.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text; using UnityEngine; namespace Heatmap.Logging @@ -42,5 +43,39 @@ public static void Log(string message, LogLevel level) if (level <= Level) Debug.Log(_tag + _prefix[level] + message); } + + /// + /// Log a hierarchy of gameobjects with their components + /// + public static void DumpGameObjectRecursive(GameObject obj, int maxDepth = 2) + { + StringBuilder output = new StringBuilder(); + DumpGameObjectRecursive(obj, ref output, maxDepth: maxDepth); + + if (output.Length > 10000) + output.AppendLine("Safety limit of 10000 characters exceeded"); + + Debug.Log(output); + } + + private static void DumpGameObjectRecursive(GameObject obj, ref StringBuilder output, int maxDepth, int depth = 0) + { + output.AppendLine(); + if (output.Length > 10000) return; // Safety limit + + // Print gameobject name + string objectPadding = new string(' ', depth * 4); + output.AppendLine($"{objectPadding}gameobject with name {obj.name}"); + + // Print the type of every component in the gameobject, indented one level relative to obj + string componentPadding = new string(' ', depth * 4 + 4); + foreach (Component component in obj.GetComponents()) + output.AppendLine($"{componentPadding}component of type {component.GetType().FullName}"); + + // Call this function for every child object until maxdepth is reached + if (depth >= maxDepth) return; + for (int i = 0; i < obj.transform.childCount; i++) + DumpGameObjectRecursive(obj.transform.GetChild(i).gameObject, ref output, maxDepth, depth + 1); + } } } diff --git a/Heatmap/Properties/AssemblyInfo.cs b/Heatmap/Properties/AssemblyInfo.cs index 9d32230..67121df 100644 --- a/Heatmap/Properties/AssemblyInfo.cs +++ b/Heatmap/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("1.5.2.0")] +[assembly: AssemblyFileVersion("1.5.2.0")] diff --git a/Heatmap/UI/SettingsPanel.cs b/Heatmap/UI/SettingsPanel.cs index d3bf62f..bfdaa1a 100644 --- a/Heatmap/UI/SettingsPanel.cs +++ b/Heatmap/UI/SettingsPanel.cs @@ -30,7 +30,7 @@ public SettingsPanel(GameObject parent) PanelManager = _panel.GetComponent(); // Move the panel so it is next to the toolbar - _panel.GetComponent().anchoredPosition = new Vector2(200, -180); + _panel.GetComponent().anchoredPosition = new Vector2(165, -5); // Hook up events PanelManager.Close.onClick.AddListener(Destroy); diff --git a/Heatmap/UI/ToolbarButton.cs b/Heatmap/UI/ToolbarButton.cs index 3525290..72ee8ba 100644 --- a/Heatmap/UI/ToolbarButton.cs +++ b/Heatmap/UI/ToolbarButton.cs @@ -38,7 +38,7 @@ public ToolbarButton() // Copy the button and add it to the layoutgroup _buttonHolder = Object.Instantiate(sourceButton); Object.DontDestroyOnLoad(_buttonHolder); - _buttonHolder.transform.SetParent(buttonGroup.transform, worldPositionStays: false); + _buttonHolder.transform.SetParent(buttonGroup.transform.parent, worldPositionStays: false); _buttonHolder.gameObject.SetActive(value: true); _button = _buttonHolder.GetComponentInChildren(); @@ -47,12 +47,6 @@ public ToolbarButton() // Make the button a toggle _button.onClick = new Button.ButtonClickedEvent(); _button.onClick.AddListener(ButtonPressed); - - // Not entirely sure what this exactly does, but it increases the - // layoutgroup size so that buttons are no longer squished - RectTransform rect = buttonGroup.gameObject.GetComponent(); - rect.sizeDelta = new Vector2(rect.sizeDelta.x, rect.sizeDelta.y * 1.5f); - rect.anchoredPosition = new Vector2(rect.anchoredPosition.x, rect.anchoredPosition.y * 1.5f); } internal async void ButtonPressed()