namespace Tilia.Interactions.Interactables.Interactables.Grab.Receiver { using UnityEngine; using Zinnia.Data.Attribute; using Zinnia.Data.Collection.List; using Zinnia.Event.Proxy; using Zinnia.Extension; using Zinnia.Tracking.Collision.Active; using Zinnia.Tracking.Collision.Active.Event.Proxy; /// /// Handles the way in which a grab event from an Interactor is received and processed by the Interactable. /// public class GrabInteractableReceiver : MonoBehaviour { /// /// The way in which the grab is kept active. /// public enum ActiveType { /// /// The grab will occur when the button is held down and will ungrab when the button is released. /// HoldTillRelease, /// /// The grab will occur on the first press of the button and stay grabbed until a second press of the button. /// Toggle } #region Interactable Settings [Header("Interactable Settings")] [Tooltip("The mechanism of how to keep the grab action active.")] [SerializeField] private ActiveType grabType = ActiveType.HoldTillRelease; /// /// The mechanism of how to keep the grab action active. /// public ActiveType GrabType { get { return grabType; } set { grabType = value; if (this.IsMemberChangeAllowed()) { OnAfterGrabTypeChange(); } } } #endregion #region Grab Consumer Settings [Header("Grab Consumer Settings")] [Tooltip("The ActiveCollisionConsumer that listens for the grab payload.")] [SerializeField] [Restricted] private ActiveCollisionConsumer grabConsumer; /// /// The that listens for the grab payload. /// public ActiveCollisionConsumer GrabConsumer { get { return grabConsumer; } set { grabConsumer = value; } } [Tooltip("The ActiveCollisionConsumer that listens for the ungrab payload.")] [SerializeField] [Restricted] private ActiveCollisionConsumer ungrabConsumer; /// /// The that listens for the ungrab payload. /// public ActiveCollisionConsumer UngrabConsumer { get { return ungrabConsumer; } set { ungrabConsumer = value; } } #endregion #region Grab Action Settings [Header("Grab Action Settings")] [Tooltip("The GameObjectEventProxyEmitter used to determine the grab validity.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter grabValidity; /// /// The used to determine the grab validity. /// public GameObjectEventProxyEmitter GrabValidity { get { return grabValidity; } set { grabValidity = value; } } #endregion #region Active Type Settings [Header("Active Type Settings")] [Tooltip("The GameObject containing the logic for starting HoldTillRelease grabbing.")] [SerializeField] [Restricted] private GameObject startStateGrab; /// /// The containing the logic for starting HoldTillRelease grabbing. /// public GameObject StartStateGrab { get { return startStateGrab; } set { startStateGrab = value; } } [Tooltip("The GameObject containing the logic for ending HoldTillRelease grabbing.")] [SerializeField] [Restricted] private GameObject stopStateGrab; /// /// The containing the logic for ending HoldTillRelease grabbing. /// public GameObject StopStateGrab { get { return stopStateGrab; } set { stopStateGrab = value; } } [Tooltip("The GameObject containing the logic for starting and ending Toggle grabbing.")] [SerializeField] [Restricted] private GameObject toggleGrab; /// /// The containing the logic for starting and ending Toggle grabbing. /// public GameObject ToggleGrab { get { return toggleGrab; } set { toggleGrab = value; } } [Tooltip("The GameObjectObservableSet containing the logic for starting and ending Toggle grabbing.")] [SerializeField] [Restricted] private GameObjectObservableList toggleList; /// /// The containing the logic for starting and ending Toggle grabbing. /// public GameObjectObservableList ToggleList { get { return toggleList; } set { toggleList = value; } } #endregion #region Output Settings [Header("Output Settings")] [Tooltip("The output ActiveCollisionConsumerEventProxyEmitter for the grab action.")] [SerializeField] [Restricted] private ActiveCollisionConsumerEventProxyEmitter outputActiveCollisionConsumer; /// /// The output for the grab action. /// public ActiveCollisionConsumerEventProxyEmitter OutputActiveCollisionConsumer { get { return outputActiveCollisionConsumer; } set { outputActiveCollisionConsumer = value; } } [Tooltip("The output GameObjectEventProxyEmitter for the grab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputGrabAction; /// /// The output for the grab action. /// public GameObjectEventProxyEmitter OutputGrabAction { get { return outputGrabAction; } set { outputGrabAction = value; } } [Tooltip("The output GameObjectEventProxyEmitter for the ungrab action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputUngrabAction; /// /// The output for the ungrab action. /// public GameObjectEventProxyEmitter OutputUngrabAction { get { return outputUngrabAction; } set { outputUngrabAction = value; } } [Tooltip("The output GameObjectEventProxyEmitter for the ungrab on untouch action.")] [SerializeField] [Restricted] private GameObjectEventProxyEmitter outputUngrabOnUntouchAction; /// /// The output for the ungrab on untouch action. /// public GameObjectEventProxyEmitter OutputUngrabOnUntouchAction { get { return outputUngrabOnUntouchAction; } set { outputUngrabOnUntouchAction = value; } } #endregion /// /// Sets the consumer containers to the current active container. /// /// The container for the consumer. public virtual void ConfigureConsumerContainers(GameObject container) { GrabConsumer.Container = container; UngrabConsumer.Container = container; } /// /// Sets the . /// /// The index of the . public virtual void SetGrabType(int index) { GrabType = EnumExtensions.GetByIndex(index); } /// /// Configures the Grab Type to be used. /// public virtual void ConfigureGrabType() { switch (GrabType) { case ActiveType.HoldTillRelease: StartStateGrab.TrySetActive(true); StopStateGrab.TrySetActive(true); ToggleGrab.TrySetActive(false); break; case ActiveType.Toggle: StartStateGrab.TrySetActive(false); StopStateGrab.TrySetActive(false); ToggleGrab.TrySetActive(true); break; } } protected virtual void OnEnable() { ConfigureGrabType(); } /// /// Called after has been changed. /// protected virtual void OnAfterGrabTypeChange() { ConfigureGrabType(); } } }