コード例 #1
0
 private void DrawProperty(SerializedProperty property, GUIContent label)
 {
     //get toolbox drawer for the property or draw it in the default way
     if (hasToolboxPropertyDrawer && (!hasBuiltInPropertyDrawer || isArray))
     {
         //NOTE: attribute-related drawers have priority over type
         if (hasToolboxPropertyAssignableDrawer)
         {
             //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
     {
         OnGuiDefault(property, label);
     }
 }
コード例 #2
0
        private void DrawProperty()
        {
            //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();
            }
        }
コード例 #3
0
        /// <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]);
                }
            }
        }