Exemple #1
0
        private static void PropertyField_Implementation(Rect rect, SerializedProperty property, bool includeChildren, PropertyFieldFunction propertyFieldFunction)
        {
            SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute <SpecialCaseDrawerAttribute>(property);

            if (specialCaseAttribute != null)
            {
                specialCaseAttribute.GetDrawer().OnGUI(rect, property);
            }
            else
            {
                // Check if visible
                bool visible = PropertyUtility.IsVisible(property);
                if (!visible)
                {
                    return;
                }

                // Validate
                ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes <ValidatorAttribute>(property);
                foreach (var validatorAttribute in validatorAttributes)
                {
                    validatorAttribute.GetValidator().ValidateProperty(property);
                }

                // Check if enabled and draw
                EditorGUI.BeginChangeCheck();
                bool enabled = PropertyUtility.IsEnabled(property);

                using (new EditorGUI.DisabledScope(disabled: !enabled))
                {
                    propertyFieldFunction.Invoke(rect, property, PropertyUtility.GetLabel(property), includeChildren);
                }

                // Call OnValueChanged callbacks
                if (EditorGUI.EndChangeCheck())
                {
                    PropertyUtility.CallOnValueChangedCallbacks(property);
                }
            }
        }
Exemple #2
0
        private static void PropertyField_Implementation(Rect rect, SerializedProperty property, bool includeChildren, PropertyFieldFunction propertyFieldFunction)
        {
            SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute <SpecialCaseDrawerAttribute>(property);

            if (specialCaseAttribute != null)
            {
                specialCaseAttribute.GetDrawer().OnGUI(rect, property);
            }
            else
            {
                GUIContent label = new GUIContent(PropertyUtility.GetLabel(property));
                bool       anyDrawerAttribute = PropertyUtility.GetAttributes <DrawerAttribute>(property).Any();

                if (!anyDrawerAttribute)
                {
                    // Drawer attributes check for visibility, enableability and validator themselves,
                    // so if a property doesn't have a DrawerAttribute we need to check for these explicitly

                    // Check if visible
                    bool visible = PropertyUtility.IsVisible(property);
                    if (!visible)
                    {
                        return;
                    }

                    // Validate
                    ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes <ValidatorAttribute>(property);
                    foreach (var validatorAttribute in validatorAttributes)
                    {
                        validatorAttribute.GetValidator().ValidateProperty(property);
                    }

                    // Check if enabled and draw
                    EditorGUI.BeginChangeCheck();
                    bool enabled = PropertyUtility.IsEnabled(property);

                    using (new EditorGUI.DisabledScope(disabled: !enabled))
                    {
                        propertyFieldFunction.Invoke(rect, property, label, includeChildren);
                    }

                    // Call OnValueChanged callbacks
                    if (EditorGUI.EndChangeCheck())
                    {
                        PropertyUtility.CallOnValueChangedCallbacks(property);
                    }
                }
                else
                {
                    // We don't need to check for enableIfAttribute
                    propertyFieldFunction.Invoke(rect, property, label, includeChildren);
                }
            }
        }
Exemple #3
0
        private static bool PropertyField_Implementation(Rect rect, NaughtyProperty naughtyProperty, bool includeChildren, PropertyFieldFunction propertyFieldFunction)
        {
            bool changeDetected = false;

            if (naughtyProperty.specialCaseDrawerAttribute != null)
            {
                return(naughtyProperty.specialCaseDrawerAttribute.GetDrawer().OnGUI(rect, naughtyProperty));
            }
            else
            {
                // Check if visible
                if (!naughtyProperty.cachedIsVisible)
                {
                    return(false);
                }

                // Validate
                foreach (var validatorAttribute in naughtyProperty.validatorAttributes)
                {
                    validatorAttribute.GetValidator().ValidateProperty(naughtyProperty.serializedProperty);
                }

                // Check if enabled and draw
                EditorGUI.BeginChangeCheck();
                bool enabled = naughtyProperty.cachedIsEnabled;

                using (new EditorGUI.DisabledScope(disabled: !enabled))
                {
                    propertyFieldFunction.Invoke(rect, naughtyProperty, PropertyUtility.GetLabel(naughtyProperty.labelAttribute, naughtyProperty.serializedProperty), includeChildren);
                }

                // Call OnValueChanged callbacks
                if (EditorGUI.EndChangeCheck())
                {
                    changeDetected = true;
                    PropertyUtility.CallOnValueChangedCallbacks(naughtyProperty.serializedProperty);
                }
            }

            return(changeDetected);
        }