/// <summary>
        /// Extract Property and Decorator drawers for property
        /// </summary>
        public void HandleDrawnType(Type drawnType, Type propertyType, FieldInfo field, PropertyAttribute attribute)
        {
            Type drawerTypeForType = StratusScriptAttributeUtility.GetDrawerTypeForType(drawnType);

            if (drawerTypeForType != null)
            {
                if (typeof(PropertyDrawer).IsAssignableFrom(drawerTypeForType))
                {
                    if (propertyType != null && propertyType.IsArrayOrList())
                    {
                        return;
                    }
                    propertyDrawer = (PropertyDrawer)Activator.CreateInstance(drawerTypeForType);

                    propertyDrawer.SetFieldInfo(field);
                    propertyDrawer.SetAttribute(attribute);
                }
                else if (typeof(DecoratorDrawer).IsAssignableFrom(drawerTypeForType))
                {
                    if (field != null && field.FieldType.IsArrayOrList() && !propertyType.IsArrayOrList())
                    {
                        return;
                    }
                    DecoratorDrawer decoratorDrawer = (DecoratorDrawer)Activator.CreateInstance(drawerTypeForType);

                    decoratorDrawer.SetAttribute(attribute);
                    if (decoratorDrawers == null)
                    {
                        decoratorDrawers = new List <DecoratorDrawer>();
                    }
                    decoratorDrawers.Add(decoratorDrawer);
                }
            }
        }
예제 #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);
         }
     }
 }
예제 #3
0
		private void Setup(PropertyAttribute attribute, [NotNull]Type decoratorDrawerType, [CanBeNull]DecoratorDrawer decoratorDrawerInstance, [CanBeNull]IParentDrawer setParent)
		{
			if(decoratorDrawerInstance == null)
			{
				decoratorDrawerInstance = decoratorDrawerType.CreateInstance() as DecoratorDrawer;
			}

			decoratorDrawer = decoratorDrawerInstance;
			
			var attField = decoratorDrawerType.GetField("m_Attribute", BindingFlags.Instance | BindingFlags.NonPublic);
			if(attField == null)
			{
				Debug.LogError("Failed to get field \"m_Attribute\" from DecoratorDrawer of type "+StringUtils.ToString(decoratorDrawerType));
			}
			else
			{
				attField.SetValue(decoratorDrawer, attribute);
			}
			
			base.Setup(setParent, GUIContent.none);
		}
    public static object GetPropertyHandler(DecoratorDrawer decoratorDrawer)
    {
        var propertyHandlerCache      = propertyHandlerCacheInfo.GetValue(null, null);
        var propertyHandlerDictionary = (IDictionary)propertyHandlersInfo.GetValue(propertyHandlerCache);
        var propertyHandlers          = propertyHandlerDictionary.Values;

        foreach (var propertyHandler in propertyHandlers)
        {
            var decoratorDrawers = (List <DecoratorDrawer>)decoratorDrawersInfo.GetValue(propertyHandler);
            if (decoratorDrawers == null)
            {
                continue;
            }

            var index = decoratorDrawers.IndexOf(decoratorDrawer);
            if (index < 0)
            {
                continue;
            }

            return(propertyHandler);
        }
        return(null);
    }
예제 #5
0
 public static void SetAttribute(this DecoratorDrawer drawer, PropertyAttribute attrib)
 {
     StratusReflection.SetField("m_Attribute", typeof(DecoratorDrawer), attrib, false, drawer);
 }