namespace VRTK.Prefabs.Helpers.AxisRotator { using UnityEngine; using Malimbe.PropertySerializationAttribute; using Malimbe.XmlDocumentationAttribute; using Zinnia.Action; using Zinnia.Extension; using Zinnia.Data.Attribute; using Zinnia.Data.Operation.Mutation; using Zinnia.Data.Operation.Extraction; /// /// Sets up the AxisRotator prefab based on the provided settings and implements the logic to allow rotating an object based on axis data. /// public class AxisRotatorConfigurator : MonoBehaviour { #region Facade Settings /// /// The public interface facade. /// [Serialized] [field: Header("Facade Settings"), DocumentedByXml, Restricted] public AxisRotatorFacade Facade { get; protected set; } #endregion #region Reference Settings /// /// The lateral to map to. /// [Serialized] [field: Header("Reference Settings"), DocumentedByXml, Restricted] public FloatAction LateralAxis { get; protected set; } /// /// The longitudinal to map to. /// [Serialized] [field: DocumentedByXml, Restricted] public FloatAction LongitudinalAxis { get; protected set; } /// /// The mutator to update the target rotation. /// [Serialized] [field: DocumentedByXml, Restricted] public TransformEulerRotationMutator RotationMutator { get; protected set; } /// /// The extractor to get the target offset direction data. /// [Serialized] [field: DocumentedByXml, Restricted] public TransformDirectionExtractor DirectionExtractor { get; protected set; } #endregion /// /// Sets the axis sources. /// /// Whether to only clear the existing sources and not add new ones. public virtual void SetAxisSources(bool clearOnly = false) { if (LateralAxis != null) { LateralAxis.RunWhenActiveAndEnabled(() => LateralAxis.ClearSources()); if (!clearOnly && Facade.LateralAxis != null) { LateralAxis.RunWhenActiveAndEnabled(() => LateralAxis.AddSource(Facade.LateralAxis)); } } if (LongitudinalAxis != null) { LongitudinalAxis.RunWhenActiveAndEnabled(() => LongitudinalAxis.ClearSources()); if (!clearOnly && Facade.LongitudinalAxis != null) { LongitudinalAxis.RunWhenActiveAndEnabled(() => LongitudinalAxis.AddSource(Facade.LongitudinalAxis)); } } } /// /// Sets the target of the rotation mutator. /// public virtual void SetMutator() { RotationMutator.Target = Facade.Target; } /// /// Sets the source of the rotation extractor. /// public virtual void SetExtractor() { DirectionExtractor.Source = Facade.DirectionOffset; } protected virtual void OnEnable() { SetAxisSources(); SetMutator(); SetExtractor(); } protected virtual void OnDisable() { SetAxisSources(true); } } }