Created
August 23, 2017 03:06
-
-
Save changhe3/e54ee228a1cdfc241a919f54a6a3ee8d to your computer and use it in GitHub Desktop.
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
using System; | |
public abstract class DisposableResult<T> : IDisposable { | |
public readonly T Value; | |
protected DisposableResult(T value) { | |
Value = value; | |
} | |
public abstract void Dispose(); | |
public static implicit operator T(DisposableResult<T> rhs) { | |
return rhs.Value; | |
} | |
} |
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
using System; | |
using UnityEditor; | |
using UnityEngine; | |
namespace EditorGUIHelper { | |
public class FadeGroup : DisposableResult<bool> { | |
public FadeGroup(float value) : base(EditorGUILayout.BeginFadeGroup(value)) {} | |
private void ReleaseUnmanagedResources() { | |
EditorGUILayout.EndFadeGroup(); | |
} | |
protected virtual void Dispose(bool disposing) { | |
ReleaseUnmanagedResources(); | |
if (disposing) { | |
// no managed resourses | |
} | |
} | |
public sealed override void Dispose() { | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
~FadeGroup() { | |
Dispose(false); | |
} | |
} | |
public class Horizontal : DisposableResult<Rect> { | |
public Horizontal(params GUILayoutOption[] options) : base(EditorGUILayout.BeginHorizontal(options)) {} | |
public Horizontal(GUIStyle style, params GUILayoutOption[] options) : base( | |
EditorGUILayout.BeginHorizontal(style, options)) { | |
} | |
private void ReleaseUnmanagedResources() { | |
EditorGUILayout.EndHorizontal(); | |
} | |
protected virtual void Dispose(bool disposing) { | |
ReleaseUnmanagedResources(); | |
if (disposing) { | |
} | |
} | |
public sealed override void Dispose() { | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
~Horizontal() { | |
Dispose(false); | |
} | |
} | |
public class ScrollView : DisposableResult<Vector2> { | |
public ScrollView(Vector2 scrollPosition, params GUILayoutOption[] options) : base( | |
EditorGUILayout.BeginScrollView(scrollPosition, options)) { | |
} | |
public ScrollView(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, | |
params GUILayoutOption[] options) : base(EditorGUILayout.BeginScrollView(scrollPosition, | |
alwaysShowHorizontal, alwaysShowVertical, options)) { | |
} | |
public ScrollView(Vector2 scrollPosition, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, | |
params GUILayoutOption[] options) : base(EditorGUILayout.BeginScrollView(scrollPosition, | |
horizontalScrollbar, verticalScrollbar, options)) { | |
} | |
public ScrollView(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, | |
GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, | |
params GUILayoutOption[] options) : base(EditorGUILayout.BeginScrollView(scrollPosition, | |
alwaysShowHorizontal, alwaysShowVertical, horizontalScrollbar, verticalScrollbar, background, options)) { | |
} | |
private void ReleaseUnmanagedResources() { | |
EditorGUILayout.EndScrollView(); | |
} | |
protected virtual void Dispose(bool disposing) { | |
ReleaseUnmanagedResources(); | |
if (disposing) { | |
} | |
} | |
public sealed override void Dispose() { | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
~ScrollView() { | |
Dispose(false); | |
} | |
} | |
public class ToggleGroup : DisposableResult<bool> { | |
public ToggleGroup(string label, bool toggle) : base(EditorGUILayout.BeginToggleGroup(label, toggle)) {} | |
public ToggleGroup(GUIContent label, bool toggle) : base(EditorGUILayout.BeginToggleGroup(label, toggle)) {} | |
private void ReleaseUnmanagedResources() { | |
EditorGUILayout.EndToggleGroup(); | |
} | |
protected virtual void Dispose(bool disposing) { | |
ReleaseUnmanagedResources(); | |
if (disposing) { | |
} | |
} | |
public sealed override void Dispose() { | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
~ToggleGroup() { | |
Dispose(false); | |
} | |
} | |
public class Vertical : DisposableResult<Rect> { | |
public Vertical(params GUILayoutOption[] options) : base(EditorGUILayout.BeginVertical(options)) {} | |
public Vertical(GUIStyle style, params GUILayoutOption[] options) : base(EditorGUILayout.BeginVertical(style, options)) {} | |
private void ReleaseUnmanagedResources() { | |
EditorGUILayout.EndVertical(); | |
} | |
protected virtual void Dispose(bool disposing) { | |
ReleaseUnmanagedResources(); | |
if (disposing) { | |
} | |
} | |
public sealed override void Dispose() { | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
~Vertical() { | |
Dispose(false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment