/// <summary> /// Helper method that automates metadata migration for array based graph reorders. /// </summary> public static void MigrateMetadata <T>(fiGraphMetadata metadata, T[] previous, T[] updated) { var migrations = ComputeNeededMigrations(metadata, previous, updated); // migrate persistent data var fromKeys = new string[migrations.Count]; var toKeys = new string[migrations.Count]; for (int i = 0; i < migrations.Count; ++i) { fromKeys[i] = metadata.Enter(migrations[i].OldIndex).Metadata._accessPath; toKeys[i] = metadata.Enter(migrations[i].NewIndex).Metadata._accessPath; } // fiPersistentMetadata.Migrate(metadata.TargetObject, fromKeys, toKeys); // migrate the graph items List <fiGraphMetadata> copiedGraphs = new List <fiGraphMetadata>(migrations.Count); for (int i = 0; i < migrations.Count; ++i) { copiedGraphs.Add(metadata._childrenInt[i]); } for (int i = 0; i < migrations.Count; ++i) { metadata._childrenInt[migrations[i].NewIndex] = copiedGraphs[i]; } }
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); }
protected override float OnGetHeight(UnityObject behavior, fiGraphMetadata metadata) { fiGraphMetadataChild childMetadata = metadata.Enter("DefaultBehaviorEditor", null); childMetadata.Metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable(); float height = 0; // 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)); height += editor.GetElementHeight(GUIContent.none, behavior, childMetadata); return(height); }
public virtual TElement Edit(Rect region, GUIContent label, TElement element, fiGraphMetadata metadata) { var nextEditor = EditorChain.GetNextEditor(this); return(PropertyEditorExtensions.Edit(nextEditor, region, label, element, metadata.Enter("IPropertyEditor"))); }
public virtual float GetElementHeight(GUIContent label, TElement element, fiGraphMetadata metadata) { var nextEditor = EditorChain.GetNextEditor(this); return(PropertyEditorExtensions.GetElementHeight(nextEditor, label, element, metadata.Enter("IPropertyEditor"))); }
public override float GetElementHeight(GUIContent label, Facade <T> element, fiGraphMetadata metadata) { float height = 0; if (string.IsNullOrEmpty(label.text) == false || TypeOptions.Types.Length > 1) { height = LabelHeight; } var anim = metadata.GetMetadata <fiAnimationMetadata>(); if (anim.IsAnimating) { return(height + anim.AnimationHeight); } if (element == null) { element = new Facade <T>(); } if (element.InstanceType == null) { element.InstanceType = TypeOptions.Types[0]; } InspectedType inspectedType = InspectedType.Get(element.InstanceType); var serializer = (BaseSerializer)fiSingletons.Get(fiInstalledSerializerManager.DefaultMetadata.SerializerType); var deserializationOp = new ListSerializationOperator() { SerializedObjects = element.ObjectReferences }; var properties = inspectedType.GetProperties(InspectedMemberFilters.InspectableMembers); for (int i = 0; i < properties.Count; ++i) { InspectedProperty property = properties[i]; object propertyValue = DeserializeProperty(serializer, deserializationOp, property, element); height += fiEditorGUI.EditPropertyHeightDirect(property, propertyValue, metadata.Enter(property.Name)); height += SplitterHeight; } return(height); }
public override Facade <T> Edit(Rect region, GUIContent label, Facade <T> element, fiGraphMetadata metadata) { if (element == null) { element = new Facade <T>(); } if (element.InstanceType == null) { element.InstanceType = TypeOptions.Types[0]; } bool changedTypes; DrawHeader(ref region, label, element, out changedTypes); var facadeMembers = new Dictionary <string, string>(); var facadeReferences = new List <UnityObject>(); InspectedType inspectedType = InspectedType.Get(element.InstanceType); var serializer = (BaseSerializer)fiSingletons.Get(fiInstalledSerializerManager.DefaultMetadata.SerializerType); var deserializationOp = new ListSerializationOperator() { SerializedObjects = element.ObjectReferences }; var serializationOp = new ListSerializationOperator() { SerializedObjects = facadeReferences }; float usedHeight = 0; var anim = metadata.GetMetadata <fiAnimationMetadata>(); if (anim.IsAnimating) { fiEditorGUI.BeginFadeGroupHeight(LabelHeight, ref region, anim.AnimationHeight); fiEditorUtility.RepaintAllEditors(); } var properties = inspectedType.GetProperties(InspectedMemberFilters.InspectableMembers); for (int i = 0; i < properties.Count; ++i) { InspectedProperty property = properties[i]; object propertyValue = DeserializeProperty(serializer, deserializationOp, property, element); float height = fiEditorGUI.EditPropertyHeightDirect(property, propertyValue, metadata.Enter(property.Name)); Rect propertyRect = region; propertyRect.height = height; region.y += height; region.y += SplitterHeight; usedHeight += height + SplitterHeight; object updatedValue = fiEditorGUI.EditPropertyDirect(propertyRect, property, propertyValue, metadata.Enter(property.Name)); string data; if (TrySerializeProperty(serializer, serializationOp, property, updatedValue, out data)) { facadeMembers[property.Name] = data; } } if (anim.IsAnimating) { fiEditorGUI.EndFadeGroup(); } element.FacadeMembers = facadeMembers; element.ObjectReferences = facadeReferences; if (changedTypes && anim.UpdateHeight(usedHeight)) { fiEditorUtility.RepaintAllEditors(); } return(element); }
/// <summary> /// This will return metadata that will be unique for this control. The metadata /// object that is passed down to each control is shared among every control -- if /// a control needs to store metadata, then it should fetch the instance metadata to /// do so, otherwise the metadata will be shared among every instance of that control /// for each object. /// </summary> protected fiGraphMetadata GetInstanceMetadata(fiGraphMetadata metadata) { return(metadata.Enter(_uniqueId).Metadata); }
protected virtual float GetElementHeight(GUIContent label, TElement element, TAttribute attribute, fiGraphMetadata metadata) { var nextEditor = EditorChain.GetNextEditor(this); return(PropertyEditorExtensions.GetElementHeight(nextEditor, label, element, metadata.Enter("IAttributePropertyEditor", metadata.Context))); }