namespace Tilia.Interactions.Interactables.Interactors.Rule { using UnityEngine; using Zinnia.Rule; /// /// Simplifies implementing s that only deals with an attached to a . /// public abstract class InteractorRule : GameObjectRule { /// /// A cache to store the given to prevent having to re execute the method on the same given . /// protected GameObject cachedGameObject; /// /// The cached to check the grabbed state on. /// protected InteractorFacade cachedInteractor; /// /// Determines whether a is accepted. /// /// The to check. /// if is accepted, otherwise. protected abstract bool Accepts(InteractorFacade targetInteractorFacade); /// protected override bool Accepts(GameObject targetGameObject) { if (cachedGameObject != targetGameObject || cachedInteractor == null) { cachedInteractor = targetGameObject.GetComponent(); if (cachedInteractor != null) { cachedGameObject = targetGameObject; } } if (cachedInteractor == null) { return false; } return Accepts(cachedInteractor); } } }