InputDeviceGGT26DofPartStatus.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. namespace SC.XR.Unity.Module_InputSystem.InputDeviceHand.GGT26Dof {
  8. public class InputDeviceGGT26DofPartStatus : InputDeviceHandPartStatus {
  9. public InputDeviceGGT26DofPart inputDeviceGGT26DofPart;
  10. public InputDeviceGGT26DofPartStatus(InputDeviceGGT26DofPart _inputDeviceHandPart) : base(_inputDeviceHandPart) {
  11. inputDeviceGGT26DofPart = _inputDeviceHandPart;
  12. }
  13. float timer = 0;
  14. static bool isUpdateDataThisFrame = false;
  15. static bool ISGCPriorityGGT26Dof=false;
  16. public override void OnSCAwake() {
  17. base.OnSCAwake();
  18. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "ISGCPriorityGGT26Dof")) {
  19. ISGCPriorityGGT26Dof = API_Module_SDKConfiguration.GetBool("Module_InputSystem", "ISGCPriorityGGT26Dof", 1);
  20. DebugMy.Log("ISGCPriorityGGT26Dof:"+ ISGCPriorityGGT26Dof,this,true);
  21. }
  22. }
  23. public override void OnSCLateUpdate() {
  24. base.OnSCLateUpdate();
  25. ///每帧只执行一次
  26. if (isUpdateDataThisFrame == false) {
  27. isUpdateDataThisFrame = true;
  28. UpdateStatus(InputDataGGT26Dof.handsInfo.originDataMode, InputDataGGT26Dof.handsInfo.originDataPose);
  29. }
  30. if (inputDeviceGGT26DofPart.PartType == InputDevicePartType.HandLeft) {
  31. inputDeviceGGT26DofPart.inputDataGGT26Dof.isFound = InputDataGGT26Dof.handsInfo.handLeftFind;
  32. if (inputDeviceGGT26DofPart.inputDeviceGGT26Dof.LeftHandOpen == false) {
  33. inputDeviceGGT26DofPart.inputDataGGT26Dof.isFound = false;
  34. }
  35. }
  36. if (inputDeviceGGT26DofPart.PartType == InputDevicePartType.HandRight) {
  37. inputDeviceGGT26DofPart.inputDataGGT26Dof.isFound = InputDataGGT26Dof.handsInfo.handRightFind;
  38. if (inputDeviceGGT26DofPart.inputDeviceGGT26Dof.RightHandOpen == false) {
  39. inputDeviceGGT26DofPart.inputDataGGT26Dof.isFound = false;
  40. }
  41. }
  42. //if (inputDeviceHandPart.inputDataHand.isFound == false) {
  43. // timer += Time.deltaTime;
  44. // inputDeviceHandPart.inputDataHand.handInfo.lostPercent = timer / inputDeviceHandPart.inputDataHand.handInfo.lostTimer;
  45. // if (inputDeviceHandPart.inputDataHand.handInfo.lostPercent >= 1) {
  46. // inputDeviceHandPart.inputDataHand.handInfo.lostPercent = 1;
  47. // inputDeviceHandPart.inputDataHand.handInfo.isLost = true;
  48. // }
  49. // ///hand都是多少百分比后将手势值设为复位值,以触发UP事件(如果已经Down或者Drag后)
  50. // //if(inputDeviceHandPart.inputDataHand.handInfo.lostPercent > 0.90f) {
  51. // // //Debug.Log("========= lost > 80 :" + inputDeviceHandPart.PartType);
  52. // // inputDeviceHandPart.inputDataHand.ResetHandData(inputDeviceHandPart.PartType);
  53. // //}
  54. //} else {
  55. // timer = 0;
  56. // inputDeviceHandPart.inputDataHand.handInfo.lostPercent = 0;
  57. // inputDeviceHandPart.inputDataHand.handInfo.isLost = false;
  58. //}
  59. inputDeviceHandPart.inputDataHand.handInfo.isLost = !inputDeviceHandPart.inputDataHand.isFound;
  60. if (inputDeviceHandPart.inputDataHand.handInfo.isLost) {
  61. inputDeviceHandPart.inputDataBase.isVaild = false;
  62. //DebugMy.Log("Hand:" + inputDeviceHandPart.PartType + " Status: DisActive !", this);
  63. } else {
  64. inputDeviceHandPart.inputDataBase.isVaild = true;
  65. //DebugMy.Log("Hand:" + inputDeviceHandPart.PartType + " Status: Active", this);
  66. }
  67. if (ISGCPriorityGGT26Dof == true) {
  68. //if (API_Module_InputSystem.InputDeviceStatus(InputDeviceType.KS) || API_Module_InputSystem.InputDeviceStatus(InputDeviceType.BT3Dof)) {
  69. // inputDeviceHandPart.inputDataBase.isVaild = false;
  70. //}
  71. if (API_GSXR_Module_InputSystem.GSXR_InputDeviceStatus(InputDeviceType.KS) || API_GSXR_Module_InputSystem.GSXR_InputDeviceStatus(InputDeviceType.BT3Dof))
  72. {
  73. inputDeviceHandPart.inputDataBase.isVaild = false;
  74. }
  75. }
  76. }
  77. public override void OnSCFuncitonWaitForEndOfFrame() {
  78. base.OnSCFuncitonWaitForEndOfFrame();
  79. isUpdateDataThisFrame = false;
  80. }
  81. /// <summary>
  82. /// every frame invoke once
  83. /// </summary>
  84. /// <param name="mode"></param>
  85. /// <param name="pose"></param>
  86. /// <returns></returns>
  87. protected virtual void UpdateStatus(float[] mode, float[] pose) {
  88. ///识别到手的个数
  89. InputDataGGT26Dof.handsInfo.handAmount = (int)mode[0];
  90. ///0代表不知左右
  91. ///1代表左
  92. ///2代表右
  93. ///可以同时0或1或2,此时舍去一个
  94. ///
  95. if ((int)mode[0] == 0) {
  96. InputDataGGT26Dof.handsInfo.handLeftFind = false;
  97. InputDataGGT26Dof.handsInfo.handRightFind = false;
  98. } else if ((int)mode[0] == 1) {
  99. if ((int)(mode[1]) == 1) {
  100. InputDataGGT26Dof.handsInfo.handLeftFind = true;
  101. InputDataGGT26Dof.handsInfo.handRightFind = false;
  102. InputDataGGT26Dof.handsInfo.handLeftIndex = 0;
  103. } else if ((int)(mode[1]) == 2) {
  104. InputDataGGT26Dof.handsInfo.handLeftFind = false;
  105. InputDataGGT26Dof.handsInfo.handRightFind = true;
  106. InputDataGGT26Dof.handsInfo.handRighIndex = 0;
  107. }
  108. } else if ((int)mode[0] == 2) {
  109. if ((int)(mode[1]) == 1 && (int)(mode[3 + 63]) == 2) {
  110. InputDataGGT26Dof.handsInfo.handLeftFind = true;
  111. InputDataGGT26Dof.handsInfo.handRightFind = true;
  112. InputDataGGT26Dof.handsInfo.handLeftIndex = 0;
  113. InputDataGGT26Dof.handsInfo.handRighIndex = 1;
  114. }
  115. }
  116. if (Application.platform != RuntimePlatform.Android) {
  117. InputDataGGT26Dof.handsInfo.handLeftFind = true;
  118. InputDataGGT26Dof.handsInfo.handRightFind = true;
  119. InputDataGGT26Dof.handsInfo.handRighIndex = 0;
  120. InputDataGGT26Dof.handsInfo.handRighIndex = 1;
  121. ///按K键左手丢失
  122. if (Input.GetKey(KeyCode.O) == true) {
  123. InputDataGGT26Dof.handsInfo.handLeftFind = false;
  124. }
  125. ///按L键右手丢失
  126. if (Input.GetKey(KeyCode.P) == true) {
  127. InputDataGGT26Dof.handsInfo.handRightFind = false;
  128. }
  129. }
  130. if (InputDataGGT26Dof.handsInfo.handLeftFind) {
  131. InputDataGGT26Dof.handsInfo.handLeft.findFrameCount++;
  132. } else if (InputDataGGT26Dof.handsInfo.handLeftFind == false) {
  133. InputDataGGT26Dof.handsInfo.handLeft.findFrameCount = 0;
  134. }
  135. if (InputDataGGT26Dof.handsInfo.handRightFind) {
  136. InputDataGGT26Dof.handsInfo.handRight.findFrameCount++;
  137. } else if (InputDataGGT26Dof.handsInfo.handRightFind == false) {
  138. InputDataGGT26Dof.handsInfo.handRight.findFrameCount = 0;
  139. }
  140. if (InputDataGGT26Dof.handsInfo.handLeft.findFrameCount > InputDataGGT26Dof.handsInfo.handLeft.frameCountValid) {
  141. InputDataGGT26Dof.handsInfo.handLeftFind = true;
  142. } else if (InputDataGGT26Dof.handsInfo.handLeft.isLost) {
  143. InputDataGGT26Dof.handsInfo.handLeftFind = false;
  144. }
  145. if (InputDataGGT26Dof.handsInfo.handRight.findFrameCount > InputDataGGT26Dof.handsInfo.handRight.frameCountValid) {
  146. InputDataGGT26Dof.handsInfo.handRightFind = true;
  147. } else if (InputDataGGT26Dof.handsInfo.handRight.isLost) {
  148. InputDataGGT26Dof.handsInfo.handRightFind = false;
  149. }
  150. }
  151. }
  152. }