#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 float to a Vector2 by setting X, Y, or both components to the float value.")]
public class ConvertFloatToVector2 : Action
{
///
/// Specifies which component(s) to set in the Vector2.
///
public enum SetComponent
{
SetX, // Set only the X component (Y remains 0).
SetY, // Set only the Y component (X remains 0).
SetBoth // Set both X and Y to the float value.
}
[Tooltip("The float to convert.")]
[SerializeField] protected SharedVariable m_InputValue;
[Tooltip("Specifies which component(s) to set.")]
[SerializeField] protected SetComponent m_SetComponent = SetComponent.SetX;
[Tooltip("The resulting Vector2 value.")]
[SerializeField] [RequireShared] protected SharedVariable m_OutputVector;
///
/// Converts the float to a Vector2.
///
/// The status of the action.
public override TaskStatus OnUpdate()
{
switch (m_SetComponent) {
case SetComponent.SetX:
m_OutputVector.Value = new Vector2(m_InputValue.Value, 0f);
break;
case SetComponent.SetY:
m_OutputVector.Value = new Vector2(0f, m_InputValue.Value);
break;
case SetComponent.SetBoth:
m_OutputVector.Value = new Vector2(m_InputValue.Value, m_InputValue.Value);
break;
}
return TaskStatus.Success;
}
///
/// Resets the action values back to their default.
///
public override void Reset()
{
base.Reset();
m_InputValue = null;
m_SetComponent = SetComponent.SetX;
m_OutputVector = null;
}
}
}
#endif