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 Component fieldValue = field.GetValue(target) as Component;
28 fieldValue = SceneObjectField(
29 SplitCamelCase(field.Name),
32 field.SetValue(target, fieldValue);
35 public override void DrawEditor(
UnityEngine.Object target, PropertyInfo prop)
37 Component propValue = prop.GetValue(target, null) as Component;
38 propValue = SceneObjectField(
39 SplitCamelCase(prop.Name),
42 prop.SetValue(target, propValue, null);
45 public static Component SceneObjectField(
string label, Component sceneObject, Type componentType)
48 EditorGUILayout.BeginHorizontal();
49 if (
string.IsNullOrEmpty(label))
51 sceneObject = (Component)EditorGUILayout.ObjectField(sceneObject, componentType,
true);
55 sceneObject = (Component)EditorGUILayout.ObjectField(label, sceneObject, componentType,
true);
57 if (sceneObject != null && sceneObject.gameObject.scene.name == null)
63 UnityEngine.Object[] objectsInScene = GameObject.FindObjectsOfType(componentType);
64 int selectedIndex = 0;
65 string[] displayedOptions =
new string[objectsInScene.Length + 1];
66 displayedOptions[0] =
"(None)";
67 for (
int i = 0; i < objectsInScene.Length; i++)
69 displayedOptions[i + 1] = objectsInScene[i].name;
70 if (objectsInScene[i] == sceneObject)
72 selectedIndex = i + 1;
75 selectedIndex = EditorGUILayout.Popup(selectedIndex, displayedOptions);
76 if (selectedIndex == 0)
82 sceneObject = (Component)objectsInScene[selectedIndex - 1];
84 EditorGUILayout.EndHorizontal();