void Update() { if (!EnableInput) { return; } #if UNITY_EDITOR || UNITY_STANDALONE_WIN if (!m_IsMouseDown && Input.GetMouseButton(0)) { m_IsMouseDown = true; Vector2 mp = new Vector2(Input.mousePosition.x, Input.mousePosition.y); m_TouchBeganPoints[0] = mp; if (OnTouchBegan != null) { OnTouchBegan(this, new TouchEventArgs(Input.mousePosition, mp)); } } else if (m_IsMouseDown) { if (Input.GetMouseButton(0)) { Vector2 mp = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if (OnTouchMoved != null) { OnTouchMoved(this, new TouchEventArgs(m_TouchBeganPoints[0], mp)); } } else { Vector2 mp = new Vector2(Input.mousePosition.x, Input.mousePosition.y); m_IsMouseDown = false; TouchEventArgs eventArgs = new TouchEventArgs(m_TouchBeganPoints[0], mp); if (OnTouchEnded != null) { OnTouchEnded(this, eventArgs); } if ((m_TouchBeganPoints[0] - mp).magnitude < 25) { if (OnTap != null) { OnTap(this, eventArgs); } } else { if (OnSlide != null) { OnSlide(this, new SlideEventArgs(m_TouchBeganPoints[0], mp)); } } } } #else int count = Input.touchCount; if (count == 0) { return; } for (int i = 0; i < count; ++i) { Touch touch = Input.GetTouch(i); int id = touch.fingerId; if (count == 1 && id == 0) { if (touch.phase == TouchPhase.Began) { m_TouchBeganPoints[0] = touch.position; if (OnTouchBegan != null) { OnTouchBegan(this, new TouchEventArgs(touch.position, touch.position)); } } else if (touch.phase == TouchPhase.Moved) { if (OnTouchMoved != null) { OnTouchMoved(this, new TouchEventArgs(m_TouchBeganPoints[0], touch.position)); } } else if (touch.phase == TouchPhase.Ended) { TouchEventArgs eventArgs = new TouchEventArgs(m_TouchBeganPoints[0], touch.position); if (OnTouchEnded != null) { OnTouchEnded(this, eventArgs); } if ((m_TouchBeganPoints[0] - touch.position).magnitude < 25) { if (OnTap != null) { OnTap(this, eventArgs); } } else { SlideEventArgs slideEventArgs = new SlideEventArgs(m_TouchBeganPoints[0], touch.position); if (OnSlide != null) { OnSlide(this, slideEventArgs); } } } } } #endif }
private void Gesture_OnSlide(object sender, SlideEventArgs e) { Debug.LogFormat("Gesture - OnSlide : {0}", e.SlideType); }