Base class to derive custom decorator drawers from.

Inheritance: GUIDrawer
示例#1
0
        public void HandleDrawnType(Type drawnType, Type propertyType, FieldInfo field, PropertyAttribute attribute)
        {
            Type drawerTypeForType = ScriptAttributeUtility.GetDrawerTypeForType(drawnType);

            if (drawerTypeForType != null)
            {
                if (typeof(PropertyDrawer).IsAssignableFrom(drawerTypeForType))
                {
                    if (propertyType != null && propertyType.IsArrayOrList())
                    {
                        return;
                    }
                    this.m_PropertyDrawer             = (PropertyDrawer)Activator.CreateInstance(drawerTypeForType);
                    this.m_PropertyDrawer.m_FieldInfo = field;
                    this.m_PropertyDrawer.m_Attribute = attribute;
                }
                else if (typeof(DecoratorDrawer).IsAssignableFrom(drawerTypeForType))
                {
                    if (field != null && field.FieldType.IsArrayOrList() && !propertyType.IsArrayOrList())
                    {
                        return;
                    }
                    DecoratorDrawer decoratorDrawer = (DecoratorDrawer)Activator.CreateInstance(drawerTypeForType);
                    decoratorDrawer.m_Attribute = attribute;
                    if (this.m_DecoratorDrawers == null)
                    {
                        this.m_DecoratorDrawers = new List <DecoratorDrawer>();
                    }
                    this.m_DecoratorDrawers.Add(decoratorDrawer);
                }
            }
        }
示例#2
0
        public void HandleDrawnType(SerializedProperty property, Type drawnType, Type propertyType, FieldInfo field, PropertyAttribute attribute)
        {
            Type drawerType = ScriptAttributeUtility.GetDrawerTypeForPropertyAndType(property, drawnType);

            // If we found a drawer type, instantiate the drawer, cache it, and return it.
            if (drawerType != null)
            {
                if (typeof(PropertyDrawer).IsAssignableFrom(drawerType))
                {
                    // Use PropertyDrawer on array elements, not on array itself.
                    // If there's a PropertyAttribute on an array, we want to apply it to the individual array elements instead.
                    // This is the only convenient way we can let the user apply PropertyDrawer attributes to elements inside an array.
                    if (propertyType != null && propertyType.IsArrayOrList())
                    {
                        return;
                    }

                    var propertyDrawerForType = (PropertyDrawer)System.Activator.CreateInstance(drawerType);
                    propertyDrawerForType.m_FieldInfo = field;

                    // Will be null by design if default type drawer!
                    propertyDrawerForType.m_Attribute = attribute;

                    if (m_PropertyDrawers == null)
                    {
                        m_PropertyDrawers = new List <PropertyDrawer>();
                    }
                    m_PropertyDrawers.Add(propertyDrawerForType);
                }
                else if (typeof(DecoratorDrawer).IsAssignableFrom(drawerType))
                {
                    // Draw decorators on array itself, not on each array elements
                    if (field != null && field.FieldType.IsArrayOrList() && !propertyType.IsArrayOrList())
                    {
                        return;
                    }

                    DecoratorDrawer decoratorDrawerForType = (DecoratorDrawer)System.Activator.CreateInstance(drawerType);
                    decoratorDrawerForType.m_Attribute = attribute;

                    if (m_DecoratorDrawers == null)
                    {
                        m_DecoratorDrawers = new List <DecoratorDrawer>();
                    }
                    m_DecoratorDrawers.Add(decoratorDrawerForType);
                }
            }
        }
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num1 = 0.0f;

            if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
            {
                using (List <DecoratorDrawer> .Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        DecoratorDrawer current = enumerator.Current;
                        num1 += current.GetHeight();
                    }
                }
            }
            float num2;

            if (this.propertyDrawer != null)
            {
                num2 = num1 + this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
            }
            else if (!includeChildren)
            {
                num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
            }
            else
            {
                property = property.Copy();
                SerializedProperty endProperty = property.GetEndProperty();
                num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
                bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
                {
                    float num3 = num2 + ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
                    enterChildren = false;
                    num2          = num3 + 2f;
                }
            }
            return(num2);
        }
示例#4
0
        public void HandleDrawnType(Type drawnType, Type propertyType, FieldInfo field, PropertyAttribute attribute)
        {
            Type drawerType = ScriptAttributeUtility.GetDrawerTypeForType(drawnType);

            // If we found a drawer type, instantiate the drawer, cache it, and return it.
            if (drawerType != null)
            {
                if (typeof(PropertyDrawer).IsAssignableFrom(drawerType))
                {
                    // HACK: Here is different from the U3D setting, maybe is not a good idea!
                    // Unity only want use PropertyDrawer on array elements, not on array itself,
                    // But i don't like this setting, so i recode it.
                    propertyDrawer = (PropertyDrawer)Activator.CreateInstance(drawerType);
                    propertyDrawer.SetFieldInfo(field);

                    // Will be null by design if default type drawer!
                    propertyDrawer.SetAttribute(attribute);
                }
                else if (typeof(UnityEditor.DecoratorDrawer).IsAssignableFrom(drawerType))
                {
                    // Draw decorators on array itself, not on each array elements
                    if (field != null && field.FieldType.IsArrayOrList() && !propertyType.IsArrayOrList())
                    {
                        return;
                    }
                    UnityEditor.DecoratorDrawer decoratorDrawer = (UnityEditor.DecoratorDrawer)System.Activator.CreateInstance(drawerType);
                    DecoratorDrawerHelper.SetAttribute(decoratorDrawer, attribute);

                    if (DecoratorDrawers == null)
                    {
                        DecoratorDrawers = new List <UnityEditor.DecoratorDrawer>();
                    }
                    DecoratorDrawers.Add(decoratorDrawer);
                }
            }
        }
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float height = position.height;

            position.height = 0.0f;
            if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
            {
                using (List <DecoratorDrawer> .Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        DecoratorDrawer current = enumerator.Current;
                        position.height = current.GetHeight();
                        float labelWidth = EditorGUIUtility.labelWidth;
                        float fieldWidth = EditorGUIUtility.fieldWidth;
                        current.OnGUI(position);
                        EditorGUIUtility.labelWidth = labelWidth;
                        EditorGUIUtility.fieldWidth = fieldWidth;
                        position.y += position.height;
                        height     -= position.height;
                    }
                }
            }
            position.height = height;
            if (this.propertyDrawer != null)
            {
                float labelWidth = EditorGUIUtility.labelWidth;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                this.propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
                EditorGUIUtility.labelWidth = labelWidth;
                EditorGUIUtility.fieldWidth = fieldWidth;
                return(false);
            }
            if (!includeChildren)
            {
                return(EditorGUI.DefaultPropertyField(position, property, label));
            }
            Vector2            iconSize           = EditorGUIUtility.GetIconSize();
            bool               enabled            = GUI.enabled;
            int                indentLevel        = EditorGUI.indentLevel;
            int                num                = indentLevel - property.depth;
            SerializedProperty serializedProperty = property.Copy();
            SerializedProperty endProperty        = serializedProperty.GetEndProperty();

            position.height       = EditorGUI.GetSinglePropertyHeight(serializedProperty, label);
            EditorGUI.indentLevel = serializedProperty.depth + num;
            bool enterChildren = EditorGUI.DefaultPropertyField(position, serializedProperty, label) && EditorGUI.HasVisibleChildFields(serializedProperty);

            position.y += position.height + 2f;
            while (serializedProperty.NextVisible(enterChildren) && !SerializedProperty.EqualContents(serializedProperty, endProperty))
            {
                EditorGUI.indentLevel = serializedProperty.depth + num;
                position.height       = EditorGUI.GetPropertyHeight(serializedProperty, (GUIContent)null, false);
                EditorGUI.BeginChangeCheck();
                enterChildren = ScriptAttributeUtility.GetHandler(serializedProperty).OnGUI(position, serializedProperty, (GUIContent)null, false) && EditorGUI.HasVisibleChildFields(serializedProperty);
                if (!EditorGUI.EndChangeCheck())
                {
                    position.y += position.height + 2f;
                }
                else
                {
                    break;
                }
            }
            GUI.enabled = enabled;
            EditorGUIUtility.SetIconSize(iconSize);
            EditorGUI.indentLevel = indentLevel;
            return(false);
        }