16 public static float Indent
20 return EditorGUI.IndentedRect(
new Rect()).x;
28 public const float HorizontalSpacing = 6.0f;
30 public static bool Button(Rect position,
string text)
32 return Button(position,
new GUIContent(text));
35 public static bool Button(Rect position, GUIContent content)
37 float indent = Indent;
39 position.width -= indent;
40 return GUI.Button(position, content);
43 public static void Label(Rect position,
string text)
45 float indent = Indent;
47 position.width -= indent;
48 GUI.Label(position, text);
55 if (valueType == typeof(Vector3) || valueType == typeof(Vector2))
57 return (!hasLabel || EditorGUIUtility.wideMode ? 0f : EditorGUIUtility.singleLineHeight) + EditorGUIUtility.singleLineHeight;
60 if (valueType == typeof(Rect))
62 return (!hasLabel || EditorGUIUtility.wideMode ? 0f : EditorGUIUtility.singleLineHeight) + EditorGUIUtility.singleLineHeight * 2;
65 if (valueType == typeof(Bounds))
67 return (!hasLabel ? 0f : EditorGUIUtility.singleLineHeight) + EditorGUIUtility.singleLineHeight * 2;
70 return EditorGUIUtility.singleLineHeight;
82 public static T ObjectField<T>(Rect position, GUIContent label, T value,
bool allowSceneObjects)
84 object objValue = value;
86 Type valueType = objValue.GetType();
87 if (valueType == typeof(Bounds))
89 objValue = EditorGUI.BoundsField(position, label, (Bounds)objValue);
91 else if (valueType == typeof(Color))
93 objValue = EditorGUI.ColorField(position, label, (Color)objValue);
95 else if (valueType == typeof(Material))
97 objValue = EditorGUI.ObjectField(position, (Material)objValue, typeof(Material), allowSceneObjects);
99 else if (valueType == typeof(AnimationCurve))
101 objValue = EditorGUI.CurveField(position, label, (AnimationCurve)objValue);
103 else if (valueType == typeof(
float))
105 objValue = EditorGUI.FloatField(position, label, (
float)objValue);
107 else if (valueType == typeof(
int))
109 objValue = EditorGUI.IntField(position, label, (
int)objValue);
111 else if (valueType == typeof(LayerMask))
115 else if (valueType.IsEnum)
117 if (valueType.GetCustomAttributes(typeof(FlagsAttribute),
true).Length > 0)
119 #if UNITY_2017_3_OR_NEWER 120 objValue = EditorGUI.EnumFlagsField(position, label, (Enum)objValue);
122 objValue = EditorGUI.EnumMaskField(position, label, (Enum)objValue);
127 objValue = EditorGUI.EnumPopup(position, label, (Enum)objValue);
130 else if (valueType == typeof(Rect))
132 objValue = EditorGUI.RectField(position, label, (Rect)objValue);
134 else if (valueType == typeof(
string))
136 objValue = EditorGUI.TextField(position, label, (
string)objValue);
138 else if (valueType == typeof(Vector2))
140 objValue = EditorGUI.Vector2Field(position,
new GUIContent(), (Vector2)objValue);
142 else if (valueType == typeof(Vector3))
144 objValue = EditorGUI.Vector3Field(position,
new GUIContent(), (Vector3)objValue);
146 else if (valueType == typeof(Vector4))
148 if (label.image != null)
150 throw new ArgumentException(
"Images not supported for labels of Vector4 fields.",
"label");
153 if (!
string.IsNullOrEmpty(label.tooltip))
155 throw new ArgumentException(
"Tool-tips not supported for labels of Vector4 fields.",
"label");
158 objValue = EditorGUI.Vector4Field(position, label.text, (Vector4)objValue);
160 else if (Equals(objValue, typeof(SceneAsset)))
162 objValue = EditorGUI.ObjectField(position, (SceneAsset)objValue, typeof(SceneAsset), allowSceneObjects);
166 objValue = EditorGUI.ObjectField(position, label, (
UnityEngine.Object)objValue, valueType, allowSceneObjects);
170 throw new ArgumentException(
172 CultureInfo.InvariantCulture,
173 "Unimplemented value type: {0}.",
UnityEngine.UI.Button Button