From 426a0c474fce9a7b943a20a7362e385ff050d719 Mon Sep 17 00:00:00 2001 From: MarkBubacz Date: Tue, 27 Feb 2018 22:13:20 +0100 Subject: [PATCH 1/2] Renamed header of SwitchGUIDepth-Example --- Example/Editor/DemoScenarios.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Editor/DemoScenarios.cs b/Example/Editor/DemoScenarios.cs index 723f94c..b26a279 100644 --- a/Example/Editor/DemoScenarios.cs +++ b/Example/Editor/DemoScenarios.cs @@ -208,7 +208,7 @@ public static class DemoScenarios Name = "SwitchGUIDepth", Scenarios = new List { - new DemoScenarioContent("SwitchGUIDepth", "Similar to EditorFrame, but can be collapsed by clicking on the header", + new DemoScenarioContent("SwitchGUIDepth", "Draw Controls overlaying each other", delegate { Rect rect = EditorGUILayout.GetControlRect(false, 50); From 4510144dd6edd02ba3f01c39c6e769291a67ad2f Mon Sep 17 00:00:00 2001 From: MarkBubacz Date: Thu, 1 Mar 2018 11:16:08 +0100 Subject: [PATCH 2/2] Added GridBlock --- Editor/EditorHelper.cs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Editor/EditorHelper.cs b/Editor/EditorHelper.cs index d8e3b62..6484ad4 100644 --- a/Editor/EditorHelper.cs +++ b/Editor/EditorHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; @@ -228,8 +229,6 @@ public static void DrawOutline(Rect rect, Color color, float borderWidth = 1f, O #endregion GUI Utilities } - #region Blocks - public sealed class RoundedBox : IDisposable { public RoundedBox() @@ -527,5 +526,38 @@ public void Dispose() } } - #endregion Blocks + public static class GridBlock + { + public static void Draw(ref Vector2 scrollPos, bool alwaysShowHorizontalScrollbar, bool alwaysShowVerticalScrollbar, List elements, int itemCountX, float padding, Func drawer) + { + scrollPos = GUILayout.BeginScrollView(scrollPos, alwaysShowHorizontalScrollbar, alwaysShowVerticalScrollbar); + if (elements.Any()) + { + EditorGUILayout.BeginHorizontal(); + int index = 0; + + using (new EditorBlock(EditorBlock.Orientation.Vertical)) + { + for (int i = 0; i < Mathf.CeilToInt((float)elements.Count / itemCountX); i++) + { + using (new EditorBlock(EditorBlock.Orientation.Horizontal)) + { + for (int j = 0; j < itemCountX; j++) + { + if (index < elements.Count) + { + drawer(elements[index]); + GUILayout.Space(padding); + } + index++; + } + } + GUILayout.Space(padding); + } + } + EditorGUILayout.EndHorizontal(); + } + GUILayout.EndScrollView(); + } + } } \ No newline at end of file