In Full Inspector, there are typically a large number of property editors that can be used for each type, for example, a user defined editor, then the abstract editor, then the reflected editor. PropertyEditorChain encapsulates this idea and makes it easy to retrieve the next editor that will be used.
Exemplo n.º 1
0
 private static PropertyEditorChain GetCachedEditors(Type propertyType, ICustomAttributeProvider attributes)
 {
     PropertyEditor.CachedType key = new PropertyEditor.CachedType
     {
         EditedType = propertyType,
         EditedAttributes = attributes
     };
     PropertyEditorChain propertyEditorChain;
     if (!PropertyEditor._cachedPropertyEditors.TryGetValue(key, out propertyEditorChain))
     {
         propertyEditorChain = new PropertyEditorChain();
         PropertyEditor._cachedPropertyEditors[key] = propertyEditorChain;
         IPropertyEditor propertyEditor;
         if ((propertyEditor = AttributePropertyEditor.TryCreate(propertyType, attributes)) != null)
         {
             propertyEditorChain.AddEditor(propertyEditor);
         }
         if ((propertyEditor = ArrayPropertyEditor.TryCreate(propertyType)) != null)
         {
             propertyEditorChain.AddEditor(propertyEditor);
         }
         List<IPropertyEditor> list = new List<IPropertyEditor>();
         foreach (Type current in PropertyEditor._editorTypes)
         {
             propertyEditor = PropertyEditorTools.TryCreateEditor(propertyType, current);
             if (propertyEditor != null)
             {
                 list.Add(propertyEditor);
             }
         }
         PropertyEditor.SortByPropertyTypeRelevance(list);
         foreach (IPropertyEditor current2 in list)
         {
             propertyEditorChain.AddEditor(current2);
         }
         if ((propertyEditor = EnumPropertyEditor.TryCreate(propertyType)) != null)
         {
             propertyEditorChain.AddEditor(propertyEditor);
         }
         if ((propertyEditor = NullablePropertyEditor.TryCreate(propertyType)) != null)
         {
             propertyEditorChain.AddEditor(propertyEditor);
         }
         if ((propertyEditor = AbstractTypePropertyEditor.TryCreate(propertyType)) != null)
         {
             propertyEditorChain.AddEditor(propertyEditor);
         }
         if ((propertyEditor = ReflectedPropertyEditor.TryCreate(propertyType)) != null)
         {
             propertyEditorChain.AddEditor(propertyEditor);
         }
     }
     return propertyEditorChain;
 }
Exemplo n.º 2
0
 public bool HasCycle(PropertyEditorChain other)
 {
     if (this._editors.Count != other._editors.Count)
     {
         return false;
     }
     for (int i = 0; i < this._editors.Count; i++)
     {
         if (this._editors[i] != other._editors[i])
         {
             return false;
         }
     }
     return true;
 }
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a set of property editors that can be used to edit the given property type.
        /// </summary>
        private static PropertyEditorChain GetCachedEditors(Type propertyType, ICustomAttributeProvider attributes)
        {
            var cachedType = new CachedType {
                EditedType       = propertyType,
                EditedAttributes = attributes
            };

            PropertyEditorChain chain;

            if (_cachedPropertyEditors.TryGetValue(cachedType, out chain) == false)
            {
                chain = new PropertyEditorChain();
                _cachedPropertyEditors[cachedType] = chain;

                IPropertyEditor editor;

                if ((editor = AttributePropertyEditor.TryCreate(propertyType, attributes)) != null)
                {
                    chain.AddEditor(editor);
                }

                // arrays always need special handling; we don't support overriding them
                if ((editor = ArrayPropertyEditor.TryCreate(propertyType, attributes)) != null)
                {
                    chain.AddEditor(editor);
                }

                // support layout editors above custom editors
                // notably this enables the layout editor to be the highest-priority, ie, above inherited editors
                if ((editor = tkControlPropertyEditor.TryCreate(propertyType, attributes)) != null)
                {
                    chain.AddEditor(editor);
                }

                // user-defined property editors
                var added = new List <IPropertyEditor>();
                foreach (Type editorType in _editorTypes)
                {
                    editor = PropertyEditorTools.TryCreateEditor(propertyType, editorType, attributes, false);
                    if (editor != null)
                    {
                        added.Add(editor);
                    }
                }
                SortByPropertyTypeRelevance(added);
                foreach (IPropertyEditor toAdd in added)
                {
                    chain.AddEditor(toAdd);
                }

                // no user-defined editors so let's try to see if we can integrate a PropertyDrawer
                if (added.Count == 0)
                {
                    if ((editor = fiGenericPropertyDrawerPropertyEditorManager.TryCreate(propertyType)) != null)
                    {
                        chain.AddEditor(editor);
                    }
                }

                // enums come after generic & inherited to allow them to be overridden
                if ((editor = EnumPropertyEditor.TryCreate(propertyType)) != null)
                {
                    chain.AddEditor(editor);
                }

                // try and create an editor for nullable types
                if ((editor = NullablePropertyEditor.TryCreate(propertyType, attributes)) != null)
                {
                    chain.AddEditor(editor);
                }

                // try and create an editor for abstract/interface type
                if ((editor = AbstractTypePropertyEditor.TryCreate(propertyType)) != null)
                {
                    chain.AddEditor(editor);
                }

                // try and create a reflected editor; will only fail for arrays or collections,
                // which should be covered by the array editor
                if ((editor = ReflectedPropertyEditor.TryCreate(propertyType, attributes)) != null)
                {
                    chain.AddEditor(editor);
                }
            }

            return(chain);
        }