#if GRAPH_DESIGNER /// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Runtime.Tasks.Actions.CharacterControllerTasks { using Opsive.GraphDesigner.Runtime.Variables; using UnityEngine; [Opsive.Shared.Utility.Category("Character Controller")] [Opsive.Shared.Utility.Description("Gets CharacterController state (grounded, velocity, bounds, properties) with validation.")] public class GetState : TargetGameObjectAction { [Tooltip("Whether the character is grounded (output).")] [SerializeField] [RequireShared] protected SharedVariable m_IsGrounded; [Tooltip("The current velocity (output).")] [SerializeField] [RequireShared] protected SharedVariable m_Velocity; [Tooltip("The current height (output).")] [SerializeField] [RequireShared] protected SharedVariable m_Height; [Tooltip("The current radius (output).")] [SerializeField] [RequireShared] protected SharedVariable m_Radius; [Tooltip("The current center (output).")] [SerializeField] [RequireShared] protected SharedVariable m_Center; [Tooltip("The bounds center (output).")] [SerializeField] [RequireShared] protected SharedVariable m_BoundsCenter; [Tooltip("The bounds extents (output).")] [SerializeField] [RequireShared] protected SharedVariable m_BoundsExtents; private CharacterController m_ResolvedCharacterController; /// /// Initializes the target GameObject. /// protected override void InitializeTarget() { base.InitializeTarget(); m_ResolvedCharacterController = m_ResolvedGameObject.GetComponent(); } /// /// Updates the CharacterController state retrieval. /// /// The status of the action. public override TaskStatus OnUpdate() { if (m_ResolvedCharacterController == null) { return TaskStatus.Success; } m_IsGrounded.Value = m_ResolvedCharacterController.isGrounded; m_Velocity.Value = m_ResolvedCharacterController.velocity; m_Height.Value = m_ResolvedCharacterController.height; m_Radius.Value = m_ResolvedCharacterController.radius; m_Center.Value = m_ResolvedCharacterController.center; var bounds = m_ResolvedCharacterController.bounds; m_BoundsCenter.Value = bounds.center; m_BoundsExtents.Value = bounds.extents; return TaskStatus.Success; } /// /// Resets the action values back to their default. /// public override void Reset() { base.Reset(); m_IsGrounded = null; m_Velocity = null; m_Height = null; m_Radius = null; m_Center = null; m_BoundsCenter = null; m_BoundsExtents = null; } } } #endif