public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property == null || property.objectReferenceValue == null) { RefEditorGUI.DefaultPropertyField(position, property, label); return; } if (property.objectReferenceValue is ScriptableObject) { Debug.Log("Default"); Default(position, property, label); return; } MonoBehaviour behaviour = property.objectReferenceValue as MonoBehaviour; List <Object> components = new List <Object>(behaviour.gameObject.GetComponents <MonoBehaviour>()); if (components.Count == 1) { Default(position, property, label); return; } index = UnityEngine.Mathf.Max(1, components.IndexOf(behaviour) + 1); string[] texts = new string[components.Count + 1]; texts[0] = "None"; for (int i = 1; i < components.Count + 1; i++) { texts[i] = i.ToString() + " : " + components[i - 1].ToString(); } index = EditorGUI.Popup(position, property.displayName, index, texts); if (index == 0) { property.objectReferenceValue = null; Default(position, property, label); return; } property.objectReferenceValue = components[index - 1]; }
public void Default(Rect position, SerializedProperty property, GUIContent label) { RefEditorGUI.DefaultPropertyField(position, property, label); }