Пример #1
0
        public static bool IsButtonVisible(UnityEngine.Object target, MethodInfo method)
        {
            var showIfAttribute = Attribute.GetCustomAttribute(method, typeof(ShowIfAttribute)) as ShowIfAttribute;
            var hideIfAttribute = Attribute.GetCustomAttribute(method, typeof(HideIfAttribute)) as HideIfAttribute;

            if ((showIfAttribute == null) && (hideIfAttribute == null))
            {
                return(true);
            }

            if (showIfAttribute != null)
            {
                bool showingCondition = true;

                if (showIfAttribute.TargetConditionValue != null)
                {
                    var hasCondition = showIfAttribute.TargetConditionValue.ToBool(out bool conditionValue);
                    showingCondition = hasCondition ? conditionValue : true;
                }

                var fieldValue = (bool)target.GetField(showIfAttribute.PropertyName).GetValue(target);

                if (showingCondition == fieldValue)
                {
                    return(true);
                }
            }

            if (hideIfAttribute != null)
            {
                bool hidingCondition = true;

                if (hideIfAttribute.TargetConditionValue != null)
                {
                    var hasCondition = hideIfAttribute.TargetConditionValue.ToBool(out bool conditionValue);
                    hidingCondition = hasCondition ? conditionValue : true;
                }

                var fieldValue = (bool)target.GetField(hideIfAttribute.PropertyName).GetValue(target);

                if (hidingCondition != fieldValue)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public static bool IsButtonEnabled(UnityEngine.Object target, MethodInfo method)
        {
            var enableIfAttribute  = Attribute.GetCustomAttribute(method, typeof(EnableIfAttribute)) as EnableIfAttribute;
            var disableIfAttribute = Attribute.GetCustomAttribute(method, typeof(DisableIfAttribute)) as DisableIfAttribute;

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

            if (enableIfAttribute != null)
            {
                bool enablingCondition = true;

                if (enableIfAttribute.TargetConditionValue != null)
                {
                    var hasCondition = enableIfAttribute.TargetConditionValue.ToBool(out bool conditionValue);
                    enablingCondition = hasCondition ? conditionValue : true;
                }

                var fieldValue = (bool)target.GetField(enableIfAttribute.PropertyName).GetValue(target);

                if (enablingCondition == fieldValue)
                {
                    return(true);
                }
            }

            if (disableIfAttribute != null)
            {
                bool disablingCondition = true;

                if (disableIfAttribute.TargetConditionValue != null)
                {
                    var hasCondition = disableIfAttribute.TargetConditionValue.ToBool(out bool conditionValue);
                    disablingCondition = hasCondition ? conditionValue : true;
                }

                var fieldValue = (bool)target.GetField(disableIfAttribute.PropertyName).GetValue(target);

                if (disablingCondition != fieldValue)
                {
                    return(true);
                }
            }

            return(false);
        }