InputDeviceHandPartCatchEvent.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 InputDeviceHandPartCatchEvent : InputDeviceHandPartEventBase {
  10. public InputDeviceHandPartCatchEvent(InputDevicePartDispatchEventHand inputDevicePartDispatchEventHand) : base(inputDevicePartDispatchEventHand) {
  11. }
  12. enum XDirection {
  13. Release = -1,
  14. Catch = 1,
  15. }
  16. List<Vector3> HandTrendList = new List<Vector3>(new Vector3[6]);
  17. protected int currentNum = 0;
  18. protected float timer = 0;
  19. bool isForefingerCatch = false;
  20. bool isDistanceNear = false;
  21. protected override void OnUpdateEvent() {
  22. float angle;
  23. float distance = 0;
  24. //angle = Vector3.Angle(
  25. // (inputDevice26Dof.handInfo.finger[(int)FINGER.thumb].joint[(int)JOINT.Two].localPosition - inputDevice26Dof.handInfo.finger[(int)FINGER.thumb].joint[(int)JOINT.Three].localPosition),
  26. // (inputDevice26Dof.handInfo.finger[(int)FINGER.thumb].joint[(int)JOINT.Three].localPosition - inputDevice26Dof.handInfo.finger[(int)FINGER.thumb].joint[(int)JOINT.Four].localPosition));
  27. //if (angle > 20) {
  28. // isThumbCatch = true;
  29. //} else if (angle < 18) {
  30. // isThumbCatch = false;
  31. //}
  32. //DebugMy.Log(FINGER.thumb + " Angle :" + angle + ">20 ?", this,true);
  33. angle = Vector3.Angle(
  34. (handInfo.finger[(int)FINGER.forefinger].joint[(int)JOINT.Two].localPosition - handInfo.finger[(int)FINGER.forefinger].joint[(int)JOINT.Three].localPosition),
  35. (handInfo.finger[(int)FINGER.forefinger].joint[(int)JOINT.Three].localPosition - handInfo.finger[(int)FINGER.forefinger].joint[(int)JOINT.Four].localPosition));
  36. if(angle > 28) {
  37. isForefingerCatch = true;
  38. } else if(angle < 20) {
  39. isForefingerCatch = false;
  40. }
  41. //DebugMy.Log(inputDevice26Dof.PartType+" "+FINGER.forefinger + " Angle :" + angle + ">28 ?", this);
  42. distance = Vector3.Distance(handInfo.finger[(int)FINGER.forefinger].joint[(int)JOINT.One].localPosition, handInfo.finger[(int)FINGER.thumb].joint[(int)JOINT.One].localPosition);
  43. if(distance < 0.035f) {
  44. isDistanceNear = true;
  45. } else if(distance < 0.050f) {
  46. isDistanceNear = false;
  47. }
  48. if(isDistanceNear == false) {
  49. distance = Vector3.Distance(handInfo.finger[(int)FINGER.forefinger].joint[(int)JOINT.Two].localPosition, handInfo.finger[(int)FINGER.thumb].joint[(int)JOINT.Two].localPosition);
  50. if(distance < 0.035f) {
  51. isDistanceNear = true;
  52. }
  53. }
  54. //DebugMy.Log(inputDevice26Dof.PartType + " " + "distance:" + distance, this);
  55. //angle = Vector3.Angle(
  56. // (inputDevice26Dof.handInfo.finger[(int)FINGER.middle].joint[(int)JOINT.Two].localPosition - inputDevice26Dof.handInfo.finger[(int)FINGER.middle].joint[(int)JOINT.Three].localPosition),
  57. // (inputDevice26Dof.handInfo.finger[(int)FINGER.middle].joint[(int)JOINT.Three].localPosition - inputDevice26Dof.handInfo.finger[(int)FINGER.middle].joint[(int)JOINT.Four].localPosition));
  58. //if (angle > 40) {
  59. // isMiddleCatch = true;
  60. //} else if (angle < 25) {
  61. // isMiddleCatch = false;
  62. //}
  63. //DebugMy.Log(FINGER.middle + " Angle :" + angle + ">25 ?", this);
  64. //angle = Vector3.Angle(
  65. // (inputDevice26Dof.handInfo.finger[(int)FINGER.ring].joint[(int)JOINT.Two].localPosition - inputDevice26Dof.handInfo.finger[(int)FINGER.ring].joint[(int)JOINT.Three].localPosition),
  66. // (inputDevice26Dof.handInfo.finger[(int)FINGER.ring].joint[(int)JOINT.Three].localPosition - inputDevice26Dof.handInfo.finger[(int)FINGER.ring].joint[(int)JOINT.Four].localPosition));
  67. //if (angle > 40) {
  68. // isRingCatch = true;
  69. //} else if (angle < 25) {
  70. // isRingCatch = false;
  71. //}
  72. //DebugMy.Log(FINGER.ring + " Angle :" + angle + ">25 ?", this);
  73. if(isDistanceNear && isForefingerCatch) {
  74. if(previousEvent == HandEventType.CatchDown || previousEvent == HandEventType.CatchDrag) {
  75. currentEvent = HandEventType.CatchDrag;
  76. } else {
  77. currentEvent = HandEventType.CatchDown;
  78. }
  79. } else {
  80. if(previousEvent == HandEventType.CatchDown || previousEvent == HandEventType.CatchDrag) {
  81. currentEvent = HandEventType.CatchUp;
  82. } else {
  83. currentEvent = HandEventType.Null;
  84. }
  85. }
  86. previousEvent = currentEvent;
  87. //if(currentEvent != HandEventType.Null) {
  88. // DebugMy.Log(inputDeviceHandPart.PartType + " Event -----> " + currentEvent, this);
  89. //}
  90. }
  91. }
  92. }