InputDeviceGCPartEventSliderLeftRight.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.InputDeviceGC {
  8. public class InputDeviceGCPartEventSliderLeftRight : InputDeviceGCPartEventBase {
  9. InputDevicePartDispatchEventGC inputDevicePartDispatchEventGC;
  10. public InputDeviceGCPartEventSliderLeftRight(InputDevicePartDispatchEventGC inputDevicePartDispatchEventGC) : base(inputDevicePartDispatchEventGC) {
  11. this.inputDevicePartDispatchEventGC = inputDevicePartDispatchEventGC;
  12. noise = 12;
  13. effect = 3;
  14. samplingTime = 0.03f;
  15. }
  16. enum XDirection {
  17. Left = -1,
  18. Right = 1,
  19. }
  20. List<Vector2> TouchTrendList = new List<Vector2>(new Vector2[6]);
  21. int DirectionResult = 0;
  22. int currentNum = 0;
  23. float timer = 0;
  24. protected override void DispatchEventTarget() {
  25. }
  26. protected override void OnUpdateEvent() {
  27. currentEvent = GCEventType.Null;
  28. timer += Time.deltaTime;
  29. if(timer >= samplingTime) {
  30. timer = 0;
  31. if(inputDevicePartDispatchEventGC.inputDeviceGCPart.inputDataGC.isTpTouch == true) {
  32. TouchTrendList[currentNum] = inputDevicePartDispatchEventGC.inputDeviceGCPart.inputDataGC.tpPosition;
  33. } else {
  34. TouchTrendList[currentNum] = Vector2.zero;
  35. }
  36. //int j = 0;
  37. //DebugMy.Log("trendList * 1000 =========== " + TouchTrendList[currentNum] * 1000 + " ==========", this);
  38. //foreach(var trend in TouchTrendList) {
  39. // if(currentNum == j) {
  40. // DebugMy.Log("trendList * 1000:[" + j++ + "]:" + trend * 1000 + "<===", this);
  41. // } else {
  42. // DebugMy.Log("trendList * 1000:[" + j++ + "]:" + trend * 1000, this);
  43. // }
  44. //}
  45. DirectionResult = 0;
  46. for(int i = TouchTrendList.Count - 1; i >= 0; i--) {
  47. if(TouchTrendList[i].x > (TouchTrendList[((i - 1) < 0) ? TouchTrendList.Count - 1 : i - 1].x + noise)) {
  48. DirectionResult += (int)XDirection.Right;
  49. //DebugMy.Log(" " + XDirection.Right + " " + DirectionResult, this);
  50. } else if((TouchTrendList[i].x + noise) < TouchTrendList[((i - 1) < 0) ? TouchTrendList.Count - 1 : i - 1].x) {
  51. DirectionResult += (int)XDirection.Left;
  52. //DebugMy.Log(" " + XDirection.Left + " " + DirectionResult, this);
  53. }
  54. //Debug.Log("xxxx:: "+ i+"::"+(((i - 1) < 0) ? HandTrendList.Count - 1 : i - 1));
  55. }
  56. ///此log可用于查看noise大小,正常手不动DirectionResult为0,当不为0时,调大 noise
  57. //DebugMy.Log("Noise ----- ----- X---:" + DirectionResult, this);
  58. if(DirectionResult >= effect) {
  59. //DebugMy.Log("Event ----- ----- TouchSildeRight---", this);
  60. for(int i = 0; i < TouchTrendList.Count; i++) {
  61. TouchTrendList[i] = Vector3.zero;
  62. }
  63. currentEvent = GCEventType.TouchSlideRight;
  64. } else if(DirectionResult <= -effect) {
  65. //DebugMy.Log("Event ----- ----- TouchSildeLeft ---", this);
  66. for(int i = 0; i < TouchTrendList.Count; i++) {
  67. TouchTrendList[i] = Vector3.zero;
  68. }
  69. currentEvent = GCEventType.TouchSlideLeft;
  70. }
  71. currentNum++;
  72. if(currentNum == TouchTrendList.Count) {
  73. currentNum = 0;
  74. }
  75. }
  76. }
  77. }
  78. }