forked from cjacobwade/HelpfulScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditorUtils.cs
91 lines (78 loc) · 3.5 KB
/
EditorUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
using UnityEditor;
using LinqTools;
public static class EditorUtils
{
public static bool Toggle(this SerializedObject so, string propName, string labelName, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
prop.boolValue = EditorGUILayout.Toggle(labelName, prop.boolValue, options);
return prop.boolValue;
}
public static bool Toggle(this SerializedObject so, string propName, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
prop.boolValue = EditorGUILayout.Toggle(prop.boolValue, options);
return prop.boolValue;
}
public static float FloatField(this SerializedObject so, string propName, string labelName, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
prop.floatValue = EditorGUILayout.FloatField(labelName, prop.floatValue, options);
return prop.floatValue;
}
public static float FloatField(this SerializedObject so, string propName, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
prop.floatValue = EditorGUILayout.FloatField(prop.floatValue, options);
return prop.floatValue;
}
public static int IntSlider(this SerializedObject so, string propName, string labelName, int leftValue, int rightValue, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
prop.intValue = EditorGUILayout.IntSlider(labelName, prop.intValue, leftValue, rightValue, options);
return prop.intValue;
}
public static int IntSlider(this SerializedObject so, string propName, int leftValue, int rightValue, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
prop.intValue = EditorGUILayout.IntSlider(prop.intValue, leftValue, rightValue, options);
return prop.intValue;
}
public static int EnumPopup<T>(this SerializedObject so, string propName, string labelName, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
var enumValue = (System.Enum)System.Enum.ToObject(typeof(T), prop.intValue);
prop.intValue = (int)((object)EditorGUILayout.EnumPopup(labelName, enumValue, options));
return prop.intValue;
}
public static int EnumPopup<T>(this SerializedObject so, string propName, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
var enumValue = (System.Enum)System.Enum.ToObject(typeof(T), prop.intValue);
prop.intValue = (int)((object)EditorGUILayout.EnumPopup(enumValue, options));
return prop.intValue;
}
public static bool PropertyField(this SerializedObject so, string propName, bool includeChildren = false, params GUILayoutOption[] options)
{
var prop = so.FindProperty(propName);
return EditorGUILayout.PropertyField(prop, includeChildren, options);
}
public static T ObjectField<T>(this SerializedObject so, string propName, string labelName, bool allowSceneObjects, params GUILayoutOption[] layoutOptions) where T : Object
{
var prop = so.FindProperty(propName);
prop.objectReferenceValue = EditorGUILayout.ObjectField(labelName,
prop.objectReferenceValue, typeof(T), allowSceneObjects, layoutOptions);
return (T)prop.objectReferenceValue;
}
public static T ObjectField<T>(this SerializedObject so, string propName, bool allowSceneObjects, params GUILayoutOption[] layoutOptions) where T : Object
{
var prop = so.FindProperty(propName);
prop.objectReferenceValue = EditorGUILayout.ObjectField(prop.objectReferenceValue,
typeof(T), allowSceneObjects, layoutOptions);
return (T)prop.objectReferenceValue;
}
}
#endif