protected virtual void Init(PropertyAttribute[] attribs)
        {
            var fieldType = _fieldInfo.FieldType;

            if (fieldType.IsListType())
            {
                fieldType = fieldType.GetElementTypeOfListType();
            }

            var fieldTypePropertyDrawerType = ScriptAttributeUtility.GetDrawerTypeForType(fieldType);

            if (fieldTypePropertyDrawerType != null && TypeUtil.IsType(fieldTypePropertyDrawerType, typeof(PropertyDrawer)))
            {
                _drawer = PropertyDrawerActivator.Create(fieldTypePropertyDrawerType, null, _fieldInfo);
                if (_drawer != null && _fieldInfo.FieldType.IsListType())
                {
                    _drawer = new ArrayPropertyDrawer(_drawer);
                }
                this.InternalDrawer = _drawer;
            }


            foreach (var attrib in attribs)
            {
                this.HandleAttribute(attrib, _fieldInfo, fieldType);
            }
        }
Exemplo n.º 2
0
 protected override void HandleAttribute(PropertyAttribute attribute, System.Reflection.FieldInfo field, System.Type propertyType)
 {
     if (attribute is PropertyModifierAttribute)
     {
         var mtp = ScriptAttributeUtility.GetDrawerTypeForType(attribute.GetType());
         if (TypeUtil.IsType(mtp, typeof(PropertyModifier)))
         {
             var modifier = PropertyDrawerActivator.Create(mtp, attribute, field) as PropertyModifier;
             if (_modifiers == null)
             {
                 _modifiers = new List <PropertyModifier>();
             }
             _modifiers.Add(modifier);
         }
     }
     else if (attribute is DisplayNameAttribute)
     {
         var dattrib = attribute as DisplayNameAttribute;
         _customDisplayName = dattrib.DisplayName;
         if (dattrib.tooltip != null)
         {
             _customTooltip = dattrib.tooltip;
             base.HandleAttribute(attribute, field, propertyType);
         }
     }
     else if (attribute is TooltipAttribute)
     {
         _customTooltip = (attribute as TooltipAttribute).tooltip;
         base.HandleAttribute(attribute, field, propertyType);
     }
     else if (attribute is ContextMenuItemAttribute)
     {
         base.HandleAttribute(attribute, field, propertyType);
     }
     else
     {
         var drawerTypeForType = ScriptAttributeUtility.GetDrawerTypeForType(attribute.GetType());
         if (drawerTypeForType == null)
         {
             return;
         }
         else if (typeof(PropertyDrawer).IsAssignableFrom(drawerTypeForType))
         {
             base.HandleAttribute(attribute, field, propertyType);
             var drawer = this.InternalDrawer; //this retrieves the drawer that was selected by called 'base.HandleAttribute'
             this.AppendDrawer(drawer);
         }
         else if (typeof(DecoratorDrawer).IsAssignableFrom(drawerTypeForType))
         {
             DecoratorDrawer instance = (DecoratorDrawer)System.Activator.CreateInstance(drawerTypeForType);
             com.spacepuppy.Dynamic.DynamicUtil.SetValue(instance, "m_Attribute", attribute);
             if (this.DecoratorDrawers == null)
             {
                 this.DecoratorDrawers = new List <DecoratorDrawer>();
             }
             this.DecoratorDrawers.Add(instance);
         }
     }
 }
        private void Init()
        {
            var dtp    = ScriptAttributeUtility.GetDrawerTypeForType(_attrib.GetType());
            var drawer = PropertyDrawerActivator.Create(dtp, _attrib, _fieldInfo);

            if (drawer is PropertyModifier)
            {
                (drawer as PropertyModifier).Init(true);
            }
            _visibleDrawer = drawer;
        }
Exemplo n.º 4
0
        protected virtual void Init(PropertyAttribute[] attribs)
        {
            var fieldType = _fieldInfo.FieldType;

            if (fieldType.IsListType())
            {
                fieldType = fieldType.GetElementTypeOfListType();
            }

            var fieldTypePropertyDrawerType = ScriptAttributeUtility.GetDrawerTypeForType(fieldType);

            if (fieldTypePropertyDrawerType != null && TypeUtil.IsType(fieldTypePropertyDrawerType, typeof(PropertyDrawer)))
            {
                _drawer = PropertyDrawerActivator.Create(fieldTypePropertyDrawerType, null, _fieldInfo);
                if (_drawer != null && _propertyIsArray)
                {
                    _drawer = new ArrayPropertyDrawer(_drawer);
                }
                this.InternalDrawer = _drawer;
            }

            if (attribs != null)
            {
                foreach (var attrib in attribs)
                {
                    this.HandleAttribute(attrib, _fieldInfo, fieldType);
                }
            }

            if (_drawer == null)
            {
                if (_modifiers != null && _modifiers.Count > 0)
                {
                    var modifier = _modifiers.Last();
                    modifier.IsDrawer = true;
                    _drawer           = modifier;
                    if (_propertyIsArray)
                    {
                        _drawer = new ArrayPropertyDrawer(_drawer);
                    }
                    this.InternalDrawer = _drawer;
                }
                else
                {
                    _drawer = DefaultPropertyDrawer.SharedInstance;
                    if (_drawer != null && _propertyIsArray)
                    {
                        _drawer = new ArrayPropertyDrawer(_drawer);
                    }
                    this.InternalDrawer = _drawer;
                }
            }
        }
Exemplo n.º 5
0
        private PropertyDrawer GetDrawer(SerializedProperty property)
        {
            if (property.propertyType == SerializedPropertyType.Generic || property.propertyType == SerializedPropertyType.ObjectReference)
            {
                var fieldInfo = ScriptAttributeUtility.GetFieldInfoFromProperty(property);
                if (fieldInfo == null)
                {
                    return(null);
                }

                var tp = fieldInfo.FieldType;
                if (tp.IsListType())
                {
                    tp = tp.GetElementTypeOfListType();
                }

                PropertyDrawer drawer = null;
                if (_fieldTypeToDrawer.TryGetValue(tp, out drawer))
                {
                    if (drawer != null)
                    {
                        PropertyDrawerActivator.InitializePropertyDrawer(drawer, null, fieldInfo);
                    }
                    return(drawer);
                }

                var drawerType = ScriptAttributeUtility.GetDrawerTypeForType(tp);
                if (drawerType == null)
                {
                    _fieldTypeToDrawer[tp] = null;
                    return(null);
                }

                drawer = PropertyDrawerActivator.Create(drawerType, null, fieldInfo);
                _fieldTypeToDrawer[tp] = drawer;
                return(drawer);
            }

            return(null);
        }
        private PropertyDrawer GetDrawer(SerializedProperty property)
        {
            if (property.propertyType == SerializedPropertyType.Generic || property.propertyType == SerializedPropertyType.ObjectReference)
            {
                var fieldInfo = ScriptAttributeUtility.GetFieldInfoFromProperty(property);
                if (fieldInfo == null)
                {
                    return(null);
                }

                var tp = fieldInfo.FieldType;
                if (tp.IsListType())
                {
                    tp = tp.GetElementTypeOfListType();
                }
                if (_fieldTypeToDrawer.ContainsKey(tp))
                {
                    var result = _fieldTypeToDrawer[tp];
                    if (result != null)
                    {
                        PropertyDrawerActivator.InitializePropertyDrawer(result, null, fieldInfo);
                    }
                    return(result);
                }

                var drawerType = ScriptAttributeUtility.GetDrawerTypeForType(tp);
                if (drawerType == null)
                {
                    _fieldTypeToDrawer.Add(tp, null);
                    return(null);
                }

                var drawer = PropertyDrawerActivator.Create(drawerType, null, fieldInfo);
                _fieldTypeToDrawer.Add(tp, drawer);
                return(drawer);
            }

            return(null);
        }
Exemplo n.º 7
0
 protected override void HandleAttribute(PropertyAttribute attribute, System.Reflection.FieldInfo field, System.Type propertyType)
 {
     if (attribute is PropertyModifierAttribute)
     {
         var mtp = ScriptAttributeUtility.GetDrawerTypeForType(attribute.GetType());
         if (TypeUtil.IsType(mtp, typeof(PropertyModifier)))
         {
             var modifier = PropertyDrawerActivator.Create(mtp, attribute, field) as PropertyModifier;
             if (_modifiers == null)
             {
                 _modifiers = new List <PropertyModifier>();
             }
             _modifiers.Add(modifier);
         }
     }
     else
     {
         base.HandleAttribute(attribute, field, propertyType);
         var drawer = this.InternalDrawer; //this retrieves the drawer that was selected by called 'base.HandleAttribute'
         this.AppendDrawer(drawer);
     }
 }