TestActionBaseInput.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SpatialTracking;
  5. using Ximmerse.XR.Utils;
  6. using System.Text;
  7. using UnityEngine.XR.Interaction.Toolkit;
  8. using UnityEngine.XR;
  9. using UnityEngine.InputSystem;
  10. namespace Ximmerse.XR.tests
  11. {
  12. /// <summary>
  13. /// Action base input test script.
  14. /// </summary>
  15. public class TestActionBaseInput : MonoBehaviour
  16. {
  17. public ActionBasedController left, right;
  18. StringBuilder leftHandMsg = new StringBuilder();
  19. StringBuilder rightHandMsg = new StringBuilder();
  20. InputActionProperty[] leftActions, leftActionValues;
  21. InputActionProperty[] rightActions, rightActionValues;
  22. // Start is called before the first frame update
  23. void Start()
  24. {
  25. leftActions = new InputActionProperty[]
  26. {
  27. left.selectAction, left.selectAction, left.uiPressAction,
  28. };
  29. leftActionValues = new InputActionProperty[]
  30. {
  31. left.selectActionValue, left.activateActionValue, left.uiPressActionValue,
  32. };
  33. rightActions = new InputActionProperty[]
  34. {
  35. right.selectAction, right.selectAction, right.uiPressAction,
  36. };
  37. rightActionValues = new InputActionProperty[]
  38. {
  39. right.selectActionValue, right.activateActionValue, right.uiPressActionValue,
  40. };
  41. }
  42. // Update is called once per frame
  43. void Update()
  44. {
  45. leftHandMsg.Clear();
  46. foreach (var a in leftActions)
  47. {
  48. if (a.action.IsPressed())
  49. {
  50. leftHandMsg.AppendFormat(" {0} ", a.action.name);
  51. }
  52. }
  53. foreach (var a in leftActionValues)
  54. {
  55. if (a.action.IsPressed())
  56. {
  57. leftHandMsg.AppendFormat("\r\n {0} = {1}", a.action.name, a.action.ReadValue<float>());
  58. }
  59. }
  60. rightHandMsg.Clear();
  61. foreach (var a in rightActions)
  62. {
  63. if (a.action.IsPressed())
  64. {
  65. rightHandMsg.AppendFormat(" {0} ", a.action.name);
  66. }
  67. }
  68. foreach (var a in rightActionValues)
  69. {
  70. if (a.action.IsPressed())
  71. {
  72. rightHandMsg.AppendFormat("\r\n {0} = {1}", a.action.name, a.action.ReadValue<float>());
  73. }
  74. }
  75. if (leftHandMsg.Length > 0)
  76. {
  77. Matrix4x4 world = Matrix4x4.TRS(left.transform.position, left.transform.rotation, Vector3.one);
  78. RxDraw.Text3D(world.GetColumn(3), Quaternion.LookRotation(Camera.main.transform.forward), 0.01f, leftHandMsg.ToString(), Color.green);
  79. }
  80. if (rightHandMsg.Length > 0)
  81. {
  82. Matrix4x4 world = Matrix4x4.TRS(right.transform.position, right.transform.rotation, Vector3.one);
  83. RxDraw.Text3D(world.GetColumn(3), Quaternion.LookRotation(Camera.main.transform.forward), 0.01f, rightHandMsg.ToString(), Color.green);
  84. }
  85. }
  86. }
  87. }