Пример #1
0
        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)
        {
            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);
        }
        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);
            }
        }
Пример #4
0
        public void Insert(int index)
        {
            Add();

            // shift metadata forwards
            for (int i = _list.Count - 1; i > index; --i)
            {
                _list[i] = _list[i - 1];
                _metadata.SetChild(i, _metadata.Enter(i - 1).Metadata);
            }

            // update the reference at index
            _list[index] = default(T);
            _metadata.SetChild(index, new fiGraphMetadata());
        }
Пример #5
0
        public void Insert(int index)
        {
            Add();

            // shift elements forwards
            for (int i = _array.Length - 1; i > index; --i)
            {
                _array[i] = _array[i - 1];
                _metadata.SetChild(i, _metadata.Enter(i - 1).Metadata);
            }

            // update the reference at index
            _array[index] = default(T);
            _metadata.SetChild(index, new fiGraphMetadata());
        }
Пример #6
0
        /// <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 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);
        }
Пример #8
0
        /// <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 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();
            }
        }
        protected override float GetElementHeight(GUIContent label, T element, InspectorSkipInheritanceAttribute attribute, fiGraphMetadata metadata)
        {
            if (element == null)
            {
                return(EditorGUIUtility.singleLineHeight);
            }

            return(GetEditor(element).GetElementHeight(label, element, metadata.Enter("InspectorSkipInheritance", metadata.Context)));
        }
        protected override T Edit(Rect region, GUIContent label, T element, InspectorSkipInheritanceAttribute attribute, fiGraphMetadata metadata)
        {
            if (element == null)
            {
                GUI.Label(region, label);
                return(element);
            }

            return(GetEditor(element).Edit(region, label, element, metadata.Enter("InspectorSkipInheritance", metadata.Context)));
        }
Пример #12
0
        public virtual void DrawItem(Rect position, int index)
        {
            // Rotorz seems to sometimes give an index of -1, not sure why.
            if (index < 0)
            {
                return;
            }

            T element = _collectionCache[index];
            T updated = _drawer(position, element, _metadata.Enter(index, _collection));

            // If the modified item is equal to the updated item, then we don't
            // have to replace it in the collection.
            if (EqualityComparer <T> .Default.Equals(element, updated) == false)
            {
                fiLog.Log(GetType(), "Removing old element " + element + " (at index " + index + ") and adding new element " + updated);

                // Removing/adding the item is considered an atomic operation; if
                // any part of it fails then we do not want to modify the
                // collection (ie, if adding the updated element fails in a
                // dictionary because the key already exists).

                bool didRemove = false;
                try {
                    _collection.Remove(element);
                    didRemove = true;
                    _collection.Add(updated);
                }
                catch (Exception) {
                    // Swallow the exception - usually it will be stating that an
                    // existing entry already exists in, say, the dictionary

                    // Treat the entire operation as atomic; undo previous work
                    // if anything failed
                    if (didRemove)
                    {
                        _collection.Add(element);
                    }
                }

                InvalidateCache(/*migrateMetadata:*/ false);
            }
        }
        protected override T Edit(Rect region, GUIContent label, T element, InspectorDisabledAttribute attribute, fiGraphMetadata metadata)
        {
            PropertyEditorChain chain = PropertyEditor.Get(typeof(T), null);

            EditorGUI.BeginDisabledGroup(true);
            element = chain.FirstEditor.Edit(region, label, element, metadata.Enter("InspectorDisabledAttribute"));
            EditorGUI.EndDisabledGroup();

            return(element);
        }
        protected override T Edit(Rect region, GUIContent label, T element, InspectorDisabledIfAttribute attribute, fiGraphMetadata metadata)
        {
            PropertyEditorChain chain = PropertyEditor.Get(typeof(T), null);

            bool disabled = fiReflectionUtility.GetBooleanReflectedMember(typeof(T), element, attribute.ConditionalMemberName, true);

            EditorGUI.BeginDisabledGroup(disabled);
            element = chain.FirstEditor.Edit(region, label, element, metadata.Enter("InspectorDisabledIfAttribute"));
            EditorGUI.EndDisabledGroup();

            return(element);
        }
        public override float GetElementHeight(GUIContent label, SharedInstance <T, TSerializer> element, fiGraphMetadata metadata)
        {
            if (typeof(TActual).IsGenericType == false)
            {
                return(PropertyEditor.Get(typeof(T), null).FirstEditor.GetElementHeight(new GUIContent("Instance"), element.Instance, new fiGraphMetadataChild {
                    Metadata = metadata
                }));
            }

            TryEnsureScript();
            return(EditorChain.GetNextEditor(this).GetElementHeight(label, element, metadata.Enter("ObjectReference", metadata.Context)));
        }
Пример #16
0
        public static float EditPropertyHeightDirect(InspectedProperty property, object propertyValue, fiGraphMetadataChild metadataChild)
        {
            fiGraphMetadata metadata = metadataChild.Metadata;

            var editor = PropertyEditor.Get(property.StorageType, property.MemberInfo).FirstEditor;

            GUIContent propertyLabel = new GUIContent(property.DisplayName);

            // Either the foldout is active or we are not displaying a foldout.
            // Either way, we want to report the full height of the property.
            return(editor.GetElementHeight(propertyLabel, propertyValue, metadata.Enter("EditProperty", metadata.Context)));
        }
        public void OnGUI()
        {
            PropertyEditor.Get(_resources.GetType(), null)
            .FirstEditor
            .EditWithGUILayout(new GUIContent("Resources"), _resources, _metadata.Enter("Resources", null));

            if (GUILayout.Button("Write To Disk"))
            {
                const string outputPath = "Assets/FullInspector2/Modules/EditorImagesManager/Editor/fiEditorImages.cs";
                File.WriteAllText(outputPath, BuildFile(_resources));
                AssetDatabase.Refresh();
            }
        }
        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 override KeyValuePair <TKey, TValue> Edit(Rect region, GUIContent label, KeyValuePair <TKey, TValue> element, fiGraphMetadata metadata)
        {
            Rect keyRect, valueRect;

            SplitRect(region, /*percentage:*/ _widthPercentage, /*margin:*/ 5, out keyRect, out valueRect);

            keyRect.height   = _keyEditor.FirstEditor.GetElementHeight(label, element.Key, metadata.Enter("Key"));
            valueRect.height = _valueEditor.FirstEditor.GetElementHeight(GUIContent.none, element.Value, metadata.Enter("Value"));

            var newKey   = _keyEditor.FirstEditor.Edit(keyRect, label, element.Key, metadata.Enter("Key"));
            var newValue = _valueEditor.FirstEditor.Edit(valueRect, GUIContent.none, element.Value, metadata.Enter("Value"));

            return(new KeyValuePair <TKey, TValue>(newKey, newValue));
        }
Пример #20
0
        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", metadata.Context));
            }

            return(height);
        }
Пример #21
0
        /// <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 + fiLateBindings.EditorGUIUtility.standardVerticalSpacing;
                region.height     -= CategoryToolbarHeight + fiLateBindings.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);
        }
Пример #22
0
        /// <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);
        }
Пример #23
0
        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)));
            }
        }
        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"));
            }

            var abstractTypeMetadata = metadata.GetMetadata <AbstractTypeAnimationMetadata>();

            height = fiEditorGUI.AnimatedHeight(height, abstractTypeMetadata.ChangedTypes, metadata);
            abstractTypeMetadata.ChangedTypes = false;
            return(height);
        }
        private static fiGraphMetadata EnsureInitialState(tkDatabaseContext context, fiGraphMetadata metadata)
        {
            if (context.editedList == null)
            {
                context.editedList = (IList)InspectedType.Get(typeof(TDerived)).CreateInstance();
            }

            InspectorDatabaseEditorMetadata databaseMetadata = metadata.GetMetadata <InspectorDatabaseEditorMetadata>();

            // Set the global metadata to the graph metadata, as the graph
            // metadata is persistent but users still may want to access the
            // global metadata.
            fiGlobalMetadata.Set(context.editedList, databaseMetadata);

            // Disable the dropdown
            metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable();

            TryEnsureValidIndex(context);

            return(metadata.Enter(databaseMetadata.CurrentIndex, context.editedList).Metadata);
        }
        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();
        }
Пример #27
0
        /// <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);
        }
        protected override float GetElementHeight(GUIContent label, T element, InspectorDisabledAttribute attribute, fiGraphMetadata metadata)
        {
            PropertyEditorChain chain = PropertyEditor.Get(typeof(T), null);

            return(chain.FirstEditor.GetElementHeight(label, element, metadata.Enter("InspectorDisabledAttribute")));
        }
        private float GetAddRegionHeight(fiGraphMetadata metadata)
        {
            if (!DisplayAddItemPreview)
            {
                return(0);
            }

            EnsureValidAddItem(ref _addItem);

            int   buttonHeight = (int)ReorderableListGUI.defaultAddButtonStyle.fixedHeight;
            float itemHeight   = _addItemEditor.FirstEditor.GetElementHeight(GUIContent.none, _addItem, metadata.Enter("NextValue"));

            return(Math.Max(buttonHeight, itemHeight));
        }
        public void DoEdit(Rect initialRegion, Rect region, GUIContent label, ref TCollection collection, fiGraphMetadata metadata,
                           IReorderableListAdaptor adaptor)
        {
            Rect bodyRect = new Rect(region);

            bodyRect.height -= GetAddRegionHeightWithMargin(metadata);

            Rect addItemButtonRect, addItemItemRect;

            {
                Rect baseAddItemRect = new Rect(region);
                baseAddItemRect.y     += bodyRect.height + AddRegionMargin;
                baseAddItemRect.height = GetAddRegionHeight(metadata);

                fiRectUtility.SplitLeftHorizontalExact(baseAddItemRect,
                                                       /*leftWidth:*/ ReorderableListGUI.defaultAddButtonStyle.fixedWidth,
                                                       /*margin:*/ 1, out addItemButtonRect, out addItemItemRect);

                // move the margin up
                addItemItemRect.x     += AddRegionBorder;
                addItemItemRect.width -= AddRegionBorder * 2;
                addItemButtonRect.y   -= AddRegionBorder * 2;
                addItemItemRect.y     -= AddRegionBorder;

                if (DisplayAddItemPreview && Event.current.type == EventType.repaint)
                {
                    Rect container = addItemItemRect;
                    container.x      -= AddRegionBorder;
                    container.y      -= AddRegionBorder;
                    container.width  += AddRegionBorder * 2;
                    container.height += AddRegionBorder * 2;
                    ReorderableListGUI.defaultContainerStyle.Draw(container, false, false, false, false);
                }

                addItemButtonRect.height = ReorderableListGUI.defaultAddButtonStyle.fixedHeight;
            }

            // draw the collection elements
            ReorderableListGUI.ListFieldAbsolute(bodyRect, adaptor, DrawEmpty, _listFlags);

            // draw the next key
            metadata.Enter("NextValue").Metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable();

            if (DisplayAddItemPreview)
            {
                var addButtonStyle = ReorderableListGUI.defaultAddButtonStyleFlipped;
                if (adaptor.Count == 0)
                {
                    addButtonStyle = ReorderableListGUI.defaultAddButtonStyleIndependent;
                }

                if (GUI.Button(addItemButtonRect, "", addButtonStyle))
                {
                    AddItemToCollection(_addItem, ref collection, adaptor);
                    GUI.FocusControl(null);
                    _addItem = default(TAddItem);
                }

                EnsureValidAddItem(ref _addItem);
                fiEditorGUI.PushHierarchyMode(false);
                _addItem = _addItemEditor.FirstEditor.Edit(addItemItemRect, GUIContent.none, _addItem,
                                                           metadata.Enter("NextValue"));
                fiEditorGUI.PopHierarchyMode();
            }

            AcceptDragAndDrop(initialRegion, ref collection, adaptor);
        }
Пример #31
0
        /// <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;
        }
Пример #32
0
        /// <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;
        }
Пример #33
0
        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 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;
        }
        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 void OnGUI()
        {
            try {
                EditorGUIUtility.hierarchyMode = true;
                Type updatedType = _inspectedType;

                GUILayout.Label("Static Inspector", EditorStyles.boldLabel);

                {
                    var label      = new GUIContent("Inspected Type");
                    var typeEditor = PropertyEditor.Get(typeof(Type), null);

                    updatedType = typeEditor.FirstEditor.EditWithGUILayout(label, _inspectedType, Metadata.Enter("TypeSelector"));
                }

                fiEditorGUILayout.Splitter(2);

                if (_inspectedType != null)
                {
                    _inspectorScrollPosition = EditorGUILayout.BeginScrollView(_inspectorScrollPosition);

                    var inspectedType = InspectedType.Get(_inspectedType);
                    foreach (InspectedProperty staticProperty in inspectedType.GetProperties(InspectedMemberFilters.StaticInspectableMembers))
                    {
                        var             editorChain = PropertyEditor.Get(staticProperty.StorageType, staticProperty.MemberInfo);
                        IPropertyEditor editor      = editorChain.FirstEditor;

                        GUIContent label        = new GUIContent(staticProperty.Name);
                        object     currentValue = staticProperty.Read(null);

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.GetControlRect(GUILayout.Width(8));
                        EditorGUILayout.BeginVertical();

                        GUI.enabled = staticProperty.CanWrite;
                        object updatedValue = editor.EditWithGUILayout(label, currentValue, Metadata.Enter(staticProperty.Name));
                        if (staticProperty.CanWrite)
                        {
                            staticProperty.Write(null, updatedValue);
                        }

                        EditorGUILayout.EndVertical();
                        EditorGUILayout.EndHorizontal();
                    }

                    EditorGUILayout.EndScrollView();
                }

                // For some reason, the type selection popup window cannot force the rest of the
                // Unity GUI to redraw. We do it here instead -- this removes any delay after
                // selecting the type in the popup window and the type actually being displayed.
                if (fiEditorUtility.ShouldInspectorRedraw.Enabled)
                {
                    Repaint();
                }

                if (_inspectedType != updatedType)
                {
                    _inspectedType = updatedType;
                    Repaint();
                }

                EditorGUIUtility.hierarchyMode = false;
            }
            catch (ExitGUIException) { }
            catch (Exception e) {
                Debug.LogError(e);
            }
        }
Пример #37
0
        /// <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);
        }
Пример #38
0
        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;
        }
Пример #39
0
        /// <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;
        }
Пример #40
0
        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();
            }
        }
Пример #41
0
        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;
                }
            }
        }
Пример #42
0
        public void OnGUI()
        {
            EnsureResources();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            _disablePopups = GUILayout.Toggle(_disablePopups, "Disable Dialog Boxes");
            GUILayout.EndHorizontal();

            GUILayout.Label("<b><size=25>About</size></b> If you've decided to change serializers (for example, from Json.NET to Full Serializer), then this utility will assist your migration.", RichLabel);

            fiEditorGUILayout.Splitter(3);

            IPropertyEditor editor = PropertyEditor.Get(typeof(TypeSpecifier <BaseSerializer>), null).FirstEditor;

            GUILayout.Label("Select the <i>current</i> serializer and then the <i>new</i> serializer", RichLabel);

            fiEditorGUILayout.WithIndent(50, () => {
                WithTemporaryLabelWidth(120, () => {
                    editor.EditWithGUILayout(new GUIContent("Current Serializer"), _currentSerializer, _metadata.Enter(0));
                    editor.EditWithGUILayout(new GUIContent("New Serializer"), _newSerializer, _metadata.Enter(1));
                });
            });

            fiEditorGUILayout.Splitter(3);

            if (_currentSerializer.Type == null || _newSerializer.Type == null)
            {
                return;
            }
            if (_currentSerializer.Type == _newSerializer.Type)
            {
                EditorGUILayout.HelpBox("You cannot migrate to the same serializer", MessageType.Error);
                return;
            }

            _selectedMode = GUILayout.SelectionGrid(_selectedMode, new string[] { "Migrate Active Selection", "Migrate Scene Objects", "Migrate Persistent Objects" }, 3);

            if (_selectedMode == 0)
            {
                GameObject[] toMigrate = DisplaySelection();

                if (GUILayout.Button("Run Migration") && CheckAnnotationsPopup())
                {
                    BeforeMigrate();
                    foreach (var obj in toMigrate)
                    {
                        fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type);
                    }
                    DisplayPostSerializeMessage();
                }
            }

            else if (_selectedMode == 1)
            {
                DisplayScenesGUI();

                if (SceneObjectSelections == null)
                {
                    SceneObjectSelections = new UnityObjectSelectionGroup(fiSerializerMigrationUtility.GetSceneObjects());
                }

                GUILayout.Label("Scene Objects to Process", EditorStyles.boldLabel);
                SceneObjectSelections.OnGUI();

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Run Migration", GUILayout.ExpandWidth(true)) && CheckAnnotationsPopup())
                {
                    BeforeMigrate();
                    foreach (var obj in SceneObjectSelections.Selected)
                    {
                        fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type);
                    }
                    DisplayPostSerializeMessage();
                }
            }

            else if (_selectedMode == 2)
            {
                if (PersistentObjectSelections == null)
                {
                    PersistentObjectSelections = new UnityObjectSelectionGroup(fiSerializerMigrationUtility.GetPersistentObjects());
                }

                GUILayout.Label("Persistent GameObjects to Process", EditorStyles.boldLabel);
                PersistentObjectSelections.OnGUI();

                if (GUILayout.Button("Run Migration", GUILayout.ExpandWidth(true)) && CheckAnnotationsPopup())
                {
                    BeforeMigrate();
                    foreach (var obj in PersistentObjectSelections.Selected)
                    {
                        fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type);
                    }
                    DisplayPostSerializeMessage();
                }
            }
        }
        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;
        }