void Update() { //Mouse bool isMouse = Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0); Touch mouseTouch = new Touch(); mouseTouch.position = Input.mousePosition; mouseTouch.phase = Input.GetMouseButton(0) ? UnityEngine.TouchPhase.Moved : mouseTouch.phase; mouseTouch.phase = Input.GetMouseButtonDown(0) ? UnityEngine.TouchPhase.Began : mouseTouch.phase; mouseTouch.phase = Input.GetMouseButtonUp(0) ? UnityEngine.TouchPhase.Ended : mouseTouch.phase; if (Input.touchCount != 1 && !isMouse && !drag.isDragging) { drag.isDragging = false; return; } Touch touch = isMouse ? mouseTouch : Input.touches[0]; if (touch.phase == TouchPhase.Began) { drag.isDragging = true; drag.localStart = drag.localEnd = touch.position; drag.timeStart = Time.time; OnDragBegan?.Invoke(drag); } if (drag.isDragging && touch.phase == TouchPhase.Moved) { drag.isDragging = true; drag.localEnd = touch.position; drag.timeEnd = Time.time; drag.DrawDebug(Color.white); OnDrag?.Invoke(drag); } if (drag.isDragging && (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)) { drag.localEnd = touch.position; drag.isDragging = false; drag.timeEnd = Time.time; drag.DrawDebug(Color.red); OnDragEnded?.Invoke(drag); } }
public void UpdateDrag() { //Mouse bool isMouse = Input.GetMouseButton(index) || Input.GetMouseButtonDown(index) || Input.GetMouseButtonUp(index); Touch mouseTouch = new Touch(); mouseTouch.position = Input.mousePosition; mouseTouch.phase = Input.GetMouseButton(index) ? UnityEngine.TouchPhase.Moved : mouseTouch.phase; mouseTouch.phase = Input.GetMouseButtonDown(index) ? UnityEngine.TouchPhase.Began : mouseTouch.phase; mouseTouch.phase = Input.GetMouseButtonUp(index) ? UnityEngine.TouchPhase.Ended : mouseTouch.phase; if (Input.touchCount != 1 && !isMouse && !isDragging) { isDragging = false; return; } Touch touch = isMouse ? mouseTouch : Input.touches[0]; if (touch.phase == TouchPhase.Began) { isDragging = true; localStart = localEnd = touch.position; OnDragBegan?.Invoke(this); } if (isDragging && touch.phase == TouchPhase.Moved) { isDragging = true; localEnd = touch.position; //drag.DrawDebug(Color.white); OnDrag?.Invoke(this); } if (isDragging && (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)) { localEnd = touch.position; isDragging = false; //drag.DrawDebug(Color.red); OnDragEnded?.Invoke(this); } }