namespace Zinnia.Rule { using UnityEngine; using Zinnia.Data.Collection.List; using Zinnia.Data.Type; using Zinnia.Extension; /// /// Determines whether a has any that is enabled and found in a list. /// public class AnyBehaviourEnabledRule : GameObjectRule { [Tooltip("The behaviour types to look for.")] [SerializeField] private SerializableTypeBehaviourObservableList behaviourTypes; /// /// The behaviour types to look for. /// public SerializableTypeBehaviourObservableList BehaviourTypes { get { return behaviourTypes; } set { behaviourTypes = value; } } /// protected override bool Accepts(GameObject targetGameObject) { if (BehaviourTypes == null) { return false; } foreach (SerializableType serializedType in BehaviourTypes.NonSubscribableElements) { if (serializedType.ActualType != null && IsEnabled(targetGameObject.TryGetComponent(serializedType))) { return true; } } return false; } /// /// Determines whether the given component is enabled. /// /// The component to check the enabled state on. /// Whether the component is enabled or not. protected virtual bool IsEnabled(Component component) { if (component == null) { return false; } Behaviour checkBehaviour = component as Behaviour; return checkBehaviour != null && checkBehaviour.enabled; } } }