namespace VRTK.Prefabs.Pointers { using UnityEngine; using Malimbe.XmlDocumentationAttribute; using Malimbe.PropertySerializationAttribute; using Zinnia.Cast; using Zinnia.Action; using Zinnia.Pointer; using Zinnia.Extension; using Zinnia.Data.Attribute; using Zinnia.Tracking.Follow; /// /// Sets up the Pointer Prefab based on the provided user settings. /// public class PointerConfigurator : MonoBehaviour { #region Facade Settings /// /// The public facade. /// [Serialized] [field: Header("Facade Settings"), DocumentedByXml, Restricted] public PointerFacade Facade { get; protected set; } #endregion #region Pointer Settings /// /// The component for the Pointer. /// [Serialized] [field: Header("Pointer Settings"), DocumentedByXml, Restricted] public ObjectPointer ObjectPointer { get; protected set; } #endregion #region Object Follow Settings /// /// The component for the Pointer. /// [Serialized] [field: Header("Object Follow Settings"), DocumentedByXml, Restricted] public ObjectFollower ObjectFollow { get; protected set; } #endregion #region Cast Settings /// /// The component for the Pointer. /// [Serialized] [field: Header("Cast Settings"), DocumentedByXml, Restricted] public PointsCast Caster { get; protected set; } #endregion #region Action Settings /// /// The that will activate/deactivate the pointer. /// [Serialized] [field: Header("Action Settings"), DocumentedByXml, Restricted] public BooleanAction ActivationAction { get; protected set; } /// /// The that initiates the pointer selection when the action is activated. /// [Serialized] [field: DocumentedByXml, Restricted] public BooleanAction SelectOnActivatedAction { get; protected set; } /// /// The that initiates the pointer selection when the action is deactivated. /// [Serialized] [field: DocumentedByXml, Restricted] public BooleanAction SelectOnDeactivatedAction { get; protected set; } #endregion /// /// Configures the target validity based on the facade settings. /// public virtual void ConfigureTargetValidity() { Caster.TargetValidity = Facade.TargetValidity; } /// /// Configures the object follow sources based on the facade settings. /// public virtual void ConfigureFollowSources() { ObjectFollow.Sources.RunWhenActiveAndEnabled(() => ObjectFollow.Sources.Clear()); if (Facade.FollowSource != null) { ObjectFollow.Sources.RunWhenActiveAndEnabled(() => ObjectFollow.Sources.Add(Facade.FollowSource)); } } /// /// Configures the selection action on the facade settings. /// public virtual void ConfigureSelectionAction() { SelectOnActivatedAction.RunWhenActiveAndEnabled(() => SelectOnActivatedAction.ClearSources()); SelectOnDeactivatedAction.RunWhenActiveAndEnabled(() => SelectOnDeactivatedAction.ClearSources()); if (Facade.SelectionAction != null) { SelectOnActivatedAction.RunWhenActiveAndEnabled(() => SelectOnActivatedAction.AddSource(Facade.SelectionAction)); SelectOnDeactivatedAction.RunWhenActiveAndEnabled(() => SelectOnDeactivatedAction.AddSource(Facade.SelectionAction)); } } /// /// Configures the activation action based on the facade settings. /// public virtual void ConfigureActivationAction() { ActivationAction.RunWhenActiveAndEnabled(() => ActivationAction.ClearSources()); if (Facade.ActivationAction != null) { ActivationAction.RunWhenActiveAndEnabled(() => ActivationAction.AddSource(Facade.ActivationAction)); } } /// /// Configures the selection type based on the facade settings. /// public virtual void ConfigureSelectionType() { ActivationAction.gameObject.SetActive(false); switch (Facade.SelectionMethod) { case PointerFacade.SelectionType.SelectOnActivate: SelectOnActivatedAction.gameObject.SetActive(true); SelectOnDeactivatedAction.gameObject.SetActive(false); break; case PointerFacade.SelectionType.SelectOnDeactivate: SelectOnActivatedAction.gameObject.SetActive(false); SelectOnDeactivatedAction.gameObject.SetActive(true); break; } ConfigureSelectionAction(); ConfigureActivationAction(); ActivationAction.gameObject.SetActive(true); } /// /// Emits the Activated event. /// /// The data to emit. public virtual void EmitActivated(ObjectPointer.EventData eventData) { Facade.Activated?.Invoke(eventData); } /// /// Emits the Deactivated event. /// /// The data to emit. public virtual void EmitDeactivated(ObjectPointer.EventData eventData) { Facade.Deactivated?.Invoke(eventData); } /// /// Emits the Entered event. /// /// The data to emit. public virtual void EmitEntered(ObjectPointer.EventData eventData) { Facade.Entered?.Invoke(eventData); } /// /// Emits the Exited event. /// /// The data to emit. public virtual void EmitExited(ObjectPointer.EventData eventData) { Facade.Exited?.Invoke(eventData); } /// /// Emits the HoverChanged event. /// /// The data to emit. public virtual void EmitHoverChanged(ObjectPointer.EventData eventData) { Facade.HoverChanged?.Invoke(eventData); } /// /// Emits the Selected event. /// /// The data to emit. public virtual void EmitSelected(ObjectPointer.EventData eventData) { Facade.Selected?.Invoke(eventData); } protected virtual void OnEnable() { ConfigureTargetValidity(); ConfigureFollowSources(); ConfigureSelectionType(); } } }