コード例 #1
0
        /// <summary>
        /// Returns the custom drawer for the supplied property attribute or null.
        /// <param name="attribute">The property attribute to search for a custom drawer.</param>
        /// <returns>The custom property drawer or null.</returns>
        /// </summary>
        public static NodePropertyDrawer GetDrawer (PropertyAttribute attribute) {
            if (attribute == null)
                return null;

            // The custom drawer dictionary is not loaded?
            if (s_CustomDrawers == null) {
                s_CustomDrawers = new Dictionary<Type, Type>();
                foreach (Type t in EditorTypeUtility.GetDerivedTypes(typeof(NodePropertyDrawer))) {
                    var customDrawerAttr = AttributeUtility.GetAttribute<CustomNodePropertyDrawerAttribute>(t, false);
                    if (customDrawerAttr != null && !s_CustomDrawers.ContainsKey(customDrawerAttr.type))
                        s_CustomDrawers.Add(customDrawerAttr.type, t);
                }
            }

            // Try to get the type of the custom property drawer
            Type drawerType;
            s_CustomDrawers.TryGetValue(attribute.GetType(), out drawerType);
            if (drawerType != null) {
                // Create the drawer
                var drawer = Activator.CreateInstance(drawerType) as NodePropertyDrawer;
                if (drawer != null) {
                    // Set the attribute and return the drawer
                    drawer.attribute = attribute;
                    return drawer;
                }
            }

            return null;
        }
コード例 #2
0
 public void HandleAttribute(PropertyAttribute attribute, System.Reflection.FieldInfo field, System.Type propertyType)
 {
   if (attribute is TooltipAttribute)
     this.tooltip = (attribute as TooltipAttribute).tooltip;
   else if (attribute is ContextMenuItemAttribute)
   {
     if (propertyType.IsArrayOrList())
       return;
     if (this.contextMenuItems == null)
       this.contextMenuItems = new List<ContextMenuItemAttribute>();
     this.contextMenuItems.Add(attribute as ContextMenuItemAttribute);
   }
   else
     this.HandleDrawnType(attribute.GetType(), propertyType, field, attribute);
 }
 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;
             modifier.Init(false);
             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);
     }
 }
コード例 #4
0
		public void HandleAttribute(PropertyAttribute attribute, FieldInfo field, Type propertyType)
		{
			if (attribute is TooltipAttribute)
			{
				this.tooltip = (attribute as TooltipAttribute).tooltip;
				return;
			}
			if (!(attribute is ContextMenuItemAttribute))
			{
				this.HandleDrawnType(attribute.GetType(), propertyType, field, attribute);
				return;
			}
			if (propertyType.IsArrayOrList())
			{
				return;
			}
			if (this.contextMenuItems == null)
			{
				this.contextMenuItems = new List<ContextMenuItemAttribute>();
			}
			this.contextMenuItems.Add(attribute as ContextMenuItemAttribute);
		}
 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;
             modifier.Init(false);
             if (_modifiers == null) _modifiers = new List<PropertyModifier>();
             _modifiers.Add(modifier);
         }
     }
     else
     {
         base.HandleAttribute(attribute, field, propertyType);
         var drawer = this.InternalDrawer;
         if (_drawer == null)
         {
             //no drawer has been set before... lets see if we got one
             if (drawer != null)
             {
                 //we got a new drawer, set it
                 if (field.FieldType.IsListType()) drawer = new ArrayPropertyDrawer(drawer);
                 _drawer = drawer;
             }
         }
         else if (drawer != _drawer)
         {
             //a new drawer was created, lets see what we need to do with it compared to the last one
             if (drawer is PropertyModifier)
             {
                 if (_modifiers == null) _modifiers = new List<PropertyModifier>();
                 _modifiers.Add(drawer as PropertyModifier);
                 this.InternalDrawer = _drawer;
             }
             else if (drawer is IArrayHandlingPropertyDrawer)
             {
                 //got an array drawer, this overrides previous drivers
                 if (_drawer is IArrayHandlingPropertyDrawer)
                 {
                     var temp = _drawer as IArrayHandlingPropertyDrawer;
                     _drawer = drawer;
                     (_drawer as IArrayHandlingPropertyDrawer).InternalDrawer = temp.InternalDrawer;
                 }
                 else if (_drawer != null)
                 {
                     var temp = _drawer;
                     _drawer = drawer;
                     (_drawer as IArrayHandlingPropertyDrawer).InternalDrawer = temp;
                 }
                 else
                 {
                     _drawer = drawer;
                 }
             }
             else if (_drawer is IArrayHandlingPropertyDrawer)
             {
                 //got an internal drawer for the existing array drawer
                 (_drawer as IArrayHandlingPropertyDrawer).InternalDrawer = drawer;
                 this.InternalDrawer = _drawer;
             }
             else
             {
                 //we got a new drawer, set it
                 if (field.FieldType.IsListType())
                 {
                     _drawer = new ArrayPropertyDrawer(drawer);
                     this.InternalDrawer = _drawer;
                 }
                 else
                 {
                     _drawer = drawer;
                 }
             }
         }
     }
 }