#if GRAPH_DESIGNER /// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Runtime.Tasks.Actions.Conversions { using Opsive.GraphDesigner.Runtime.Variables; using UnityEngine; [Opsive.Shared.Utility.Category("Conversions")] [Opsive.Shared.Utility.Description("Converts a Vector2 to a float value. Can extract magnitude, squared magnitude, X, or Y component.")] public class ConvertVector2ToFloat : Action { /// /// Specifies how to convert the Vector2 to a float. /// public enum ConversionType { Magnitude, // The magnitude (length) of the vector. SqrMagnitude, // The squared magnitude of the vector. X, // The X component. Y // The Y component. } [Tooltip("The Vector2 to convert.")] [SerializeField] protected SharedVariable m_InputVector; [Tooltip("Specifies how to convert the Vector2 to a float.")] [SerializeField] protected ConversionType m_ConversionType = ConversionType.Magnitude; [Tooltip("The resulting float value.")] [SerializeField] [RequireShared] protected SharedVariable m_OutputValue; /// /// Converts the Vector2 to a float based on the conversion type. /// /// The status of the action. public override TaskStatus OnUpdate() { switch (m_ConversionType) { case ConversionType.Magnitude: m_OutputValue.Value = m_InputVector.Value.magnitude; break; case ConversionType.SqrMagnitude: m_OutputValue.Value = m_InputVector.Value.sqrMagnitude; break; case ConversionType.X: m_OutputValue.Value = m_InputVector.Value.x; break; case ConversionType.Y: m_OutputValue.Value = m_InputVector.Value.y; break; } return TaskStatus.Success; } /// /// Resets the action values back to their default. /// public override void Reset() { base.Reset(); m_InputVector = null; m_ConversionType = ConversionType.Magnitude; m_OutputValue = null; } } } #endif