public ArrayAdaptor(T[] array, ItemDrawer itemDrawer, ItemHeight itemHeight, fiGraphMetadata metadata) { _metadata = metadata; _array = array; _itemDrawer = itemDrawer; _itemHeight = itemHeight; }
public static void AnimatedEnd(fiGraphMetadata metadata) { var anim = metadata.GetMetadata<fiAnimationMetadata>(); if (anim.IsAnimating) { EndFadeGroup(); } }
public static void AnimatedBegin(ref Rect rect, fiGraphMetadata metadata) { var anim = metadata.GetMetadata<fiAnimationMetadata>(); if (anim.IsAnimating) { BeginFadeGroupHeight(0, ref rect, anim.AnimationHeight); } }
public override TStack Edit(Rect region, GUIContent label, TStack element, fiGraphMetadata metadata) { var collection = new StackCollection <T>(element); collection = (StackCollection <T>)ActualEditor.Edit(region, label, collection, metadata); return((TStack)collection.Stack); }
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) { Enum selected = (Enum)element; if (selected.GetType().IsDefined(typeof(FlagsAttribute), /*inherit:*/ true)) { return EditorGUI.EnumMaskField(region, label, selected); } return EditorGUI.EnumPopup(region, label, selected); }
public static float AnimatedHeight(float currentHeight, bool updateHeight, fiGraphMetadata metadata) { var anim = metadata.GetMetadata<fiAnimationMetadata>(); if (updateHeight) anim.UpdateHeight(currentHeight); if (anim.IsAnimating) { fiEditorUtility.RepaintAllEditors(); return anim.AnimationHeight; } return currentHeight; }
// see http://answers.unity3d.com/questions/436295/how-to-have-a-gradient-editor-in-an-editor-script.html // for the inspiration behind this approach private ItemMetadata GetMetadata(fiGraphMetadata graphMetadata) { var metadata = graphMetadata.GetMetadata <ItemMetadata>(); if (metadata.Container == null) { metadata.Container = MetadataObject.AddComponent <TContainer>(); metadata.SerializedObject = new SerializedObject(metadata.Container); metadata.SerializedProperty = metadata.SerializedObject.FindProperty("Item"); } return(metadata); }
public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata) { metadata.Enter("AbstractTypeEditor", metadata.Context).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", metadata.Context)); } } finally { fiEditorGUI.AnimatedEnd(metadata); } }
public static fiGraphMetadata GetMetadataFor(UnityObject target_) { var target = new fiUnityObjectReference(target_); fiGraphMetadata metadata; if (s_metadata.TryGetValue(target, out metadata) == false) { // Make sure that we update the s_metadata instance for target before initializing all of the providers, // as some of the providers may recurisvely call into this method to fetch the actual fiGraphMetadata // instance during initialization. metadata = new fiGraphMetadata(target); s_metadata[target] = metadata; for (int i = 0; i < s_providers.Length; ++i) { s_providers[i].RestoreData(target.Target); } } return metadata; }
/// <summary> /// Draws an editor for the given control at the given rect. /// </summary> /// <param name="element">The element to edit.</param> /// <param name="metadata">The metadata to use when editing.</param> /// <param name="control">The actual control that will be used for the editor.</param> /// <returns>The height that is needed to fully display this control.</returns> public static float tkControlHeight(object element, fiGraphMetadata metadata, tkControlEditor control) { fiLateBindingsBinder.EnsureLoaded(); var height = control.Control.GetHeight(element, control.Context, metadata.Enter(tkControl_Metadata_Layout).Metadata); if (control.Debug) { height += tkControl_MarginBeforeHelp; height += tkControl_HelpRectHeight; height += fiLateBindings.EditorGUIUtility.standardVerticalSpacing; height += tkControl_PropertyEditor.FirstEditor.GetElementHeight(tkControl_DebugControl_Label, control, metadata.Enter(tkControl_Metadata_DebugControl)); } return(height); }
public override IEnumerable ExecuteTest(MonoBehaviour target) { var metadata = new fiGraphMetadata(); LayerMask expectedValue = ~(1 << LayerMask.NameToLayer("Water")); Model model = new Model { mask = 0 }; yield return fiTestUtilities.DrawPropertyEditor(model, metadata); model.mask = expectedValue; yield return fiTestUtilities.DrawPropertyEditor(model, metadata); Assert.AreEqual(expectedValue, model.mask); }
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")); } }
public static void DisplayDeserializedObject(fiDeserializedObject obj, fiGraphMetadata metadata) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.BeginVertical(); for (int i = 0; i < obj.Members.Count; ++i) { fiDeserializedMember member = obj.Members[i]; PropertyEditorChain editor = PropertyEditor.Get( member.InspectedProperty.StorageType, member.InspectedProperty.MemberInfo); GUILayout.BeginHorizontal(); member.ShouldRestore.Enabled = GUILayout.Toggle(member.ShouldRestore.Enabled, GUIContent.none, GUILayout.Width(15)); GUI.enabled = false; string label = member.InspectedProperty.DisplayName; if (member.ShouldRestore.Enabled) { editor.FirstEditor.EditWithGUILayout(new GUIContent(label), member.Value, metadata.Enter(label, null)); } else { GUILayout.Label(new GUIContent(label + " (will not restore)")); } GUI.enabled = true; GUILayout.EndHorizontal(); if (i != obj.Members.Count - 1) { fiEditorGUILayout.Splitter(1); } } GUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); }
private void DisableFoldouts(fiGraphMetadata metadata) { if (_showTopLevelFoldout == false) { metadata.GetPersistentMetadata<fiDropdownMetadata>().ForceDisable(); } for (int i = 0; i < _editors.Count; ++i) { metadata.Enter(i).Metadata.GetPersistentMetadata<fiDropdownMetadata>().ForceDisable(); } if (_showPrimary) { metadata.Enter("Primary").Metadata.GetPersistentMetadata<fiDropdownMetadata>().ForceDisable(); } }
public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata) { float height = 0; for (int i = 0; i < _editors.Count; ++i) { height += _editors[i].GetElementHeight(label, element, metadata.Enter(i)); } if (_showPrimary) { height += NextEditor.GetElementHeight(label, element, metadata.Enter("Primary")); } return height; }
public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata) { DisableFoldouts(metadata); if (_indent) { region.x += fiRectUtility.IndentHorizontal; region.width -= fiRectUtility.IndentHorizontal; } var heights = new List<float>(_editors.Count); for (int i = 0; i < _editors.Count; ++i) { heights.Add(_editors[i].GetElementHeight(label, element, metadata.Enter(i))); } Rect editRegion = region; for (int i = 0; i < _editors.Count; ++i) { editRegion.height = heights[i]; element = _editors[i].Edit(editRegion, label, element, metadata.Enter(i)); editRegion.y += editRegion.height; } if (_showPrimary) { editRegion.height = NextEditor.GetElementHeight(label, element, metadata.Enter("Primary")); element = NextEditor.Edit(editRegion, label, element, metadata.Enter("Primary")); } return element; }
/// <summary> /// A helper method that draws the inspector for a field/property at the given location. /// </summary> private void EditProperty(ref Rect region, object element, InspectedProperty property, fiGraphMetadata metadata) { bool hasPrefabDiff = fiPrefabTools.HasPrefabDiff(element, property); if (hasPrefabDiff) fiUnityInternalReflection.SetBoldDefaultFont(true); // edit the property { var childMetadata = metadata.Enter(property.Name); fiGraphMetadataCallbacks.PropertyMetadataCallback(childMetadata.Metadata, property); Rect propertyRect = region; float propertyHeight = fiEditorGUI.EditPropertyHeight(element, property, childMetadata); propertyRect.height = propertyHeight; fiEditorGUI.EditProperty(propertyRect, element, property, childMetadata); region.y += propertyHeight; } if (hasPrefabDiff) fiUnityInternalReflection.SetBoldDefaultFont(false); }
private void EditInspectedMember(ref Rect region, object element, InspectedMember member, fiGraphMetadata metadata) { // requested skip if (ShouldShowMemberDynamic(element, member.MemberInfo) == false) { return; } if (member.IsMethod) { EditButton(ref region, element, member.Method); } else { EditProperty(ref region, element, member.Property, metadata); } region.y += DividerHeight; }
/// <summary> /// Draws the actual property editors. /// </summary> private object EditPropertiesButtons(GUIContent label, Rect region, object element, fiGraphMetadata metadata) { // If we have a label, then our properties block is indented and we should use hierarchy mode. Otherwise // we do not have a label so our properties block is *not* indented so we should *not* use hierarchy mode. // // HACK: We also check the nesting depth - if we're the top-level editor, then we want to enable hierarchy // mode fiEditorGUI.PushHierarchyMode(_cycleEdit.Depth == 1 || string.IsNullOrEmpty(label.text) == false); var categories = _metadata.GetCategories(InspectedMemberFilters.InspectableMembers); if (categories.Count > 0) { var selectedCategoryMetadata = metadata.GetMetadata<SelectedCategoryMetadata>(); Rect toolbarRect = region; toolbarRect.height = CategoryToolbarHeight; region.y += CategoryToolbarHeight + EditorGUIUtility.standardVerticalSpacing; region.height -= CategoryToolbarHeight + EditorGUIUtility.standardVerticalSpacing; int index = selectedCategoryMetadata.SelectedCategoryIndex; selectedCategoryMetadata.SelectedCategoryIndex = GUI.Toolbar(toolbarRect, index, categories.Keys.ToArray()); foreach (var member in categories.Values.ElementAt(index)) { EditInspectedMember(ref region, element, member, metadata); } // Make sure we don't prune metadata foreach (var member in _metadata.GetMembers(InspectedMemberFilters.InspectableMembers)) { metadata.Enter(member.Name); } } else { var orderedMembers = _metadata.GetMembers(InspectedMemberFilters.InspectableMembers); for (int i = 0; i < orderedMembers.Count; ++i) { EditInspectedMember(ref region, element, orderedMembers[i], metadata); } } fiEditorGUI.PopHierarchyMode(); return element; }
/// <summary> /// Draws an editor for the given control at the given rect. /// </summary> /// <param name="element">The element to edit.</param> /// <param name="label">The label for the edited control.</param> /// <param name="metadata">The metadata to use when editing.</param> /// <param name="control"> /// The actual control that will be used for the editor. /// </param> /// <returns> /// The height that is needed to fully display this control. /// </returns> public static float tkControlHeight(GUIContent label, object element, fiGraphMetadata metadata, tkControlEditor control) { fiLateBindingsBinder.EnsureLoaded(); SetupContext(control, label); var height = control.Control.GetHeight(element, control.Context, metadata.Enter(tkControl_Metadata_Layout, metadata.Context).Metadata); if (control.Debug) { height += tkControl_MarginBeforeHelp; height += tkControl_HelpRectHeight; height += fiLateBindings.EditorGUIUtility.standardVerticalSpacing; height += tkControl_PropertyEditor.FirstEditor.GetElementHeight(tkControl_DebugControl_Label, control, metadata.Enter(tkControl_Metadata_DebugControl, null)); } return height; }
/// <summary> /// Draws an editor for the given control at the given rect. /// </summary> /// <param name="rect">The rect to draw the editor within.</param> /// <param name="label">The label for the edited control.</param> /// <param name="element">The element to edit.</param> /// <param name="metadata">The metadata to use when editing.</param> /// <param name="control"> /// The actual control that will be used for the editor. /// </param> /// <returns>The updated element instance.</returns> public static object tkControl(Rect rect, GUIContent label, object element, fiGraphMetadata metadata, tkControlEditor control) { fiLateBindingsBinder.EnsureLoaded(); Rect layoutRect = rect; Rect helpRect = rect; Rect tweakerRect = rect; if (control.Debug) { float tweakerRectHeight = tkControl_PropertyEditor.FirstEditor.GetElementHeight(tkControl_DebugControl_Label, control, metadata.Enter(tkControl_Metadata_DebugControl, null)); layoutRect.height -= tkControl_MarginBeforeHelp + tkControl_HelpRectHeight + fiLateBindings.EditorGUIUtility.standardVerticalSpacing + tweakerRectHeight; helpRect = layoutRect; helpRect.y += layoutRect.height + tkControl_MarginBeforeHelp; helpRect.height = tkControl_HelpRectHeight; tweakerRect = helpRect; tweakerRect.y += tweakerRect.height + fiLateBindings.EditorGUIUtility.standardVerticalSpacing; tweakerRect.height = tweakerRectHeight; } SetupContext(control, label); element = control.Control.Edit(layoutRect, element, control.Context, metadata.Enter(tkControl_Metadata_Layout, metadata.Context).Metadata); if (control.Debug) { EditorGUI.HelpBox(helpRect, "The layout below should be used for visualizing the runtime layout structure or for tweaking layout values like minimum width. Changes will *not* persist - you need to modify the code itself.", MessageType.Info); tkControl_PropertyEditor.FirstEditor.Edit(tweakerRect, tkControl_DebugControl_Label, control, metadata.Enter(tkControl_Metadata_DebugControl, null)); } return element; }
public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata) { try { if (_cycleEdit == null) { _cycleEdit = new fiCycleDetector(_cycleHeight, _cycleScene); } _cycleEdit.Enter(); if (_cycleEdit.TryMark(element) == false) { EditorGUI.LabelField(region, label, new GUIContent("<cycle>")); return element; } if (HasLabel(label)) { region = DrawLabel(region, label); } if (element == null) { // if the user want's an instance, we'll create one right away We also check to // make sure we should automatically instantiate references, as if we're pretty // far down in the nesting level there may be an infinite recursion going on if (fiSettings.InspectorAutomaticReferenceInstantation && _metadata.HasDefaultConstructor && ShouldAutoInstantiate()) { element = _metadata.CreateInstance(); GUI.changed = true; } // otherwise we show a button to create an instance else { string buttonMessage = "null - create instance (ctor)?"; if (_metadata.HasDefaultConstructor == false) { buttonMessage = "null - create instance (unformatted)?"; } if (fiEditorGUI.LabeledButton(region, _metadata.ReflectedType.Name, buttonMessage)) { element = _metadata.CreateInstance(); GUI.changed = true; } return element; } } return EditPropertiesButtons(label, region, element, metadata); } finally { _cycleEdit.Exit(); if (_cycleEdit.Depth == 0) { _cycleEdit = null; } } }
public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata) { float height = EditorStyles.popup.CalcHeight(label, 100); height += fiRectUtility.IndentVertical; if (element != null) { PropertyEditorChain chain = PropertyEditor.Get(element.GetType(), null); IPropertyEditor editor = chain.SkipUntilNot(typeof(AbstractTypePropertyEditor)); height += editor.GetElementHeight(GUIContent.none, element, metadata.Enter("AbstractTypeEditor", metadata.Context)); } var abstractTypeMetadata = metadata.GetMetadata<AbstractTypeAnimationMetadata>(); height = fiEditorGUI.AnimatedHeight(height, abstractTypeMetadata.ChangedTypes, metadata); abstractTypeMetadata.ChangedTypes = false; return height; }
public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata) { return EditorStyles.popup.CalcHeight(label, 100); }
public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata) { try { if (_cycleHeight == null) { _cycleHeight = new fiCycleDetector(_cycleEdit, _cycleScene); } _cycleHeight.Enter(); if (_cycleHeight.TryMark(element) == false) { return EditorStyles.label.CalcHeight(GUIContent.none, 100); } float height = HasLabel(label) ? TitleHeight + fiRectUtility.IndentVertical : 0; if (element == null) { // if the user want's an instance, we'll create one right away. We also check to // make sure we should automatically instantiate references, as if we're pretty // far down in the nesting level there may be an infinite recursion going on if (fiSettings.InspectorAutomaticReferenceInstantation && _metadata.HasDefaultConstructor && ShouldAutoInstantiate()) { element = _metadata.CreateInstance(); GUI.changed = true; } // otherwise we show a button to create an instance else { height += ButtonHeight; } } if (element != null) { // figure out which members we should display List<InspectedMember> displayableMembers; var categories = _metadata.GetCategories(InspectedMemberFilters.InspectableMembers); if (categories.Count > 0) { var selectedCategoryMetadata = metadata.GetMetadata<SelectedCategoryMetadata>(); height += CategoryToolbarHeight + EditorGUIUtility.standardVerticalSpacing; displayableMembers = categories.Values.ElementAt(selectedCategoryMetadata.SelectedCategoryIndex); } else { displayableMembers = _metadata.GetMembers(InspectedMemberFilters.InspectableMembers); } // compute the height of the members we will display for (int i = 0; i < displayableMembers.Count; ++i) { var member = displayableMembers[i]; // requested skip if (ShouldShowMemberDynamic(element, member.MemberInfo) == false) { continue; } var childMetadata = metadata.Enter(member.Name); if (member.IsMethod) { height += ButtonHeight; } else { fiGraphMetadataCallbacks.PropertyMetadataCallback(childMetadata.Metadata, member.Property); height += fiEditorGUI.EditPropertyHeight(element, member.Property, childMetadata); } height += DividerHeight; } // Remove the last divider if (displayableMembers.Count > 0) height -= DividerHeight; } return height; } finally { _cycleHeight.Exit(); if (_cycleHeight.Depth == 0) { _cycleHeight = null; } } }
public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata) { float height = EditorStyles.label.CalcHeight(label, 100); if (element != null) { PropertyEditorChain chain = PropertyEditor.Get(element.GetType(), null); IPropertyEditor editor = chain.SkipUntilNot(typeof(NullablePropertyEditor)); height += fiRectUtility.IndentVertical; height += editor.GetElementHeight(GUIContent.none, element, metadata.Enter("NullableEditor")); } return height; }