123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class MyTouch : MonoBehaviour
- {
- bool isStartouch1=true;
- bool isStartouch2=true;
- Vector2 startPos1=Vector2.zero;
- Vector2 startPos2 = Vector2.zero;
- Vector2 endPos1 = Vector2.zero;
- Vector2 endPos2 = Vector2.zero;
- public GameObject btnManager;
- float startDis = 0;
- float endDis = 0;
- public GameObject openListBtn;
- public GameObject scrollList;
- public GameObject donghuaObj;
- public GameObject imageObj;
- public GameObject rawBg;
- // Start is called before the first frame update
- void Start()
- {
- Init();
-
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.touchCount>0)
- {
- if (Input.GetTouch(0).phase == TouchPhase.Began && isStartouch1 == true)
- {
- startPos1 = Input.GetTouch(0).position;
- isStartouch1 = false;
- }
- if (Input.GetTouch(1).phase == TouchPhase.Began && isStartouch2 == true)
- {
- startPos2 = Input.GetTouch(1).position;
- isStartouch2 = false;
- }
- if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(1).phase == TouchPhase.Ended && isStartouch1 == false && isStartouch2 == false)
- {
- endPos1 = Input.GetTouch(0).position;
- endPos2 = Input.GetTouch(1).position;
- JudgeDis();
- Init();
- isStartouch1 = true;
- isStartouch2 = true;
- }
- }
-
-
-
- }
- private void Init()
- {
- Vector2 startPos1 = Vector2.zero;
- Vector2 startPos2 = Vector2.zero;
- Vector2 endPos1 = Vector2.zero;
- Vector2 endPos2 = Vector2.zero;
-
-
- }
- private void JudgeDis()
- {
- if (startPos1!=Vector2.zero && startPos2 != Vector2.zero&& endPos1 != Vector2.zero&& endPos2 != Vector2.zero)
- {
- startDis = (startPos2 - startPos1).sqrMagnitude;
- endDis = (endPos2 - endPos1).sqrMagnitude;
- if (startDis < endDis)
- {
- if (!imageObj.activeSelf)
- {
- SetActT(btnManager);
- SetActF(scrollList);
- SetActT(openListBtn);
- }
- else
- {
- SetActT(scrollList);
- SetActF(openListBtn);
- }
- }
- else
- {
- SetActF(btnManager);
- SetActF(openListBtn);
- SetActF(scrollList);
- }
- }
-
- }
- public void CloseScroll()
- {
- SetActF(scrollList);
- SetActT(openListBtn);
-
- }
- public void OpenScroll()
- {
- SetActT(scrollList);
- SetActF(openListBtn);
- SetActT(donghuaObj);
- SetActT(imageObj);
- SetActF(btnManager);
- SetActT(rawBg);
- }
- private void SetActT(GameObject obj)
- {
- if (!obj.activeSelf)
- {
- obj.SetActive(true);
- }
- }
- private void SetActF(GameObject obj)
- {
- if (obj.activeSelf)
- {
- obj.SetActive(false);
- }
- }
- private void SetActTa(GameObject[] objs)
- {
- for (int i = 0; i < objs.Length; i++)
- {
- if (!objs[i].activeSelf)
- {
- objs[i].SetActive(true);
- }
- }
- }
- private void SetActFa(GameObject[] objs)
- {
- for (int i = 0; i < objs.Length; i++)
- {
- if (objs[i].activeSelf)
- {
- objs[i].SetActive(false);
- }
- }
-
- }
-
- }
|