InputDeviceGCPartEventSliderUpDown.cs 3.8 KB

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