namespace VRTK.Prefabs.Interactions.Interactables.Grab.Receiver
{
using UnityEngine;
using Malimbe.MemberChangeMethod;
using Malimbe.XmlDocumentationAttribute;
using Malimbe.PropertySerializationAttribute;
using Zinnia.Extension;
using Zinnia.Event.Proxy;
using Zinnia.Data.Attribute;
using Zinnia.Data.Collection.List;
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
///
/// The mechanism of how to keep the grab action active.
///
[Serialized]
[field: Header("Interactable Settings"), DocumentedByXml]
public ActiveType GrabType { get; set; } = ActiveType.HoldTillRelease;
#endregion
#region Grab Consumer Settings
///
/// The that listens for the grab payload.
///
[Serialized]
[field: Header("Grab Consumer Settings"), DocumentedByXml, Restricted]
public ActiveCollisionConsumer GrabConsumer { get; protected set; }
///
/// The that listens for the ungrab payload.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public ActiveCollisionConsumer UngrabConsumer { get; protected set; }
#endregion
#region Grab Action Settings
///
/// The used to determine the grab validity.
///
[Serialized]
[field: Header("Grab Action Settings"), DocumentedByXml, Restricted]
public GameObjectEventProxyEmitter GrabValidity { get; set; }
#endregion
#region Active Type Settings
///
/// The containing the logic for starting HoldTillRelease grabbing.
///
[Serialized]
[field: Header("Active Type Settings"), DocumentedByXml, Restricted]
public GameObject StartStateGrab { get; protected set; }
///
/// The containing the logic for ending HoldTillRelease grabbing.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObject StopStateGrab { get; protected set; }
///
/// The containing the logic for starting and ending Toggle grabbing.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObject ToggleGrab { get; protected set; }
///
/// The containing the logic for starting and ending Toggle grabbing.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObjectObservableList ToggleList { get; protected set; }
#endregion
#region Output Settings
///
/// The output for the grab action.
///
[Serialized]
[field: Header("Output Settings"), DocumentedByXml, Restricted]
public ActiveCollisionConsumerEventProxyEmitter OutputActiveCollisionConsumer { get; protected set; }
///
/// The output for the grab action.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObjectEventProxyEmitter OutputGrabAction { get; protected set; }
///
/// The output for the ungrab action.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObjectEventProxyEmitter OutputUngrabAction { get; protected set; }
///
/// The output for the ungrab on untouch action.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObjectEventProxyEmitter OutputUngrabOnUntouchAction { get; protected set; }
#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;
}
///
/// 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.
///
[CalledAfterChangeOf(nameof(GrabType))]
protected virtual void OnAfterGrabTypeChange()
{
ConfigureGrabType();
}
}
}