Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions Editor/EditorHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -527,5 +526,38 @@ public void Dispose()
}
}

#endregion Blocks
public static class GridBlock
{
public static void Draw<T>(ref Vector2 scrollPos, bool alwaysShowHorizontalScrollbar, bool alwaysShowVerticalScrollbar, List<T> elements, int itemCountX, float padding, Func<T, bool> 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();
}
}
}
2 changes: 1 addition & 1 deletion Example/Editor/DemoScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static class DemoScenarios
Name = "SwitchGUIDepth",
Scenarios = new List<DemoScenarioContent>
{
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);
Expand Down