using System; using UnityEditor; using UnityEngine; public class TestWindow : EditorWindow { [MenuItem("Test/Test Window")] public static void Init() { CreateInstance().Show(); } private Vector2 scrollPosition = new Vector2(0,0); private int testValue; public void OnGUI() { scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); TestLabels(); EditorGUILayout.Space(); EditorGUILayout.LabelField("After 10 levels of indentation:"); EditorGUILayout.Space(); using (new ScopedIndent(10)) { TestLabels(); } EditorGUILayout.EndScrollView(); } private void TestLabels() { testValue = EditorGUILayout.IntField("This is a label:", testValue); testValue = EditorGUILayout.IntField("This is a much longer label:", testValue); testValue = EditorGUILayout.IntField("Min width:", testValue, GUILayout.MinWidth(300)); testValue = EditorGUILayout.IntField("Max width:", testValue, GUILayout.MaxWidth(300)); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Horizontal group:"); testValue = EditorGUILayout.IntField(testValue); EditorGUILayout.EndHorizontal(); using (new FixedWidthLabel("Fixed width (label only):")) { testValue = EditorGUILayout.IntField(testValue); } using (new FixedWidthLabel("This is a longer fixed width label:")) { testValue = EditorGUILayout.IntField(testValue); } using (new FixedWidthLabel("Two vertical input boxes:")) { EditorGUILayout.BeginVertical(); testValue = EditorGUILayout.IntField(testValue); testValue = EditorGUILayout.IntField(testValue); EditorGUILayout.EndVertical(); } using (new FixedWidthLabel("Two horizontal input boxes:")) { testValue = EditorGUILayout.IntField(testValue); testValue = Convert.ToInt32(EditorGUILayout.TextField(testValue + "")); } using (new FixedWidthLabel("Nesting:")) { testValue = EditorGUILayout.IntField(testValue); using (new FixedWidthLabel("Testing:")) { testValue = EditorGUILayout.IntField(testValue); } } using (new FixedWidthLabel("Vertical + nested:")) { EditorGUILayout.BeginVertical(); testValue = EditorGUILayout.IntField(testValue); testValue = EditorGUILayout.IntField(testValue); using (new FixedWidthLabel("Nesting:")) { testValue = EditorGUILayout.IntField(testValue); using (new FixedWidthLabel("Testing:")) { testValue = EditorGUILayout.IntField(testValue); } } EditorGUILayout.EndVertical(); } } } public class ScopedIndent : IDisposable { private readonly int delta; public ScopedIndent(int delta) { this.delta = delta; EditorGUI.indentLevel += delta; } public void Dispose() { EditorGUI.indentLevel -= delta; } }