namespace Tilia.Interactions.Interactables.Interactables.Grab.Provider { using System.Collections.Generic; using Tilia.Interactions.Interactables.Interactors; using UnityEngine; using Zinnia.Data.Attribute; using Zinnia.Event.Proxy; using Zinnia.Extension; /// /// Processes a received grab event and passes it over to the appropriate grab actions. /// public abstract class GrabInteractableInteractorProvider : MonoBehaviour { #region Input Settings [Header("Input Settings")] [Tooltip("The input GameObjectEventProxyEmitter for the grab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter inputGrabReceived; /// /// The input for the grab action. /// public GameObjectEventProxyEmitter InputGrabReceived { get { return inputGrabReceived; } set { inputGrabReceived = value; } } [Tooltip("The input GameObjectEventProxyEmitter for the ungrab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter inputUngrabReceived; /// /// The input for the ungrab action. /// public GameObjectEventProxyEmitter InputUngrabReceived { get { return inputUngrabReceived; } set { inputUngrabReceived = value; } } #endregion #region Primary Output Settings [Header("Primary Output Settings")] [Tooltip("The output GameObjectEventProxyEmitter for the primary grab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputPrimaryGrabAction; /// /// The output for the primary grab action. /// public GameObjectEventProxyEmitter OutputPrimaryGrabAction { get { return outputPrimaryGrabAction; } set { outputPrimaryGrabAction = value; } } [Tooltip("The output GameObjectEventProxyEmitter for the primary grab setup on secondary action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputPrimaryGrabSetupOnSecondaryAction; /// /// The output for the primary grab setup on secondary action. /// public GameObjectEventProxyEmitter OutputPrimaryGrabSetupOnSecondaryAction { get { return outputPrimaryGrabSetupOnSecondaryAction; } set { outputPrimaryGrabSetupOnSecondaryAction = value; } } [Tooltip("The output GameObjectEventProxyEmitter for the primary ungrab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputPrimaryUngrabAction; /// /// The output for the primary ungrab action. /// public GameObjectEventProxyEmitter OutputPrimaryUngrabAction { get { return outputPrimaryUngrabAction; } set { outputPrimaryUngrabAction = value; } } [Tooltip("The output GameObjectEventProxyEmitter for the primary ungrab reset on secondary action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputPrimaryUngrabResetOnSecondaryAction; /// /// The output for the primary ungrab reset on secondary action. /// public GameObjectEventProxyEmitter OutputPrimaryUngrabResetOnSecondaryAction { get { return outputPrimaryUngrabResetOnSecondaryAction; } set { outputPrimaryUngrabResetOnSecondaryAction = value; } } #endregion #region Secondary Output Settings [Header("Secondary Output Settings")] [Tooltip("The output GameObjectEventProxyEmitter for the secondary grab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputSecondaryGrabAction; /// /// The output for the secondary grab action. /// public GameObjectEventProxyEmitter OutputSecondaryGrabAction { get { return outputSecondaryGrabAction; } set { outputSecondaryGrabAction = value; } } [Tooltip("The output GameObjectEventProxyEmitter for the Secondary ungrab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputSecondaryUngrabAction; /// /// The output for the Secondary ungrab action. /// public GameObjectEventProxyEmitter OutputSecondaryUngrabAction { get { return outputSecondaryUngrabAction; } set { outputSecondaryUngrabAction = value; } } #endregion /// /// Gets the available grabbing Interactors from the provider. /// /// A collection of Interactors that are currently grabbing the Interactable. public abstract IReadOnlyList GrabbingInteractors { get; } /// /// A reusable collection to hold the returned grabbing interactors. /// protected readonly List grabbingInteractors = new List(); /// /// Gets the Grabbing Interactors stored in the given collection. /// /// The collection to retrieve the Grabbing Interactors from. /// A collection of Grabbing Interactors. protected virtual IReadOnlyList GetGrabbingInteractors(IEnumerable elements) { grabbingInteractors.Clear(); if (elements == null) { return grabbingInteractors; } foreach (GameObject element in elements) { InteractorFacade interactor = element.TryGetComponent(true, true); if (interactor != null) { grabbingInteractors.Add(interactor); } } return grabbingInteractors; } } }