Skip to content

Instantly share code, notes, and snippets.

@eral
Last active August 23, 2017 03:09
Show Gist options
  • Save eral/23751a84167917f6e7c4 to your computer and use it in GitHub Desktop.
Save eral/23751a84167917f6e7c4 to your computer and use it in GitHub Desktop.
Disposable EditorGUILayout
// 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();
}
}
// 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);
}
}
}
@changhe3
Copy link

I also have a similar piece of code. I wonder if it is necessary to implement IDisposable interface according to this guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment