InputDeviceHandPartFaceFlatHead.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. namespace SC.XR.Unity.Module_InputSystem.InputDeviceHand {
  9. public class InputDeviceHandPartFaceFlatHead : InputDeviceHandPartEventBase {
  10. public float faceAngle = 60;
  11. public InputDeviceHandPartFaceFlatHead(InputDevicePartDispatchEventHand inputDevicePartDispatchEventHand) : base(inputDevicePartDispatchEventHand) {
  12. }
  13. public override void OnSCStart() {
  14. base.OnSCStart();
  15. previousEvent = currentEvent = HandEventType.Null;
  16. EventPercent = 0;
  17. }
  18. public float forefingerAngle = 0;
  19. public float middleAngle = 0;
  20. public float ringAngle = 0;
  21. protected override void OnUpdateEvent() {
  22. currentEvent = HandEventType.Null;
  23. if (API_GSXR_Slam.SlamManager && Camera.main.transform) {
  24. if (Vector3.Angle(handInfo.normal, Camera.main.transform.up) <= 60
  25. ||
  26. Vector3.Angle(handInfo.normal, Camera.main.transform.position - inputDeviceHandPart.inputDataHand.handInfo.centerPosition) < 60
  27. ) {
  28. forefingerAngle = Vector3.Angle((handInfo.GetJoint(FINGER.forefinger, JOINT.Two).localPosition - handInfo.GetJoint(FINGER.forefinger, JOINT.Three).localPosition),
  29. (handInfo.GetJoint(FINGER.forefinger, JOINT.Three).localPosition - handInfo.GetJoint(FINGER.forefinger, JOINT.Four).localPosition));
  30. middleAngle = Vector3.Angle((handInfo.GetJoint(FINGER.middle, JOINT.Two).localPosition - handInfo.GetJoint(FINGER.middle, JOINT.Three).localPosition),
  31. (handInfo.GetJoint(FINGER.middle, JOINT.Three).localPosition - handInfo.GetJoint(FINGER.middle, JOINT.Four).localPosition));
  32. ringAngle = Vector3.Angle((handInfo.GetJoint(FINGER.ring, JOINT.Two).localPosition - handInfo.GetJoint(FINGER.ring, JOINT.Three).localPosition),
  33. (handInfo.GetJoint(FINGER.ring, JOINT.Three).localPosition - handInfo.GetJoint(FINGER.ring, JOINT.Four).localPosition));
  34. //DebugMy.Log(inputDeviceHandPart.PartType + "Event Angle forefingerAngle:" + forefingerAngle + " " + middleAngle + " " + ringAngle, this, true);
  35. if (forefingerAngle < 25 && middleAngle < 25 && ringAngle < 25) {
  36. if (previousEvent == HandEventType.PalmFlatFaceHeadFlat ||
  37. previousEvent == HandEventType.PalmFlatFaceHeadCatch ||
  38. previousEvent == HandEventType.PalmFlatFaceHeadStart ||
  39. previousEvent == HandEventType.PalmFlatFaceHeadMiddelFlatAndCatch) {
  40. currentEvent = HandEventType.PalmFlatFaceHeadFlat;
  41. } else {
  42. currentEvent = HandEventType.PalmFlatFaceHeadStart;
  43. }
  44. } else if (forefingerAngle > 60 && middleAngle > 60 && ringAngle > 60) {
  45. if (previousEvent == HandEventType.PalmFlatFaceHeadFlat ||
  46. previousEvent == HandEventType.PalmFlatFaceHeadCatch ||
  47. previousEvent == HandEventType.PalmFlatFaceHeadStart ||
  48. previousEvent == HandEventType.PalmFlatFaceHeadMiddelFlatAndCatch) {
  49. currentEvent = HandEventType.PalmFlatFaceHeadCatch;
  50. }
  51. } else {
  52. if (previousEvent == HandEventType.PalmFlatFaceHeadFlat ||
  53. previousEvent == HandEventType.PalmFlatFaceHeadCatch ||
  54. previousEvent == HandEventType.PalmFlatFaceHeadStart ||
  55. previousEvent == HandEventType.PalmFlatFaceHeadMiddelFlatAndCatch) {
  56. currentEvent = HandEventType.PalmFlatFaceHeadMiddelFlatAndCatch;
  57. }
  58. }
  59. } else {
  60. if (previousEvent == HandEventType.PalmFlatFaceHeadFlat ||
  61. previousEvent == HandEventType.PalmFlatFaceHeadCatch ||
  62. previousEvent == HandEventType.PalmFlatFaceHeadStart ||
  63. previousEvent == HandEventType.PalmFlatFaceHeadMiddelFlatAndCatch) {
  64. currentEvent = HandEventType.PalmFlatFaceHeadEnd;
  65. }else {
  66. currentEvent = HandEventType.Null;
  67. }
  68. }
  69. }
  70. previousEvent = currentEvent;
  71. //if (currentEvent != HandEventType.Null) {
  72. // DebugMy.Log(inputDeviceHandPart.PartType + " Event -----> " + currentEvent + " " + EventPercent, this, true);
  73. //}
  74. }
  75. public override void OnSCDisable() {
  76. if (previousEvent == HandEventType.PalmFlatFaceHeadFlat ||
  77. previousEvent == HandEventType.PalmFlatFaceHeadCatch ||
  78. previousEvent == HandEventType.PalmFlatFaceHeadStart ||
  79. previousEvent == HandEventType.PalmFlatFaceHeadMiddelFlatAndCatch
  80. ) {
  81. currentEvent = HandEventType.PalmFlatFaceHeadEnd;
  82. }
  83. EventPercent = 0;
  84. base.OnSCDisable();
  85. }
  86. }
  87. }