public void ResetInputState() { for (int j = 0; j < 5; j++) { TouchInfo touch = _touches[j]; touch.Reset(); } if (!touchScreen) { _touches[0].touchId = 0; } }
void HandleTouchEvents() { int tc = Input.touchCount; for (int i = 0; i < tc; ++i) { Touch uTouch = Input.GetTouch(i); if (uTouch.phase == TouchPhase.Stationary) { continue; } Vector2 pos = uTouch.position; pos.y = stageHeight - pos.y; TouchInfo touch = null; for (int j = 0; j < 5; j++) { if (_touches[j].touchId == uTouch.fingerId) { touch = _touches[j]; break; } } if (touch == null) { continue; } if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); //no rollover/rollout on mobile } if (uTouch.phase == TouchPhase.Began) { if (!touch.began) { _touchCount++; touch.begin(); this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended) { if (touch.began) { _touchCount--; touch.end(); DisplayObject clickTarget = touch.ClickTest(); if (clickTarget != null) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); clickTarget.onClick.BubbleCall(touch.evt); } } touch.Reset(); } } }
void HandleTouchEvents() { for (int i = 0; i < Input.touchCount; ++i) { Touch uTouch = Input.GetTouch(i); if (uTouch.phase == TouchPhase.Stationary) { continue; } Vector2 pos = uTouch.position; pos.y = stageHeight - pos.y; TouchInfo touch = null; for (int j = 0; j < 5; j++) { if (_touches[j].touchId == uTouch.fingerId) { touch = _touches[j]; break; } } if (touch == null) { continue; } if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); //no rollover/rollout on mobile } if (uTouch.phase == TouchPhase.Began) { if (!touch.began) { touch.began = true; _touchCount++; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended) { if (touch.began) { touch.began = false; _touchCount--; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchEnd.BubbleCall(touch.evt); if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 50 && Mathf.Abs(touch.y - touch.downY) < 50) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); touch.target.onClick.BubbleCall(touch.evt); } } } touch.Reset(); } } }
void HandleTouchEvents() { for (int i = 0; i < Input.touchCount; ++i) { Touch uTouch = Input.GetTouch(i); if (uTouch.phase == TouchPhase.Stationary) { continue; } bool hitTested = false; Vector2 touchPosition = uTouch.position; touchPosition.y = stageHeight - touchPosition.y; TouchInfo touch = null; for (int j = 0; j < 5; j++) { if (_touches[j].touchId == uTouch.fingerId) { touch = _touches[j]; break; } if (_touches[j].touchId == -1) { touch = _touches[j]; } } if (touch == null) { continue; } touch.touchId = uTouch.fingerId; mouseX = touchPosition.x; mouseY = touchPosition.y; if (touch.x != mouseX || touch.y != mouseY) { touch.x = mouseX; touch.y = mouseY; _objectUnderMouse = HitTest(touchPosition, true); hitTested = true; touch.target = _objectUnderMouse; touch.UpdateEvent(); onMouseMove.Call(touch.evt); //no rollover/rollout on mobile //if (evt.lastRollOver != _objectUnderMouse) //HandleRollOver(evt); } if (uTouch.phase == TouchPhase.Began) { if (!touch.began) { touch.began = true; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; if (!hitTested) { _objectUnderMouse = HitTest(touchPosition, true); hitTested = true; touch.target = _objectUnderMouse; } this.focus = _objectUnderMouse; if (_objectUnderMouse != null) { touch.UpdateEvent(); _objectUnderMouse.onMouseDown.BubbleCall(touch.evt); } } } else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended) { if (touch.began) { touch.began = false; if (!hitTested) { _objectUnderMouse = HitTest(touchPosition, true); hitTested = true; touch.target = _objectUnderMouse; } if (_objectUnderMouse != null) { touch.UpdateEvent(); _objectUnderMouse.onMouseUp.BubbleCall(touch.evt); if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 50 && Mathf.Abs(touch.y - touch.downY) < 50) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); _objectUnderMouse.onClick.BubbleCall(touch.evt); } } } touch.Reset(); } } }