HandMenuExample.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using TMPro;
  5. using UnityEngine;
  6. public class HandMenuExample : MonoBehaviour
  7. {
  8. public GameObject objectMenu;
  9. public Vector3 offsetCenter = new Vector3(0,0,0.05f);
  10. private Vector3 initlocalScale;
  11. TextMeshPro textMesh;
  12. int PalmFlatFaceHeadStartCount = 0;
  13. int PalmFlatFaceHeadFlatCount = 0;
  14. int PalmFlatFaceHeadMiddelFlatAndCatchCount = 0;
  15. int PalmFlatFaceHeadCatchCount = 0;
  16. int PalmFlatFaceHeadEndCount = 0;
  17. // Start is called before the first frame update
  18. void Start()
  19. {
  20. InputDeviceHandPartEventBase.eventDelegate += HandEvent;
  21. initlocalScale = objectMenu.transform.localScale;
  22. textMesh = GetComponent<TextMeshPro>();
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. }
  28. void OnDestroy() {
  29. InputDeviceHandPartEventBase.eventDelegate -= HandEvent;
  30. }
  31. void HandEvent(InputDeviceHandPart inputDeviceHandPart, HandEventType eventType, float eventPercent) {
  32. if (inputDeviceHandPart.PartType == SC.XR.Unity.Module_InputSystem.InputDevicePartType.HandLeft) {
  33. textMesh.text = "Event: ";
  34. if (eventType == HandEventType.PalmFlatFaceHeadStart) {
  35. objectMenu.transform.localScale = initlocalScale;
  36. objectMenu.SetActive(true);
  37. textMesh.text += eventType + "";
  38. PalmFlatFaceHeadStartCount++;
  39. } else if (eventType == HandEventType.PalmFlatFaceHeadFlat || eventType == HandEventType.PalmFlatFaceHeadMiddelFlatAndCatch) {
  40. objectMenu.transform.localScale = Vector3.Lerp(objectMenu.transform.localScale, initlocalScale, 0.1f);
  41. objectMenu.transform.rotation = inputDeviceHandPart.inputDataHand.handInfo.centerRotation;
  42. objectMenu.transform.position = inputDeviceHandPart.inputDataHand.handInfo.centerPosition + inputDeviceHandPart.inputDataHand.handInfo.centerRotation * offsetCenter;
  43. textMesh.text += eventType+"";
  44. if (eventType == HandEventType.PalmFlatFaceHeadFlat) {
  45. PalmFlatFaceHeadFlatCount++;
  46. } else {
  47. PalmFlatFaceHeadMiddelFlatAndCatchCount++;
  48. }
  49. } else if (eventType == HandEventType.PalmFlatFaceHeadCatch) {
  50. objectMenu.transform.rotation = inputDeviceHandPart.inputDataHand.handInfo.centerRotation;
  51. objectMenu.transform.position = inputDeviceHandPart.inputDataHand.handInfo.centerPosition + inputDeviceHandPart.inputDataHand.handInfo.centerRotation * offsetCenter;
  52. objectMenu.transform.localScale = Vector3.Lerp(objectMenu.transform.localScale, initlocalScale*0.2f, 0.1f);
  53. textMesh.text += eventType + "";
  54. PalmFlatFaceHeadCatchCount++;
  55. } else if (eventType == HandEventType.PalmFlatFaceHeadEnd) {
  56. objectMenu.SetActive(false);
  57. objectMenu.transform.localScale = initlocalScale;
  58. textMesh.text += eventType + "";
  59. PalmFlatFaceHeadEndCount++;
  60. }
  61. textMesh.text += "\nPalmFlatFaceHeadStartCount " + PalmFlatFaceHeadStartCount +
  62. "\nPalmFlatFaceHeadFlatCount " + PalmFlatFaceHeadFlatCount +
  63. "\nPalmFlatFaceHeadMiddelFlatAndCatchCount " + PalmFlatFaceHeadMiddelFlatAndCatchCount +
  64. "\nPalmFlatFaceHeadCatchCount " + PalmFlatFaceHeadCatchCount +
  65. "\nPalmFlatFaceHeadEndCount " + PalmFlatFaceHeadEndCount;
  66. }
  67. }
  68. }