MyTouch.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class MyTouch : MonoBehaviour
  6. {
  7. bool isStartouch1=true;
  8. bool isStartouch2=true;
  9. Vector2 startPos1=Vector2.zero;
  10. Vector2 startPos2 = Vector2.zero;
  11. Vector2 endPos1 = Vector2.zero;
  12. Vector2 endPos2 = Vector2.zero;
  13. public GameObject btnManager;
  14. float startDis = 0;
  15. float endDis = 0;
  16. public GameObject openListBtn;
  17. public GameObject scrollList;
  18. public GameObject donghuaObj;
  19. public GameObject imageObj;
  20. public GameObject rawBg;
  21. // Start is called before the first frame update
  22. void Start()
  23. {
  24. Init();
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. if (Input.touchCount>0)
  30. {
  31. if (Input.GetTouch(0).phase == TouchPhase.Began && isStartouch1 == true)
  32. {
  33. startPos1 = Input.GetTouch(0).position;
  34. isStartouch1 = false;
  35. }
  36. if (Input.GetTouch(1).phase == TouchPhase.Began && isStartouch2 == true)
  37. {
  38. startPos2 = Input.GetTouch(1).position;
  39. isStartouch2 = false;
  40. }
  41. if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(1).phase == TouchPhase.Ended && isStartouch1 == false && isStartouch2 == false)
  42. {
  43. endPos1 = Input.GetTouch(0).position;
  44. endPos2 = Input.GetTouch(1).position;
  45. JudgeDis();
  46. Init();
  47. isStartouch1 = true;
  48. isStartouch2 = true;
  49. }
  50. }
  51. }
  52. private void Init()
  53. {
  54. Vector2 startPos1 = Vector2.zero;
  55. Vector2 startPos2 = Vector2.zero;
  56. Vector2 endPos1 = Vector2.zero;
  57. Vector2 endPos2 = Vector2.zero;
  58. }
  59. private void JudgeDis()
  60. {
  61. if (startPos1!=Vector2.zero && startPos2 != Vector2.zero&& endPos1 != Vector2.zero&& endPos2 != Vector2.zero)
  62. {
  63. startDis = (startPos2 - startPos1).sqrMagnitude;
  64. endDis = (endPos2 - endPos1).sqrMagnitude;
  65. if (startDis < endDis)
  66. {
  67. if (!imageObj.activeSelf)
  68. {
  69. SetActT(btnManager);
  70. SetActF(scrollList);
  71. SetActT(openListBtn);
  72. }
  73. else
  74. {
  75. SetActT(scrollList);
  76. SetActF(openListBtn);
  77. }
  78. }
  79. else
  80. {
  81. SetActF(btnManager);
  82. SetActF(openListBtn);
  83. SetActF(scrollList);
  84. }
  85. }
  86. }
  87. public void CloseScroll()
  88. {
  89. SetActF(scrollList);
  90. SetActT(openListBtn);
  91. }
  92. public void OpenScroll()
  93. {
  94. SetActT(scrollList);
  95. SetActF(openListBtn);
  96. SetActT(donghuaObj);
  97. SetActT(imageObj);
  98. SetActF(btnManager);
  99. SetActT(rawBg);
  100. }
  101. private void SetActT(GameObject obj)
  102. {
  103. if (!obj.activeSelf)
  104. {
  105. obj.SetActive(true);
  106. }
  107. }
  108. private void SetActF(GameObject obj)
  109. {
  110. if (obj.activeSelf)
  111. {
  112. obj.SetActive(false);
  113. }
  114. }
  115. private void SetActTa(GameObject[] objs)
  116. {
  117. for (int i = 0; i < objs.Length; i++)
  118. {
  119. if (!objs[i].activeSelf)
  120. {
  121. objs[i].SetActive(true);
  122. }
  123. }
  124. }
  125. private void SetActFa(GameObject[] objs)
  126. {
  127. for (int i = 0; i < objs.Length; i++)
  128. {
  129. if (objs[i].activeSelf)
  130. {
  131. objs[i].SetActive(false);
  132. }
  133. }
  134. }
  135. }