Exemple #1
0
        public void SetAllPossibleSelfPropertyDrawers()
        {
            selfPropertyDrawerHandlers?.Clear();

            var types = ToolboxDrawerModule.GetAllPossibleSelfPropertyDrawers();

            for (var i = 0; i < types.Count; i++)
            {
                AddSelfPropertyDrawerHandler(new SerializedType(types[i]));
            }
        }
        public void SetAllPossibleTargetTypeDrawers()
        {
            targetTypeDrawerHandlers?.Clear();

            var types = ToolboxDrawerModule.GetAllPossibleTargetTypeDrawers();

            for (var i = 0; i < types.Count; i++)
            {
                targetTypeDrawerHandlers.Add(new SerializedType(types[i]));
            }
        }
Exemple #3
0
        private PropertyCondition Validate()
        {
            var conditionState = PropertyCondition.Valid;

            if (!hasToolboxConditionDrawer)
            {
                return(conditionState);
            }

            return(ToolboxDrawerModule.GetConditionDrawer(conditionAttribute)?.OnGuiValidate(property, conditionAttribute) ?? conditionState);
        }
Exemple #4
0
        private void CloseDecoratorDrawers()
        {
            if (!hasToolboxDecoratorDrawer)
            {
                return;
            }

            for (var i = decoratorAttributes.Count - 1; i >= 0; i--)
            {
                ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiClose(decoratorAttributes[i]);
            }
        }
Exemple #5
0
        private void BeginDecoratorDrawers()
        {
            if (!hasToolboxDecoratorDrawer)
            {
                return;
            }

            for (var i = 0; i < decoratorAttributes.Count; i++)
            {
                ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiBegin(decoratorAttributes[i]);
            }
        }
Exemple #6
0
 private void ProcessBuiltInData()
 {
     //check if this property has built-in property drawer
     if (!(hasBuiltInPropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(type)))
     {
         var propertyAttributes = fieldInfo.GetCustomAttributes <PropertyAttribute>();
         foreach (var attribute in propertyAttributes)
         {
             var attributeType = attribute.GetType();
             if (hasBuiltInPropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(attributeType))
             {
                 break;
             }
         }
     }
 }
        /// <summary>
        /// Constructor prepares all property-related data for custom drawing.
        /// </summary>
        /// <param name="property"></param>
        public ToolboxPropertyHandler(SerializedProperty property)
        {
            this.property = property;

            //here starts preparation of all needed data for this handler
            //first of all we have to retrieve the native data like FieldInfo, custom native drawer, etc.
            //after this we have to retrieve (if possible) all Toolbox-related data - ToolboxAttributes

            //set basic content for the handled property
            label = new GUIContent(property.displayName);

            //get FieldInfo associated to this property, it is needed to cache custom attributes
            if ((fieldInfo = property.GetFieldInfo(out type)) == null)
            {
                return;
            }

            isArray = property.isArray && property.propertyType == SerializedPropertyType.Generic;

            //check if this property has built-in property drawer
            if (!(hasNativePropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(type)))
            {
                var propertyAttributes = fieldInfo.GetCustomAttributes <PropertyAttribute>();
                foreach (var attribute in propertyAttributes)
                {
                    var attributeType = attribute.GetType();
                    if (hasNativePropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(attributeType))
                    {
                        break;
                    }
                }
            }

            if (isArray)
            {
                //get collection drawer associated to this array
                propertyAttribute = fieldInfo.GetCustomAttribute <ToolboxListPropertyAttribute>();
            }
            else
            {
                //get property drawer associated to this field
                propertyAttribute = fieldInfo.GetCustomAttribute <ToolboxSelfPropertyAttribute>();
            }

            //check if property has a custom attribute drawer
            hasToolboxPropertyAttributeDrawer = propertyAttribute != null;
            //check if property has a custom target type drawer
            hasToolboxPropertyTargetTypeDrawer = ToolboxDrawerModule.HasTargetTypeDrawer(type);

            hasToolboxPropertyDrawer = hasToolboxPropertyAttributeDrawer || hasToolboxPropertyTargetTypeDrawer;

            //validate child property using the associated FieldInfo
            if (isChild = (property.name != fieldInfo.Name))
            {
                return;
            }

            //get only one condition attribute to valdiate state of this property
            conditionAttribute        = fieldInfo.GetCustomAttribute <ToolboxConditionAttribute>();
            hasToolboxConditionDrawer = conditionAttribute != null;

            //get all available decorator attributes
            decoratorAttributes       = fieldInfo.GetCustomAttributes <ToolboxDecoratorAttribute>().ToArray();
            hasToolboxDecoratorDrawer = decoratorAttributes != null && decoratorAttributes.Length > 0;
            //keep decorator attributes in the order
            Array.Sort(decoratorAttributes, (a1, a2) => a1.Order.CompareTo(a2.Order));
        }
        /// <summary>
        /// Draw property using built-in layout system and cached <see cref="ToolboxAttributeDrawer"/>s.
        /// </summary>
        public void OnGuiLayout()
        {
            //depending on previously gained data we can provide more action
            //using custom attributes and information about native drawers
            //we can use associated ToolboxDrawers or/and draw property in the default way

            //begin all needed decorator drawers in the proper order
            if (hasToolboxDecoratorDrawer)
            {
                for (var i = 0; i < decoratorAttributes.Length; i++)
                {
                    ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiBegin(decoratorAttributes[i]);
                }
            }

            //handle condition attribute(only one allowed)
            var conditionState = PropertyCondition.Valid;

            if (hasToolboxConditionDrawer)
            {
                conditionState = ToolboxDrawerModule.GetConditionDrawer(conditionAttribute)?.OnGuiValidate(property, conditionAttribute) ?? conditionState;
            }

            if (conditionState == PropertyCondition.NonValid)
            {
                goto Finish;
            }

            //disable property field if it is needed
            if (conditionState == PropertyCondition.Disabled)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            //get toolbox drawer for the property or draw it in the default way
            if (hasToolboxPropertyDrawer && (!hasNativePropertyDrawer || isArray))
            {
                //NOTE: attribute-related drawers have priority
                if (hasToolboxPropertyAttributeDrawer)
                {
                    //draw target property using the associated attribute
                    var propertyDrawer = isArray
                        ? ToolboxDrawerModule.GetListPropertyDrawer(propertyAttribute.GetType())
                        : ToolboxDrawerModule.GetSelfPropertyDrawer(propertyAttribute.GetType());
                    propertyDrawer?.OnGui(property, label, propertyAttribute);
                }
                else
                {
                    //draw target property using the associated type drawer
                    ToolboxDrawerModule.GetTargetTypeDrawer(type)?.OnGui(property, label);
                }
            }
            else
            {
                if (hasToolboxPropertyDrawer)
                {
                    //TODO: warning
                    //NOTE: since property has a custom drawer it will override any Toolbox-related one
                }

                OnGuiDefault();
            }

            //end disabled state check
            if (conditionState == PropertyCondition.Disabled)
            {
                EditorGUI.EndDisabledGroup();
            }

Finish:
            //end all needed decorator drawers in the proper order
            if (hasToolboxDecoratorDrawer)
            {
                for (var i = decoratorAttributes.Length - 1; i >= 0; i--)
                {
                    ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiEnd(decoratorAttributes[i]);
                }
            }
        }
 private static void ManageInspectorCore(IToolboxInspectorSettings settings)
 {
     //setup all available drawers using the internal module
     ToolboxDrawerModule.UpdateDrawers(settings);
 }