Пример #1
0
        public static bool IsEnabled(SerializedProperty property)
        {
            EnableIfAttributeBase enableIfAttribute = GetAttribute <EnableIfAttributeBase>(property);

            if (enableIfAttribute == null)
            {
                return(true);
            }

            object target = GetTargetObjectWithProperty(property);

            List <bool> conditionValues = GetConditionValues(target, enableIfAttribute.Conditions);

            if (conditionValues.Count > 0)
            {
                bool enabled = GetConditionsFlag(conditionValues, enableIfAttribute.ConditionOperator, enableIfAttribute.Inverted);
                return(enabled);
            }
            else
            {
                string message = enableIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work";
                Debug.LogWarning(message, property.serializedObject.targetObject);

                return(false);
            }
        }
Пример #2
0
        public static bool IsEnabled(SerializedProperty property)
        {
            ReadOnlyAttribute     readOnlyAttribute = GetAttribute <ReadOnlyAttribute>(property);
            EnableIfAttributeBase enableIfAttribute = GetAttribute <EnableIfAttributeBase>(property);

            return(IsEnabled(readOnlyAttribute, enableIfAttribute, property));
        }
Пример #3
0
        public static bool IsEnabled(SerializedProperty property)
        {
            ReadOnlyAttribute readOnlyAttribute = GetAttribute <ReadOnlyAttribute>(property);

            if (readOnlyAttribute != null)
            {
                return(false);
            }

            EnableIfAttributeBase enableIfAttribute = GetAttribute <EnableIfAttributeBase>(property);

            if (enableIfAttribute == null)
            {
                return(true);
            }

            object target = GetTargetObjectWithProperty(property);

            // deal with enum conditions
            if (enableIfAttribute.EnumValue != null)
            {
                Enum value = GetEnumValue(target, enableIfAttribute.Conditions[0]);
                if (value != null)
                {
                    bool matched = value.GetType().GetCustomAttribute <FlagsAttribute>() == null
                        ? enableIfAttribute.EnumValue.Equals(value)
                        : value.HasFlag(enableIfAttribute.EnumValue);

                    return(matched != enableIfAttribute.Inverted);
                }

                string message = enableIfAttribute.GetType().Name + " needs a valid enum field, property or method name to work";
                Debug.LogWarning(message, property.serializedObject.targetObject);

                return(false);
            }

            // deal with normal conditions
            List <bool> conditionValues = GetConditionValues(target, enableIfAttribute.Conditions);

            if (conditionValues.Count > 0)
            {
                bool enabled = GetConditionsFlag(conditionValues, enableIfAttribute.ConditionOperator, enableIfAttribute.Inverted);
                return(enabled);
            }
            else
            {
                string message = enableIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work";
                Debug.LogWarning(message, property.serializedObject.targetObject);

                return(false);
            }
        }
Пример #4
0
        public static bool IsEnabled(Object target, MethodInfo method)
        {
            EnableIfAttributeBase enableIfAttribute = method.GetCustomAttribute <EnableIfAttributeBase>();

            if (enableIfAttribute == null)
            {
                return(true);
            }

            List <bool> conditionValues = PropertyUtility.GetConditionValues(target, enableIfAttribute.Conditions);

            if (conditionValues.Count > 0)
            {
                bool enabled = PropertyUtility.GetConditionsFlag(conditionValues, enableIfAttribute.ConditionOperator, enableIfAttribute.Inverted);
                return(enabled);
            }
            else
            {
                string message = enableIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work";
                Debug.LogWarning(message, target);

                return(false);
            }
        }