14 [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
17 public string CustomLabel {
get;
private set; }
21 CustomLabel = customLabel;
25 public override void DrawEditor(
UnityEngine.Object target, FieldInfo field, SerializedProperty property)
27 Transform transform = (target as Component).transform;
29 GameObject fieldValue = field.GetValue(target) as GameObject;
30 fieldValue = DropDownGameObjectField(
31 SplitCamelCase(field.Name),
34 field.SetValue(target, fieldValue);
37 public override void DrawEditor(
UnityEngine.Object target, PropertyInfo prop)
39 Transform transform = (target as Component).transform;
41 GameObject propValue = prop.GetValue(target, null) as GameObject;
42 propValue = DropDownGameObjectField(
43 SplitCamelCase(prop.Name),
46 prop.SetValue(target, propValue, null);
49 private static GameObject DropDownGameObjectField(
string label, GameObject obj, Transform transform)
51 Transform[] optionObjects = transform.GetComponentsInChildren<Transform>(
true);
52 int selectedIndex = 0;
53 string[] options =
new string[optionObjects.Length + 1];
54 options[0] =
"(None)";
55 for (
int i = 0; i < optionObjects.Length; i++)
57 options[i + 1] = optionObjects[i].name;
58 if (obj == optionObjects[i].gameObject)
60 selectedIndex = i + 1;
64 EditorGUILayout.BeginHorizontal();
65 int newIndex = EditorGUILayout.Popup(label, selectedIndex, options);
73 obj = optionObjects[newIndex - 1].gameObject;
77 obj = (GameObject)EditorGUILayout.ObjectField(obj, typeof(GameObject),
true);
78 EditorGUILayout.EndHorizontal();