namespace VRTK.Prefabs.Interactions.Interactors { using UnityEngine; using Malimbe.MemberChangeMethod; using Malimbe.MemberClearanceMethod; using Malimbe.XmlDocumentationAttribute; using Malimbe.PropertySerializationAttribute; using Zinnia.Action; using Zinnia.Extension; using Zinnia.Data.Attribute; using Zinnia.Tracking.Collision.Active; /// /// Sets up the Interactor Prefab action settings based on the provided user settings. /// public class ActionInteractorConfigurator : MonoBehaviour { #region Action Settings /// /// The to be monitored to control the interaction. /// [Serialized, Cleared] [field: Header("Action Settings"), DocumentedByXml] public Action SourceAction { get; set; } /// /// The source for the interaction publishers to publish as. /// [Serialized, Cleared] [field: Header("Action Settings"), DocumentedByXml] public GameObject SourceContainer { get; set; } #endregion #region Reference Settings /// /// The that will be linked to the . /// [Serialized] [field: Header("Reference Settings"), DocumentedByXml, Restricted] public Action TargetAction { get; protected set; } /// /// The for checking valid start action. /// [Serialized] [field: DocumentedByXml, Restricted] public ActiveCollisionPublisher StartActionPublisher { get; protected set; } /// /// The for checking valid stop action. /// [Serialized] [field: DocumentedByXml, Restricted] public ActiveCollisionPublisher StopActionPublisher { get; protected set; } #endregion protected virtual void OnEnable() { LinkSourceActionToTargetAction(); LinkSourceContainerToPublishers(); } /// /// Links the to the internal . /// protected virtual void LinkSourceActionToTargetAction() { TargetAction.RunWhenActiveAndEnabled(() => TargetAction.ClearSources()); TargetAction.RunWhenActiveAndEnabled(() => TargetAction.AddSource(SourceAction)); } /// /// Links the to the payload source containers on the start and stop publishers. /// protected virtual void LinkSourceContainerToPublishers() { StartActionPublisher.Payload.SourceContainer = SourceContainer; StopActionPublisher.Payload.SourceContainer = SourceContainer; } /// /// Called after has been changed. /// [CalledAfterChangeOf(nameof(SourceAction))] protected virtual void OnAfterSourceActionChange() { LinkSourceActionToTargetAction(); } /// /// Called after has been changed. /// [CalledAfterChangeOf(nameof(SourceContainer))] protected virtual void OnAfterSourceContainerChange() { LinkSourceContainerToPublishers(); } } }