Last active
August 23, 2017 03:09
-
-
Save eral/23751a84167917f6e7c4 to your computer and use it in GitHub Desktop.
Disposable EditorGUILayout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by ERAL | |
// This is free and unencumbered software released into the public domain. | |
using UnityEngine; | |
using UnityEditor; | |
class HorizontalGroup : System.IDisposable { | |
public Rect Rect; | |
public HorizontalGroup(params GUILayoutOption[] options) { | |
Rect = EditorGUILayout.BeginHorizontal(options); | |
} | |
public HorizontalGroup(GUIStyle style, params GUILayoutOption[] options) { | |
Rect = EditorGUILayout.BeginHorizontal(style, options); | |
} | |
public void Dispose() { | |
EditorGUILayout.EndHorizontal(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by ERAL | |
// This is free and unencumbered software released into the public domain. | |
using UnityEngine; | |
using UnityEditor; | |
[CustomEditor(typeof(Sample))] | |
public class SampleEditor : Editor { | |
public override void OnInspectorGUI() { | |
EditorGUILayout.LabelField("Horizontal Group Sample"); | |
using (new HorizontalGroup()) { | |
GUILayout.Button("Button1", EditorStyles.miniButtonLeft); | |
GUILayout.Button("Button2", EditorStyles.miniButtonMid); | |
GUILayout.Button("Button3", EditorStyles.miniButtonRight); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also have a similar piece of code. I wonder if it is necessary to implement IDisposable interface according to this guide.