using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
namespace UnityEngine.InputSystem.Controls
{
///
/// A floating-point 2D vector control composed of two s.
///
///
/// An example is .
///
///
///
/// Debug.Log(string.Format("Mouse position x={0} y={1}",
/// Mouse.current.position.x.ReadValue(),
/// Mouse.current.position.y.ReadValue()));
///
///
///
/// Normalization is not implied. The X and Y coordinates can be in any range or units.
///
public class Vector2Control : InputControl
{
///
/// Horizontal position of the control.
///
/// Control representing horizontal motion input.
[InputControl(offset = 0, displayName = "X")]
public AxisControl x { get; set; }
///
/// Vertical position of the control.
///
/// Control representing vertical motion input.
[InputControl(offset = 4, displayName = "Y")]
public AxisControl y { get; set; }
///
/// Default-initialize the control.
///
public Vector2Control()
{
m_StateBlock.format = InputStateBlock.FormatVector2;
}
///
protected override void FinishSetup()
{
x = GetChildControl("x");
y = GetChildControl("y");
base.FinishSetup();
}
///
public override unsafe Vector2 ReadUnprocessedValueFromState(void* statePtr)
{
return new Vector2(
x.ReadUnprocessedValueFromState(statePtr),
y.ReadUnprocessedValueFromState(statePtr));
}
///
public override unsafe void WriteValueIntoState(Vector2 value, void* statePtr)
{
x.WriteValueIntoState(value.x, statePtr);
y.WriteValueIntoState(value.y, statePtr);
}
///
public override unsafe float EvaluateMagnitude(void* statePtr)
{
////REVIEW: this can go beyond 1; that okay?
return ReadValueFromState(statePtr).magnitude;
}
}
}