//参数为一个序列化属性 public static bool IsVisible(SerializedProperty property) { ShowIfAttributeBase showIfAttribute = GetAttribute <ShowIfAttributeBase>(property); if (showIfAttribute == null) { return(true); } object target = GetTargetObjectWithProperty(property); List <bool> conditionValues = GetConditionValues(target, showIfAttribute.Conditions); if (conditionValues.Count > 0) { bool enabled = GetConditionsFlag(conditionValues, showIfAttribute.ConditionOperator, showIfAttribute.Inverted); return(enabled); } else { // string message = showIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work"; // Debug.LogWarning(message, property.serializedObject.targetObject); return(showIfAttribute.Condition); } }
public static bool IsVisible(ShowIfAttributeBase showIfAttribute, SerializedProperty property) { if (showIfAttribute == null) { return(true); } object target = GetTargetObjectWithProperty(property); // deal with enum conditions if (showIfAttribute.EnumValue != null) { Enum value = GetEnumValue(target, showIfAttribute.Conditions[0]); if (value != null) { bool matched = value.GetType().GetCustomAttribute <FlagsAttribute>() == null ? showIfAttribute.EnumValue.Equals(value) : value.HasFlag(showIfAttribute.EnumValue); return(matched != showIfAttribute.Inverted); } string message = showIfAttribute.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, showIfAttribute.Conditions); if (conditionValues.Count > 0) { bool enabled = GetConditionsFlag(conditionValues, showIfAttribute.ConditionOperator, showIfAttribute.Inverted); return(enabled); } else { string message = showIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work"; Debug.LogWarning(message, property.serializedObject.targetObject); return(false); } }
public static bool IsVisible(Object target, MethodInfo method) { ShowIfAttributeBase showIfAttribute = method.GetCustomAttribute <ShowIfAttributeBase>(); if (showIfAttribute == null) { return(true); } List <bool> conditionValues = PropertyUtility.GetConditionValues(target, showIfAttribute.Conditions); if (conditionValues.Count > 0) { bool enabled = PropertyUtility.GetConditionsFlag(conditionValues, showIfAttribute.ConditionOperator, showIfAttribute.Inverted); return(enabled); } else { string message = showIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work"; Debug.LogWarning(message, target); return(false); } }
public static bool IsVisible(SerializedProperty property) { ShowIfAttributeBase showIfAttribute = GetAttribute <ShowIfAttributeBase>(property); return(IsVisible(showIfAttribute, property)); }