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) { touch.began = true; _touchCount++; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; touch.downTarget = touch.target; 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.CallTouchEnd(); } DisplayObject clickTarget = clickTest(touch); if (clickTarget != null) { touch.clickCount = uTouch.tapCount; touch.UpdateEvent(); clickTarget.onClick.BubbleCall(touch.evt); } } touch.Reset(); } } }
void HandleCustomInput() { Vector2 pos = _customInputPos; pos.y = stageHeight - pos.y; TouchInfo touch = _touches[0]; if (touch.x != pos.x || touch.y != pos.y) { touch.x = pos.x; touch.y = pos.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (_customInputButtonDown) { if (!touch.began) { touch.began = true; _touchCount = 1; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; touch.downTarget = touch.target; this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } else if (touch.began) { touch.began = false; _touchCount = 0; if (touch.target != null) { touch.UpdateEvent(); touch.CallTouchEnd(); DisplayObject clickTarget = clickTest(touch); if (clickTarget != null) { if (Time.realtimeSinceStartup - touch.lastClickTime < 0.35f) { if (touch.clickCount == 2) { touch.clickCount = 1; } else { touch.clickCount++; } } else { touch.clickCount = 1; } touch.lastClickTime = Time.realtimeSinceStartup; touch.UpdateEvent(); clickTarget.onClick.BubbleCall(touch.evt); } } } }
void HandleMouseEvents() { TouchInfo touch = _touches[0]; if (touch.x != _touchPosition.x || touch.y != _touchPosition.y) { touch.x = _touchPosition.x; touch.y = _touchPosition.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2)) { if (!touch.began) { touch.began = true; _touchCount = 1; touch.clickCancelled = false; touch.downX = touch.x; touch.downY = touch.y; touch.downTarget = touch.target; touch.button = Input.GetMouseButtonDown(2) ? 2 : (Input.GetMouseButtonDown(1) ? 1 : 0); this.focus = touch.target; if (touch.target != null) { touch.UpdateEvent(); touch.target.onTouchBegin.BubbleCall(touch.evt); } } } if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2)) { if (touch.began) { touch.began = false; _touchCount = 0; if (touch.target != null) { touch.UpdateEvent(); touch.CallTouchEnd(); } DisplayObject clickTarget = clickTest(touch); if (clickTarget != null) { if (Time.realtimeSinceStartup - touch.lastClickTime < 0.35f) { if (touch.clickCount == 2) { touch.clickCount = 1; } else { touch.clickCount++; } } else { touch.clickCount = 1; } touch.lastClickTime = Time.realtimeSinceStartup; touch.UpdateEvent(); if (Input.GetMouseButtonUp(1)) { clickTarget.onRightClick.BubbleCall(touch.evt); } else { clickTarget.onClick.BubbleCall(touch.evt); } } } } }
void HandleMouseEvents() { TouchInfo touch = _touches[0]; if (touch.x != _touchPosition.x || touch.y != _touchPosition.y) { touch.x = _touchPosition.x; touch.y = _touchPosition.y; touch.UpdateEvent(); onTouchMove.Call(touch.evt); if (touch.lastRollOver != touch.target) { HandleRollOver(touch); } } if (Input.GetMouseButtonDown(0)) { 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); } } } if (Input.GetMouseButtonUp(0)) { if (touch.began) { touch.began = false; _touchCount--; if (touch.target != null) { touch.UpdateEvent(); touch.CallTouchEnd(); if (!touch.clickCancelled && Mathf.Abs(touch.x - touch.downX) < 50 && Mathf.Abs(touch.y - touch.downY) < 50) { if (Time.realtimeSinceStartup - touch.lastClickTime < 0.35f) { if (touch.clickCount == 2) { touch.clickCount = 1; } else { touch.clickCount++; } } else { touch.clickCount = 1; } touch.lastClickTime = Time.realtimeSinceStartup; touch.UpdateEvent(); touch.target.onClick.BubbleCall(touch.evt); } } } } if (Input.GetMouseButtonUp(1)) { if (touch.target != null) { touch.UpdateEvent(); touch.target.onRightClick.BubbleCall(touch.evt); } } }