Vector3Control.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine.InputSystem.Layouts;
  2. using UnityEngine.InputSystem.LowLevel;
  3. namespace UnityEngine.InputSystem.Controls
  4. {
  5. /// <summary>
  6. /// A floating-point 3D vector control composed of three <see cref="AxisControl">AxisControls</see>.
  7. /// </summary>
  8. [Scripting.Preserve]
  9. public class Vector3Control : InputControl<Vector3>
  10. {
  11. [InputControl(offset = 0, displayName = "X")]
  12. public AxisControl x { get; private set; }
  13. [InputControl(offset = 4, displayName = "Y")]
  14. public AxisControl y { get; private set; }
  15. [InputControl(offset = 8, displayName = "Z")]
  16. public AxisControl z { get; private set; }
  17. public Vector3Control()
  18. {
  19. m_StateBlock.format = InputStateBlock.FormatVector3;
  20. }
  21. protected override void FinishSetup()
  22. {
  23. x = GetChildControl<AxisControl>("x");
  24. y = GetChildControl<AxisControl>("y");
  25. z = GetChildControl<AxisControl>("z");
  26. base.FinishSetup();
  27. }
  28. public override unsafe Vector3 ReadUnprocessedValueFromState(void* statePtr)
  29. {
  30. return new Vector3(
  31. x.ReadUnprocessedValueFromState(statePtr),
  32. y.ReadUnprocessedValueFromState(statePtr),
  33. z.ReadUnprocessedValueFromState(statePtr));
  34. }
  35. public override unsafe void WriteValueIntoState(Vector3 value, void* statePtr)
  36. {
  37. x.WriteValueIntoState(value.x, statePtr);
  38. y.WriteValueIntoState(value.y, statePtr);
  39. z.WriteValueIntoState(value.z, statePtr);
  40. }
  41. public override unsafe float EvaluateMagnitude(void* statePtr)
  42. {
  43. ////REVIEW: this can go beyond 1; that okay?
  44. return ReadValueFromState(statePtr).magnitude;
  45. }
  46. }
  47. }