public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { guiRect.SetRect(position); Initialize(property); int index = -1; int newIndex; if (property.Value != null) { index = Array.IndexOf(subclasses, property.Type); } if (index != -1) { Rect rect = guiRect.GetFieldRect(); float width = EditorGUIUtility.labelWidth; Rect r1 = new Rect(rect) { width = width }; Rect r2 = new Rect(rect) { x = rect.x + width, width = rect.width - width }; property.IsExpanded = EditorGUI.Foldout(r1, property.IsExpanded, property.Label); newIndex = EditorGUI.Popup(r2, index + 1, subclassNames) - 1; } else { newIndex = EditorGUI.Popup(guiRect.GetFieldRect(), property.Label, index + 1, subclassNames) - 1; } if (index != newIndex) { property.SetValueAndCopyCompatibleProperties( newIndex == -1 ? null : EditorReflector.MakeInstance(subclasses[newIndex]) ); property.IsExpanded = newIndex != -1; } if (property.IsExpanded && newIndex != -1) { EditorGUI.indentLevel += 2; EditorGUIX.DrawProperties(guiRect.GetRect(), property); EditorGUI.indentLevel -= 2; } }
private void DrawTypeSelect(Rect selectRect, ReflectedProperty property) { Type newConsiderationType; if (property.Value != null) { considerationType = property.Value.GetType(); newConsiderationType = EditorGUIX.ConstructableTypePopup <Consideration>(selectRect, considerationType, FormatTypeName, style); } else { considerationType = null; newConsiderationType = EditorGUIX.ConstructableTypePopup <Consideration>(selectRect, considerationType, FormatTypeName, style); } if (newConsiderationType != considerationType) { considerationType = newConsiderationType; Consideration instance = EditorReflector.MakeInstance <Consideration>(considerationType); property.SetValueAndCopyCompatibleProperties(instance); } }