namespace Zinnia.Rule { using System; using UnityEngine; using Zinnia.Data.Attribute; /// /// The basis for all rule types. /// public abstract class Rule : MonoBehaviour, IRule { /// /// The states that are considered when determining if a should be automatically rejected. /// [Flags] public enum RejectRuleStates { /// /// The will always be rejected if the component is disabled. /// RuleComponentIsDisabled = 1 << 0, /// /// The will always be rejected if the containing is inactive in the scene hierarchy. /// RuleGameObjectIsNotActiveInHierarchy = 1 << 1 } [Tooltip("The states on whether to automatically reject a Rule.")] [SerializeField] [UnityFlags] private RejectRuleStates autoRejectStates = (RejectRuleStates)(-1); /// /// The states on whether to automatically reject a . /// public RejectRuleStates AutoRejectStates { get { return autoRejectStates; } set { autoRejectStates = value; } } protected bool isDestroyed; /// public abstract bool Accepts(object target); /// /// Whether to automatically reject the based on the . /// /// Whether the rule should be rejected. public virtual bool ShouldAutoRejectDueToState() { return ((AutoRejectStates & RejectRuleStates.RuleComponentIsDisabled) != 0 && !enabled) || ((AutoRejectStates & RejectRuleStates.RuleGameObjectIsNotActiveInHierarchy) != 0 && !gameObject.activeInHierarchy); } protected virtual void OnDestroy() { isDestroyed = true; } } }