public static T DrawPropertyEditor <T>(T obj, fiGraphMetadata metadata) { var label = GUIContent.none; IPropertyEditor editor = PropertyEditor.Get(typeof(T), null).FirstEditor; var height = editor.GetElementHeight(label, obj, metadata.Enter("Root", metadata.Context)); Rect rect = new Rect(0, 0, 500, height); var serializedObj = obj as ISerializationCallbackReceiver; if (serializedObj != null) { serializedObj.OnBeforeSerialize(); serializedObj.OnAfterDeserialize(); } obj = editor.Edit(rect, label, obj, metadata.Enter("Root", metadata.Context)); if (serializedObj != null) { serializedObj.OnBeforeSerialize(); } return(obj); }
public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata) { metadata.Enter("AbstractTypeEditor").Metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable(); try { fiEditorGUI.AnimatedBegin(ref region, metadata); _options.RemoveExtraneousOptions(); // draw the popup { int popupHeight = (int)EditorStyles.popup.CalcHeight(GUIContent.none, 100); Rect popupRegion = new Rect(region); popupRegion.height = popupHeight; region.y += popupRegion.height; region.height -= popupRegion.height; int selectedIndex = _options.GetDisplayOptionIndex(element); int updatedIndex = EditorGUI.Popup(popupRegion, label, selectedIndex, _options.GetDisplayOptions()); if (selectedIndex != updatedIndex) { metadata.GetMetadata <AbstractTypeAnimationMetadata>().ChangedTypes = true; } element = _options.UpdateObjectInstance(element, selectedIndex, updatedIndex); } // no element; no editor if (element == null) { return(null); } // draw the instance specific property editor { Rect selectedRegion = new Rect(region); selectedRegion = fiRectUtility.IndentedRect(selectedRegion); region.y += selectedRegion.height; region.height -= selectedRegion.height; // show custom editor PropertyEditorChain chain = PropertyEditor.Get(element.GetType(), null); IPropertyEditor editor = chain.SkipUntilNot(typeof(AbstractTypePropertyEditor)); return(editor.Edit(selectedRegion, GUIContent.none, element, metadata.Enter("AbstractTypeEditor"))); } } finally { fiEditorGUI.AnimatedEnd(metadata); } }
/// <summary> /// This method makes it easy to use a typical property editor as a GUILayout style method, /// where the rect is taken care of. /// </summary> /// <param name="editor">The editor that is being used.</param> /// <param name="label">The label to edit the region with.</param> /// <param name="element">The element that is being edited.</param> public static T EditWithGUILayout <T>(this IPropertyEditor editor, GUIContent label, T element, fiGraphMetadataChild metadata) { float height = editor.GetElementHeight(label, element, metadata); Rect region = EditorGUILayout.GetControlRect(false, height); if (Event.current.type != EventType.Layout) { return(editor.Edit(region, label, element, metadata)); } return(element); }
public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata) { // draw the nullable type toggle { int labelHeight = (int)EditorStyles.label.CalcHeight(GUIContent.none, 100); Rect toggleRegion = new Rect(region); toggleRegion.height = labelHeight; region.y += toggleRegion.height; region.height -= toggleRegion.height; if (EditorGUI.Toggle(toggleRegion, label, element != null)) { if (element == null) { element = _elementType.CreateInstance(); GUI.changed = true; } } else { element = null; } } // no element; no editor if (element == null) { return(null); } // we have a value for the nullable type; draw the property editor { Rect selectedRegion = new Rect(region); selectedRegion = fiRectUtility.IndentedRect(selectedRegion); region.y += selectedRegion.height; region.height -= selectedRegion.height; // show custom editor PropertyEditorChain chain = PropertyEditor.Get(element.GetType(), null); IPropertyEditor editor = chain.SkipUntilNot(typeof(NullablePropertyEditor)); return(editor.Edit(selectedRegion, GUIContent.none, element, metadata.Enter("NullableEditor", metadata.Context))); } }
protected override void OnEdit(Rect rect, UnityObject behavior, fiGraphMetadata metadata) { fiGraphMetadataChild childMetadata = metadata.Enter("DefaultBehaviorEditor"); childMetadata.Metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable(); // We don't want to get the IObjectPropertyEditor for the given target, which extends // UnityObject, so that we can actually edit the property instead of getting a Unity // reference field. We also don't want the AbstractTypePropertyEditor, which we will get // if the behavior has any derived types. PropertyEditorChain editorChain = PropertyEditor.Get(behavior.GetType(), null); IPropertyEditor editor = editorChain.SkipUntilNot( typeof(IObjectPropertyEditor), typeof(AbstractTypePropertyEditor)); // Run the editor editor.Edit(rect, GUIContent.none, behavior, childMetadata); }
/// <summary> /// Draws a GUI for editing the given property and returns the updated /// value. This does /// *not* write the updated value to a container. /// </summary> /// <param name="context"> /// An optional context that the property value came from. If this is not /// given, then a prefab context menu will not be displayable. /// </param> public static object EditPropertyDirect(Rect region, InspectedProperty property, object propertyValue, fiGraphMetadataChild metadataChild, object context) { fiGraphMetadata metadata = metadataChild.Metadata; // Show a "revert to prefab" value context-menu if possible if (context != null) { RevertPrefabContextMenu(region, context, property); } // get the label / tooltip GUIContent label = new GUIContent(property.DisplayName, InspectorTooltipAttribute.GetTooltip(property.MemberInfo)); var editorChain = PropertyEditor.Get(property.StorageType, property.MemberInfo); IPropertyEditor editor = editorChain.FirstEditor; EditorGUI.BeginDisabledGroup(property.CanWrite == false); propertyValue = editor.Edit(region, label, propertyValue, metadata.Enter("EditProperty", metadata.Context)); EditorGUI.EndDisabledGroup(); return(propertyValue); }