namespace VRTK.Prefabs.Interactions.Interactables.Climb
{
using UnityEngine;
using Malimbe.XmlDocumentationAttribute;
using Malimbe.PropertySerializationAttribute;
using Zinnia.Event.Proxy;
using Zinnia.Data.Attribute;
///
/// Sets up the Interactable.Climbable prefab based on the provided user settings.
///
public class ClimbInteractableConfigurator : MonoBehaviour
{
#region Facade Settings
///
/// The public interface facade.
///
[Serialized]
[field: Header("Facade Settings"), DocumentedByXml, Restricted]
public ClimbInteractableFacade Facade { get; protected set; }
#endregion
#region Reference Settings
///
/// The component acting as the interactable for climbing.
///
[Serialized]
[field: Header("Reference Settings"), DocumentedByXml, Restricted]
public InteractableFacade InteractableFacade { get; protected set; }
///
/// The component handling a started climb.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObjectEventProxyEmitter StartEventProxyEmitter { get; protected set; }
///
/// The component handling a stopped climb.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObjectEventProxyEmitter StopEventProxyEmitter { get; protected set; }
#endregion
protected virtual void OnEnable()
{
StartEventProxyEmitter.Emitted.AddListener(OnStartEventProxyEmitted);
StopEventProxyEmitter.Emitted.AddListener(OnStopEventProxyEmitted);
}
protected virtual void OnDisable()
{
StopEventProxyEmitter.Emitted.RemoveListener(OnStopEventProxyEmitted);
StartEventProxyEmitter.Emitted.RemoveListener(OnStartEventProxyEmitted);
}
///
/// Processes the start climbing functionality.
///
/// The interactor initiating the climb.
protected virtual void OnStartEventProxyEmitted(GameObject interactor)
{
Facade.ClimbFacade.AddInteractor(interactor);
Facade.ClimbFacade.AddInteractable(InteractableFacade.gameObject);
}
///
/// Processes the stop climbing functionality.
///
/// The interactor that is no longer climbing.
protected virtual void OnStopEventProxyEmitted(GameObject interactor)
{
Facade.ClimbFacade.SetVelocitySource(interactor);
Facade.ClimbFacade.SetVelocityMultiplier(Facade.ReleaseMultiplier);
Facade.ClimbFacade.RemoveInteractable(InteractableFacade.gameObject);
Facade.ClimbFacade.RemoveInteractor(interactor);
}
}
}