namespace Tilia.Interactions.Interactables.Interactables.Grab.Action { using UnityEngine; using Zinnia.Data.Attribute; using Zinnia.Data.Collection.List; using Zinnia.Tracking.Modification; /// /// Describes an action that allows the Interactable to point in the direction of a given Interactor. /// public class GrabInteractableControlDirectionAction : GrabInteractableAction { #region Interactable Settings [Header("Interactable Settings")] [Tooltip("A GameObject collection to enable/disabled as part of the direction control process.")] [SerializeField] private GameObjectObservableList linkedObjects; /// /// A collection to enable/disabled as part of the direction control process. /// public GameObjectObservableList LinkedObjects { get { return linkedObjects; } set { linkedObjects = value; } } [Tooltip("The Zinnia.Tracking.Modification.DirectionModifier to process the direction control.")] [SerializeField] [Restricted] private DirectionModifier directionModifier; /// /// The to process the direction control. /// public DirectionModifier DirectionModifier { get { return directionModifier; } set { directionModifier = value; } } #endregion /// /// Enables the state of each of the items in the collection. /// public virtual void EnableLinkedObjects() { ToggleLinkedObjectState(true); } /// /// Disables the state of each of the items in the collection. /// public virtual void DisableLinkedObjects() { ToggleLinkedObjectState(false); } /// /// Sets up the based on the target offsets from any follow action. /// public virtual void SetupTargetOffset() { if (GrabSetup == null) { return; } if (GrabSetup.SecondaryAction == this) { LinkTargetOffsets(GrabSetup.PrimaryAction); } else if (GrabSetup.PrimaryAction == this) { LinkTargetOffsets(GrabSetup.SecondaryAction); } } /// /// Links the given action's target offset to the if the action is a Follow Action. /// /// The action to try and link from. protected virtual void LinkTargetOffsets(GrabInteractableAction action) { if (!typeof(GrabInteractableFollowAction).IsAssignableFrom(action.GetType())) { return; } GrabInteractableFollowAction followAction = (GrabInteractableFollowAction)action; if (followAction == null || followAction.ObjectFollower == null || followAction.ObjectFollower.TargetOffsets == null) { return; } DirectionModifier.TargetOffset = followAction.ObjectFollower.TargetOffsets.NonSubscribableElements.Count > 0 ? followAction.ObjectFollower.TargetOffsets.NonSubscribableElements[0] : null; DirectionModifier.PivotOffset = DirectionModifier.TargetOffset != null && DirectionModifier.TargetOffset.transform.childCount > 0 ? DirectionModifier.TargetOffset.transform.GetChild(0).gameObject : null; } /// /// Toggles the state of each of the items in the collection. /// /// The state to set the active state to. protected virtual void ToggleLinkedObjectState(bool state) { if (LinkedObjects == null) { return; } foreach (GameObject linkedObject in LinkedObjects.NonSubscribableElements) { linkedObject.SetActive(state); } } /// protected override void OnAfterGrabSetupChange() { DirectionModifier.Target = GrabSetup.Facade.Configuration.ConsumerContainer; } } }