// We don't leverage EZGUI's rayCast hit test functionality. // Instead we use a simple AABB hit test on our collider. protected override bool Colliding(VCTouchWrapper tw) { if (!tw.Active) return false; return AABBContains(tw.position); }
protected override void ProcessTouch(VCTouchWrapper tw) { // if measuring relative to center, set origin to movingPart pos if (measureDeltaRelativeToCenter) { _touchOrigin = movingPart.transform.position; _touchOriginScreen.x = _touchOrigin.x * Screen.width; _touchOriginScreen.y = _touchOrigin.y * Screen.height; } else { // otherwise set origin to touch location _touchOrigin.x = tw.position.x / Screen.width; _touchOrigin.y = tw.position.y / Screen.height; _touchOrigin.z = movingPart.transform.position.z; _touchOriginScreen.x = tw.position.x; _touchOriginScreen.y = tw.position.y; } // if we need to move the joystick, do it if (positionAtTouchLocation) { _movingPartOrigin = _touchOrigin; basePart.transform.position = new Vector3(_touchOrigin.x, _touchOrigin.y, basePart.transform.position.z); } }
protected override void ProcessTouch(VCTouchWrapper tw) { if (this.measureDeltaRelativeToCenter) { this._touchOrigin = this.movingPart.transform.position; this._touchOriginScreen.x = this._touchOrigin.x * (float)ResolutionConstrain.Instance.width; this._touchOriginScreen.y = this._touchOrigin.y * (float)ResolutionConstrain.Instance.height; } else { this._touchOrigin.x = tw.position.x / (float)ResolutionConstrain.Instance.width; this._touchOrigin.y = tw.position.y / (float)ResolutionConstrain.Instance.height; this._touchOrigin.z = this.movingPart.transform.position.z; this._touchOriginScreen.x = tw.position.x; this._touchOriginScreen.y = tw.position.y; } if (this.positionAtTouchLocation) { this._movingPartOrigin = this._touchOrigin; Vector3 zero = Vector3.zero; zero.x = this._touchOrigin.x; zero.y = this._touchOrigin.y; zero.z = this.basePart.transform.position.z; this.basePart.transform.position = zero; } }
protected override void ProcessTouch(VCTouchWrapper tw) { if (measureDeltaRelativeToCenter) { _touchOrigin = movingPart.transform.position; _touchOriginScreen = _colliderCamera.WorldToScreenPoint(movingPart.transform.position); } else { _touchOrigin = _colliderCamera.ScreenToWorldPoint(tw.position); _touchOriginScreen.x = tw.position.x; _touchOriginScreen.y = tw.position.y; } if (positionAtTouchLocation) { float zCache = movingPart.transform.localPosition.z; Vector3 targetPos = _touchOrigin; targetPos.z = basePart.transform.position.z; basePart.transform.position = targetPos; targetPos.z = movingPart.transform.position.z; movingPart.transform.position = targetPos; _movingPartOrigin.Set(movingPart.transform.localPosition.x, movingPart.transform.localPosition.y, zCache); } }
protected override void ProcessTouch(VCTouchWrapper tw) { // if measuring delta relative to center, set origin to movingPart's pos if (measureDeltaRelativeToCenter) { _touchOrigin = movingPart.transform.position; _touchOriginScreen = _colliderCamera.WorldToScreenPoint(movingPart.transform.position); } else { // otherwise set it to the touch location _touchOrigin = _colliderCamera.ScreenToWorldPoint(tw.position); _touchOrigin.Set(_touchOrigin.x, _touchOrigin.y, basePart.transform.position.z); _touchOriginScreen.x = tw.position.x; _touchOriginScreen.y = tw.position.y; } // move to the touch location if necessary if (positionAtTouchLocation) { float zCache = movingPart.transform.localPosition.z; basePart.transform.localPosition = _touchOrigin; movingPart.transform.position = _touchOrigin; _movingPartOrigin.Set(movingPart.transform.localPosition.x, movingPart.transform.localPosition.y, zCache); } }
protected bool SetTouch(VCTouchWrapper tw) { if (requireExclusiveTouch) { // don't do anything if this touch is already in use foreach (VCTouchWrapper twInUse in touchesInUse) { if (twInUse.fingerId == tw.fingerId) { return(false); } } } _touch = tw; TapCount++; if (TapCount == 1) { _tapTime = Time.time; } else if (TapCount > 0 && (TapCount % 2 == 0) && OnDoubleTap != null) { OnDoubleTap(this); } touchesInUse.Add(tw); _wasDragging = true; return(true); }
protected void StopDragging() { this.SetPosition(this.movingPart, this._movingPartOrigin); this._deltaPixels = Vector2.zero; this._wasDragging = false; VCAnalogJoystickBase.touchesInUse.Remove(this._touch); this._touch = null; }
// We don't leverage EZGUI's rayCast hit test functionality. // Instead we use a simple AABB hit test on our collider. protected override bool Colliding(VCTouchWrapper tw) { if (!tw.Active) { return(false); } return(AABBContains(tw.position)); }
protected override bool Colliding(VCTouchWrapper tw) { if (!tw.Active) return false; // NGUI's default OnHover and OnPress behavior doesn't update target info until // the mouse button or touch is released, which is not compatible with some VCAnalogJoystick behavior. // instead, we use a simple AABB hit test. return AABBContains(tw.position); }
// ceases dragging and repositions joystick protected void StopDragging() { SetPosition(movingPart, _movingPartOrigin); _deltaPixels = Vector2.zero; _wasDragging = false; touchesInUse.Remove(_touch); _touch = null; }
protected void Update () { PressBeganThisFrame = false; PressEndedThisFrame = false; #if UNITY_EDITOR UpdateDebugKeys(); #endif if (!skipCollisionDetection) { // handle a current touch if (Pressed) { // end of a current touch if (PressEnded) { if (!toggle) Pressed = false; } } if (!Pressed || toggle) { // look for a new touch VCTouchWrapper tw; for (int i = 0; i < VCTouchController.Instance.touches.Count; i++) { tw = VCTouchController.Instance.touches[i]; if (!tw.Active || (touchMustBeginOnCollider && tw.phase != TouchPhase.Began)) continue; if (anyTouchActivatesControl || Colliding(tw)) { _touch = tw; if (toggle) Pressed = !Pressed; else Pressed = true; } } } } // don't add hold time on the first frame in which a press began if (Pressed && !PressBeganThisFrame) { HoldTime += Time.deltaTime; if (OnHold != null) OnHold(this); } UpdateVisibility(); }
protected override bool Colliding(VCTouchWrapper tw) { if (this._collider != null) { return(base.AABBContains(tw.position)); } Rect screenRect = this._colliderGuiTexture.GetScreenRect(); VCUtils.ScaleRect(ref screenRect, this.hitRectScale); return(screenRect.Contains(tw.position)); }
protected override bool Colliding(VCTouchWrapper tw) { if (!tw.Active) { return(false); } // NGUI's default OnHover and OnPress behavior doesn't update target info until // the mouse button or touch is released, which is not compatible with some VCAnalogJoystick behavior. // instead, we use a simple AABB hit test. return(AABBContains(tw.position)); }
protected override bool Colliding(VCTouchWrapper tw) { // hit test against a collider if we have one if (_collider != null) { return AABBContains(tw.position); } // otherwise, fall back to a rect hit test on the guiTexture Rect r = _colliderGuiTexture.GetScreenRect(); VCUtils.ScaleRect(ref r, hitRectScale); return r.Contains(tw.position); }
protected override bool Colliding(VCTouchWrapper tw) { // hit test against a collider if we have one if (_collider != null) { return(AABBContains(tw.position)); } // otherwise, fall back to a rect hit test on the guiTexture Rect r = _colliderGuiTexture.GetScreenRect(); VCUtils.ScaleRect(ref r, hitRectScale); return(r.Contains(tw.position)); }
protected void Update() { #if UNITY_EDITOR UpdateDebugKeys(); #endif if (!skipCollisionDetection) { // handle a current touch if (Pressed) { // end of a current touch if (PressEnded) { Pressed = false; } else // continuation of a touch { HoldTime += Time.deltaTime; if (OnHold != null) { OnHold(this); } } } else { // look for a new touch VCTouchWrapper tw; for (int i = 0; i < VCTouchController.Instance.touches.Count; i++) { tw = VCTouchController.Instance.touches[i]; if (!tw.Active || touchMustBeginOnCollider && tw.phase != TouchPhase.Began) { continue; } if (anyTouchActivatesControl || Colliding(tw)) { _touch = tw; Pressed = true; } } } } UpdateVisibility(); }
protected override bool Colliding(VCTouchWrapper tw) { if (!tw.Active) return false; // first try and hitTest against a collider if we have one if (_collider != null) { return AABBContains(tw.position); } // otherwise, fall back to a rect hit test on the guiTexture (this is what most people will want) Rect r = _movingPartGuiTexture.GetScreenRect(); VCUtils.ScaleRect(ref r, hitRectScale); return r.Contains(tw.position); }
protected bool SetTouch(VCTouchWrapper tw) { if (this.requireExclusiveTouch && VCAnalogJoystickBase.touchesInUse.Any((VCTouchWrapper x) => x.fingerId == tw.fingerId)) { return(false); } this._touch = tw; this.TapCount++; if (this.TapCount == 1) { this._tapTime = Time.time; } else if (this.TapCount > 0 && this.TapCount % 2 == 0 && this.OnDoubleTap != null) { this.OnDoubleTap(this); } VCAnalogJoystickBase.touchesInUse.Add(tw); return(true); }
protected override bool Colliding(VCTouchWrapper tw) { if (!tw.Active) { return(false); } // first try and hitTest against a collider if we have one if (_collider != null) { return(AABBContains(tw.position)); } // otherwise, fall back to a rect hit test on the guiTexture (this is what most people will want) Rect r = _movingPartGuiTexture.GetScreenRect(); VCUtils.ScaleRect(ref r, hitRectScale); return(r.Contains(tw.position)); }
protected override void ProcessTouch(VCTouchWrapper tw) { if (this.measureDeltaRelativeToCenter) { this._touchOrigin = this.movingPart.transform.position; this._touchOriginScreen = this._colliderCamera.WorldToScreenPoint(this.movingPart.transform.position); } else { this._touchOrigin = this._colliderCamera.ScreenToWorldPoint(tw.position); this._touchOriginScreen.x = tw.position.x; this._touchOriginScreen.y = tw.position.y; } if (this.positionAtTouchLocation) { float z = this.movingPart.transform.localPosition.z; this.basePart.transform.position = this._touchOrigin; this.movingPart.transform.position = this._touchOrigin; this._movingPartOrigin.Set(this.movingPart.transform.localPosition.x, this.movingPart.transform.localPosition.y, z); } }
protected bool SetTouch(VCTouchWrapper tw) { if (requireExclusiveTouch && touchesInUse.Any(x => x.fingerId == tw.fingerId)) { return(false); } _touch = tw; TapCount++; if (TapCount == 1) { _tapTime = Time.time; } else if (TapCount > 0 && (TapCount % 2 == 0) && OnDoubleTap != null) { OnDoubleTap(this); } touchesInUse.Add(tw); return(true); }
protected override void ProcessTouch(VCTouchWrapper tw) { if (measureDeltaRelativeToCenter) { _touchOrigin = movingPart.transform.position; _touchOriginScreen = _colliderCamera.WorldToScreenPoint(movingPart.transform.position); } else { _touchOrigin = _colliderCamera.ScreenToWorldPoint(tw.position); _touchOriginScreen.x = tw.position.x; _touchOriginScreen.y = tw.position.y; } if (positionAtTouchLocation) { float zCache = movingPart.transform.localPosition.z; basePart.transform.position = _touchOrigin; movingPart.transform.position = _touchOrigin; _movingPartOrigin.Set(movingPart.transform.localPosition.x, movingPart.transform.localPosition.y, zCache); } }
protected void Update() { if (!this.skipCollisionDetection) { if (this.Pressed) { if (this.PressEnded) { this.Pressed = false; } else { this.HoldTime += Time.deltaTime; if (this.OnHold != null) { this.OnHold(this); } } } else { for (int i = 0; i < VCTouchController.Instance.touches.Count; i++) { VCTouchWrapper vCTouchWrapper = VCTouchController.Instance.touches[i]; if (vCTouchWrapper.Active && (!this.touchMustBeginOnCollider || vCTouchWrapper.phase == TouchPhase.Began)) { if (this.anyTouchActivatesControl || this.Colliding(vCTouchWrapper)) { this._touch = vCTouchWrapper; this.Pressed = true; } } } } } this.UpdateVisibility(); }
// handles an active touch protected abstract void ProcessTouch(VCTouchWrapper tw);
protected void PerformUpdate() { if (Time.time - this._tapTime >= this.tapCountResetTime) { this.TapCount = 0; } if (this.Dragging) { this.UpdateDelta(); Vector3 zero = Vector3.zero; zero.x = this._movingPartOrigin.x + this._movingPartOffset.x; zero.y = this._movingPartOrigin.y + this._movingPartOffset.y; zero.z = this.movingPart.transform.position.z; this.SetPosition(this.movingPart, zero); this._wasDragging = true; if (this.stopDraggingOnMoveOut && !this.Colliding(this._touch)) { this.StopDragging(); return; } } else { if (this._wasDragging) { this.StopDragging(); } if (VCTouchController.Instance == null || VCTouchController.Instance.touches == null) { return; } for (int i = 0; i < VCTouchController.Instance.touches.Count; i++) { VCTouchWrapper vCTouchWrapper = VCTouchController.Instance.touches[i]; if (vCTouchWrapper.phase == TouchPhase.Began) { if (this.anyTouchActivatesControl && this.SetTouch(vCTouchWrapper)) { break; } if (this.positionAtTouchLocation) { Vector2 zero2 = Vector2.zero; zero2.x = vCTouchWrapper.position.x / (float)ResolutionConstrain.Instance.width; zero2.y = vCTouchWrapper.position.y / (float)ResolutionConstrain.Instance.height; if (zero2.x < this.positionAtTouchLocationAreaMin.x || zero2.x > this.positionAtTouchLocationAreaMax.x) { goto IL_223; } if (zero2.y < this.positionAtTouchLocationAreaMin.y || zero2.y > this.positionAtTouchLocationAreaMax.y) { goto IL_223; } if (this.SetTouch(vCTouchWrapper)) { break; } } if (this.Colliding(vCTouchWrapper) && this.SetTouch(vCTouchWrapper)) { break; } } IL_223 :; } if (this._touch != null && this._touch.Active) { this.ProcessTouch(this._touch); } } this.SetVisible(this.visibleWhenNotActive || this.Dragging, this._movingPartVisible == this.hideMovingPart); }
protected abstract bool Colliding(VCTouchWrapper tw);
protected abstract void ProcessTouch(VCTouchWrapper tw);
protected override bool Colliding(VCTouchWrapper tw) { return AABBContains(tw.position); }
protected override void ProcessTouch(VCTouchWrapper tw) { // if measuring delta relative to center, set origin to movingPart's pos if (measureDeltaRelativeToCenter) { _touchOrigin = movingPart.transform.position; _touchOriginScreen = _colliderCamera.WorldToScreenPoint(movingPart.transform.position); } else { // otherwise set it to the touch location _touchOrigin = _colliderCamera.ScreenToWorldPoint(tw.position); _touchOrigin.Set (_touchOrigin.x, _touchOrigin.y, basePart.transform.position.z); _touchOriginScreen.x = tw.position.x; _touchOriginScreen.y = tw.position.y; } // move to the touch location if necessary if (positionAtTouchLocation) { float zCache = movingPart.transform.localPosition.z; basePart.transform.localPosition = _touchOrigin; movingPart.transform.position = _touchOrigin; _movingPartOrigin.Set(movingPart.transform.localPosition.x, movingPart.transform.localPosition.y, zCache); } }
protected void Update() { #if UNITY_EDITOR UpdateDebugKeys(); #endif if (!skipCollisionDetection) { // handle a current touch if (Pressed) { // end of a current touch if (PressEnded) { Pressed = false; } else // continuation of a touch { HoldTime += Time.deltaTime; if (OnHold != null) OnHold(this); } } else { // look for a new touch VCTouchWrapper tw; for (int i = 0; i < VCTouchController.Instance.touches.Count; i++) { tw = VCTouchController.Instance.touches[i]; if (!tw.Active || touchMustBeginOnCollider && tw.phase != TouchPhase.Began) continue; if (anyTouchActivatesControl || Colliding(tw)) { _touch = tw; Pressed = true; } } } } UpdateVisibility(); }
void Update() { #if (UNITY_IPHONE && !UNITY_EDITOR) || (UNITY_ANDROID && !UNITY_EDITOR) Input.multiTouchEnabled = multitouch; // update old touches foreach (Touch t in Input.touches) { VCTouchWrapper tw = touches.FirstOrDefault(x => x.fingerId == t.fingerId); if (tw == null) { // this is a new touch, add it to our active list touches.FirstOrDefault(x => x.fingerId == -1).Set(t); } else // touch we're already tracking, update it. { tw.visited = true; #if UNITY_ANDROID // test for error movement if (ignoreMultitouchErrorMovement && Input.touchCount > 1) { Vector2 d = tw.position - t.position; if (d.sqrMagnitude > multiTouchErrorSqrMagnitudeMax) { continue; } } #endif tw.deltaPosition = t.position - tw.position; tw.position = t.position; tw.phase = t.phase; } } // reset any previously active, but no longer active touch foreach (VCTouchWrapper tw in touches) { if (!tw.visited) { tw.Reset(); } else { tw.visited = false; // ready to cull next frame } } #else // use mouse input to emulate a touch. if (Input.GetMouseButtonDown(0)) { touches[0].phase = TouchPhase.Began; touches[0].fingerId = 1; touches[0].deltaPosition.x = 0.0f; touches[0].deltaPosition.y = 0.0f; touches[0].position.x = Input.mousePosition.x; touches[0].position.y = Input.mousePosition.y; } else if (Input.GetMouseButton(0)) { touches[0].phase = TouchPhase.Moved; touches[0].deltaPosition.x = Input.mousePosition.x - touches[0].position.x; touches[0].deltaPosition.y = Input.mousePosition.y - touches[0].position.y; touches[0].position.x = Input.mousePosition.x; touches[0].position.y = Input.mousePosition.y; } else { touches[0].Reset(); } #endif _activeTouchesCache = null; }
protected override bool Colliding(VCTouchWrapper tw) { return(tw.Active && base.AABBContains(tw.position)); }
private void Update() { if (this.touches == null) { return; } try { Input.multiTouchEnabled = this.multitouch; if (Input.touches != null && Input.touchCount > 0) { Touch[] array = Input.touches; int i = 0; Touch t; while (i < array.Length) { t = array[i]; if (t.phase != TouchPhase.Began || !UICamera.Raycast(t.position, out UICamera.lastHit)) { goto IL_C6; } if (!(UICamera.lastHit.collider == null)) { if (UICamera.lastHit.collider.gameObject.name.Equals("JoyFront")) { goto IL_C6; } } IL_1B4: i++; continue; IL_C6: VCTouchWrapper vCTouchWrapper = this.touches.FirstOrDefault((VCTouchWrapper x) => x.fingerId == t.fingerId); if (vCTouchWrapper == null) { VCTouchWrapper vCTouchWrapper2 = this.touches.FirstOrDefault((VCTouchWrapper x) => x.fingerId == -1); if (vCTouchWrapper2 != null) { vCTouchWrapper2.Set(t); } goto IL_1B4; } vCTouchWrapper.visited = true; if (this.ignoreMultitouchErrorMovement && Input.touchCount > 1 && (vCTouchWrapper.position - t.position).sqrMagnitude > this.multiTouchErrorSqrMagnitudeMax) { goto IL_1B4; } vCTouchWrapper.deltaPosition = t.position - vCTouchWrapper.position; vCTouchWrapper.position = t.position; vCTouchWrapper.phase = t.phase; goto IL_1B4; } } if (this.touches.Count > 0) { foreach (VCTouchWrapper current in this.touches) { if (current != null) { if (!current.visited) { current.Reset(); } else { current.visited = false; } } } } } catch (Exception ex) { LogSystem.LogError(new object[] { "Update VCTouchController", ex.ToString() }); } this._activeTouchesCache = null; }
protected bool SetTouch(VCTouchWrapper tw) { if (requireExclusiveTouch && touchesInUse.Any(x => x.fingerId == tw.fingerId)) return false; _touch = tw; TapCount++; if (TapCount == 1) { _tapTime = Time.time; } else if (TapCount > 0 && (TapCount % 2 == 0) && OnDoubleTap != null) { OnDoubleTap(this); } touchesInUse.Add(tw); return true; }
void Update() { Input.multiTouchEnabled = multitouch; // update old touches foreach (Touch t in Input.touches) { // see if we already have a TouchWrapper for this particular Touch. VCTouchWrapper tw = null; foreach (VCTouchWrapper touchWrapper in touches) { if (touchWrapper.fingerId == t.fingerId) { tw = touchWrapper; break; } } if (tw == null) { // this is a new touch, add it to our active list // find an available TouchWrapper to use. VCTouchWrapper availableTw = null; foreach (VCTouchWrapper touchWrapper in touches) { if (touchWrapper.fingerId == -1) { availableTw = touchWrapper; break; } } if (availableTw == null) { Debug.LogWarning("Cannot find an available TouchWrapper to assign Touch info from! Consider increasing VCTouchController.kMaxTouches."); } else { availableTw.Set(t); } } else // touch we're already tracking, update it. { tw.visited = true; tw.deltaPosition = t.position - tw.position; tw.position = t.position; tw.phase = t.phase; } } #if UNITY_EDITOR // use mouse input to emulate a touch. if (Input.GetMouseButtonDown(0)) { VCTouchWrapper availableTw = null; foreach (VCTouchWrapper touchWrapper in touches) { if (touchWrapper.fingerId == -1) { availableTw = touchWrapper; break; } } if (availableTw == null) { // we're out of touches, can't emulate. Debug.LogWarning("Cannot find an available TouchWrapper to assign Mouse Emulated Touch info from! Consider increasing VCTouchController.kMaxTouches."); } else { // populate the TouchWrapper with mouse input data. availableTw.phase = TouchPhase.Began; availableTw.fingerId = kEmulatedTouchFingerId; availableTw.deltaPosition.x = 0.0f; availableTw.deltaPosition.y = 0.0f; availableTw.position.x = Input.mousePosition.x; availableTw.position.y = Input.mousePosition.y; availableTw.visited = true; } } else if (Input.GetMouseButton(0)) { // find the emulated TouchWrapper VCTouchWrapper emulatedTw = null; foreach (VCTouchWrapper touchWrapper in touches) { if (touchWrapper.fingerId == kEmulatedTouchFingerId) { emulatedTw = touchWrapper; break; } } // update it emulatedTw.phase = TouchPhase.Moved; emulatedTw.deltaPosition.x = Input.mousePosition.x - emulatedTw.position.x; emulatedTw.deltaPosition.y = Input.mousePosition.y - emulatedTw.position.y; emulatedTw.position.x = Input.mousePosition.x; emulatedTw.position.y = Input.mousePosition.y; emulatedTw.visited = true; } #endif // reset any previously active, but no longer active touch foreach (VCTouchWrapper tw in touches) { if (!tw.visited) { tw.Reset(); } else { tw.visited = false; // ready to cull next frame } } // invalidate the ActiveTouches cache so it updates next time the user wants it. _activeTouchesCacheNeedsUpdate = true; }