// Touch handlers public override void onTouchBegan(myTouch touch, Vector2 touchPos) { base.onTouchBegan(touch, touchPos); _zoomInAnimation.restartStartToCurrent(); UI.instance.StartCoroutine(_zoomInAnimation.animate()); }
public override void onTouchMoved(myTouch touch, Vector2 touchPos) { // dont fire this continously if we were asked to only fire start and end if (!onlyFireStartAndEndEvents && onTouchIsDown != null) { onTouchIsDown(this); } }
public void resetWithTouch(myTouch touch) { // Initialize the detectionState only with the swipe types we want to listen for swipeDetectionState = swipesToDetect; startPoint = touch.position; startTime = Time.time; swipeDetectionStatus = SwipeDetectionStatus.Waiting; }
public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { // Set highlighted to avoid calling super highlighted = false; // Reset back to default state this.resetJoystick(); }
public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { base.onTouchEnded(touch, touchPos, touchWasInsideTouchFrame); _zoomInAnimation.stop(); _zoomOutAnimation.restartStartToCurrent(); UI.instance.StartCoroutine(_zoomOutAnimation.animate()); }
public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { base.onTouchEnded(touch, touchPos, touchWasInsideTouchFrame); if (onlyFireStartAndEndEvents && onActivationEnded != null) { onActivationEnded(this); } }
// Touch handlers public override void onTouchBegan(myTouch touch, Vector2 touchPos) { base.onTouchBegan(touch, touchPos); if (onlyFireStartAndEndEvents && onActivationStarted != null) { onActivationStarted(this); } }
public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { highlighted = false; if (onKnobChanged != null) { onKnobChanged(this, _value); } }
public override void onTouchBegan(myTouch touch, Vector2 touchPos) { if (touchInfoArray[touch.fingerId] == null) { touchInfoArray[touch.fingerId] = new TouchInfo(swipesToDetect); } // Reset the TouchInfo with the current touch touchInfoArray[touch.fingerId].resetWithTouch(touch); }
public void CheckTouch(myTouch t, RaycastHit hit) { foreach (guiButton b in buttons) { if (b.enabled) { b.CheckTouch(t, hit); } } }
public override void onTouchMoved(myTouch touch, Vector2 touchPos) { // increment deltaTouch so we can pass on the touch if necessary _deltaTouch += touch.deltaPosition.y; _lastTouch = touch; /*if (Vector2.Magnitude(touchStartPos, touchPos) < 10) { * }*/ // once we move too far unhighlight and stop tracking the touchable if (_activeTouchable != null && Mathf.Abs(_deltaTouch) > TOUCH_MAX_DELTA_FOR_ACTIVATION) { _activeTouchable.onTouchEnded(touch, touchPos, true); _activeTouchable = null; } var newTop = _scrollPosition - touch.deltaPosition.y; // are we dragging above/below the scrollables boundaries? _isDraggingPastExtents = (newTop > 0 || newTop < _minEdgeInset.y); // if we are dragging past our extents dragging is no longer 1:1. we apply an exponential falloff if (_isDraggingPastExtents) { // how far from the top/bottom are we? var distanceFromSource = 0f; if (newTop > 0) // stretching down { distanceFromSource = newTop; } else { distanceFromSource = Mathf.Abs(_contentHeight + newTop - height); } // we need to know the percentage we are from the source var percentFromSource = distanceFromSource / height; // apply exponential falloff so that the further we are from source the less 1 pixel drag actually goes newTop = _scrollPosition - (touch.deltaPosition.y * Mathf.Pow(0.04f, percentFromSource)); } _scrollPosition = newTop; layoutChildren(); // pop any extra velocities and push the current velocity onto the stack if (_velocities.Count == TOTAL_VELOCITY_SAMPLE_COUNT) { _velocities.Dequeue(); } _velocities.Enqueue(touch.deltaPosition.y / Time.deltaTime); }
public override void onTouchMoved(myTouch touch, Vector2 touchPos) { if (touch.fingerId != currentTouchId) { return; } touchPos.y = -touchPos.y; this.layoutJoystick(this.inverseTranformPoint(touchPos - _joystickCenter)); }
public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { if (touchCount == 0) { highlighted = false; } if (onChange != null) { onChange(this, _value); } }
public override void onTouchMoved(myTouch touch, Vector2 touchPos) { Color oldColor = colorPicked; Vector2 textureCoord = getTouchTextureCoords(touchPos); colorPicked = getColorForPixel((int)textureCoord.x, (int)textureCoord.y); if (onColorChange != null) { onColorChange(this, colorPicked, oldColor); } }
public override void onTouchBegan(myTouch touch, Vector2 touchPos) { highlighted = true; this.layoutJoystick(this.inverseTranformPoint(touchPos)); // If we have a highlightedUVframe, swap it in if (highlightedUVframe != UIUVRect.zero) { _joystickSprite.uvFrame = highlightedUVframe; } }
// Check for touch. // Used at the start of game, can touch ball or press 'start' to begin the game. public void CheckTouch(myTouch t) { if (t.phase == TouchPhase.Began && GameManager.instance.gameState == GameState.Start) { ray = Camera.main.ScreenPointToRay(t.position); if (Physics.Raycast(ray, out hit, 10, 1 << gameObject.layer)) { Debug.Log("hit the ball: " + hit.transform.name); GameManager.instance.StartGame(); } } }
public bool CheckTouch(myTouch t, RaycastHit hit) { if (t.phase == TouchPhase.Began) { if (hit.collider != null && hit.collider.gameObject == this.gameObject) { Touched(); return(true); } } return(false); }
public override void onTouchMoved(myTouch touch, Vector2 touchPos) { if (processTouchInfoWithTouch(touchInfoArray[touch.fingerId], touch)) { // Got a swipe if (onSwipe != null) { onSwipe(this, touchInfoArray[touch.fingerId].completedSwipeDirection); } touchInfoArray[touch.fingerId].swipeDetectionStatus = SwipeDetectionStatus.Done; } }
// Touch handlers public override void onTouchBegan(myTouch touch, Vector2 touchPos) { highlighted = true; Color oldColor = colorPicked; Vector2 textureCoord = getTouchTextureCoords(touchPos); colorPicked = getColorForPixel((int)textureCoord.x, (int)textureCoord.y); if (onColorChangeBegan != null) { onColorChangeBegan(this, colorPicked, oldColor); } }
public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { if (touch.fingerId != currentTouchId) { return; } // Set highlighted to avoid calling super highlighted = false; // Reset back to default state this.resetJoystick(); currentTouchId = -1; }
public virtual void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { _isDragging = false; // pass on the touch if we still have an active touchable if (_activeTouchable != null) { _activeTouchable.onTouchEnded(touch, touchPos, true); _activeTouchable.highlighted = false; _activeTouchable = null; } else { _manager.StartCoroutine(decelerate()); } }
// Touch handlers public override void onTouchBegan(myTouch touch, Vector2 touchPos) { highlighted = true; initialTouchPosition = touch.position; if (touchDownSound != null) { UI.instance.playSound(touchDownSound); } if (onTouchDown != null) { onTouchDown(this); } }
public static myTouch createTouchFromInput(UIMouseState mouseState, ref Vector2?lastMousePosition) { //try{ var self = new myTouch(); //ValueType valueSelf = self; var type = typeof(myTouch); var currentMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); // if we have a lastMousePosition use it to get a delta if (lastMousePosition.HasValue) { self.deltaPosition = (Vector2)(currentMousePosition - lastMousePosition); } //type.GetField("m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(valueSelf, currentMousePosition - lastMousePosition); if (mouseState == UIMouseState.DownThisFrame) // equivalent to touchBegan { self.phase = TouchPhase.Began; //type.GetField("m_Phase", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(valueSelf, TouchPhase.Began); lastMousePosition = Input.mousePosition; } else if (mouseState == UIMouseState.UpThisFrame) // equivalent to touchEnded { self.phase = TouchPhase.Ended; //type.GetField("m_Phase", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(valueSelf, TouchPhase.Ended); lastMousePosition = Vector2.zero; } else // UIMouseState.HeldDown - equivalent to touchMoved/Stationary { self.phase = TouchPhase.Moved; //type.GetField("m_Phase", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(valueSelf, TouchPhase.Moved); lastMousePosition = Input.mousePosition; } self.position = currentMousePosition; //type.GetField("m_Position", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(valueSelf, currentMousePosition); //return (myTouch)valueSelf; return(self); /*}catch(Exception e){ * Statics.Instance.myString = e.ToString(); * } * return new Touch();*/ }
// Touch handlers public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { highlighted = false; // If the touch was inside our touchFrame and we have an action, call it if (touchWasInsideTouchFrame) { // Toggle our selected state this.selected = !_selected; // Let our delegate know things changed if (onToggle != null) { onToggle(this, _selected); } } }
// Touch handlers. Subclasses should override onTouchMoved public virtual void onTouchBegan(myTouch touch, Vector2 touchPos) { touchStartPos = touchPos; // sanity check in case we lost a touch (happens with Unity on occassion) if (_activeTouchable != null) { // we dont pass onTouchEnded here because technically we are still over the ITouchable _activeTouchable.highlighted = false; _activeTouchable = null; } _deltaTouch = 0; _isDragging = true; _velocities.Clear(); // kick off a new check _manager.StartCoroutine(checkDelayedContentTouch()); }
// Handle Touch Input (inclusing mouse). void CheckTouch(myTouch t) { // OH MY GOD REBUILD HOW TOUCH IS HANDLED, SO BAD. // Screen point touched. ray = Camera.main.ScreenPointToRay(t.position); Physics.Raycast(ray, out hit, 10, buttonLayer); if (GameManager.instance.gameState == GameState.Play) { // Check game elements. paddle.CheckTouch(t); // Check Buttons - Goal here is to get down to one raycast. //if (Physics.Raycast(ray, out hit, 10, buttonLayer)) { // check all buffs. for (int i = 0; i < gameBuffButtons.Count; i++) { if (gameBuffButtons[i].CheckTouch(t, hit)) { return; } } // Check GUI elements guiMagnetButton.CheckTouch(t, hit); guiBombButton.CheckTouch(t, hit); guiPauseButton.CheckTouch(t, hit); // } } else { // if (Physics.Raycast(ray, out hit, 10, buttonLayer)) { pauseScreen.CheckTouch(t, hit); //} if (GameManager.instance.gameState == GameState.Start) { // Check game elements. paddle.CheckTouch(t); ball.CheckTouch(t); } } }
// Handle Touch events. public void CheckTouch(myTouch t, RaycastHit hit) { if (t.phase == TouchPhase.Began) { if (touchFinger < 0) { if (hit.collider != null && hit.collider.gameObject == this.gameObject) { touchFinger = t.fingerId; if (!buttonDown && _usable) { ButtonDown(); } } } } else if (t.phase == TouchPhase.Moved) { if (t.fingerId == touchFinger) { if (hit.collider == null || hit.collider.gameObject != this.gameObject) { //finger moved out of button, set it to up. if (buttonDown) { ButtonUp(false); } } } } else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled) { if (t.fingerId == touchFinger) { touchFinger = -1; if (buttonDown) { ButtonUp(); } } } }
public void CheckTouch(myTouch t) { float xPos = _transform.position.x; if (t.phase == TouchPhase.Began) { if (paddleController < 0) // No paddle controller? Lets check if anything is touching it { ray = Camera.main.ScreenPointToRay(t.position); if (Physics.Raycast(ray, out hit, 10, paddleLayer)) { paddleController = t.fingerId; } } } else if (t.phase == TouchPhase.Moved) { if (t.fingerId == paddleController) { ray = Camera.main.ScreenPointToRay(t.position); if (Physics.Raycast(ray, out hit, 10, paddleMovementLayer)) { xPos = hit.point.x; // Clamp the paddle in the arena. xPos = Mathf.Clamp(xPos, -2.5f, 2.5f); _transform.position = Vector3.Lerp( _transform.position, new Vector3(xPos, _transform.position.y, _transform.position.z), Time.deltaTime * paddleSpeed); } } } else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled) { if (t.fingerId == paddleController) { paddleController = -1; } } }
public override void onTouchEnded(myTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame) { if (touchWasInsideTouchFrame) { _state++; adjustForStateRollover(_state); } base.onTouchEnded(touch, touchPos, touchWasInsideTouchFrame); if (touchWasInsideTouchFrame) { setFramesForState(_state); // If the touch was inside our touchFrame and we have an action, call it if (onStateChange != null) { onStateChange(this, _state); } } }
public static myTouch createTouch(int finderId, int tapCount, Vector2 position, Vector2 deltaPos, float timeDelta, TouchPhase phase) { var self = new myTouch(); //ValueType valueSelf = self; var type = typeof(myTouch); //type.GetField( "m_FingerId", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, finderId ); self.fingerId = finderId; //type.GetField( "m_TapCount", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, tapCount ); self.tapCount = tapCount; //type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, position ); self.position = position; //type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, deltaPos ); self.deltaPosition = deltaPos; //type.GetField( "m_timeDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, timeDelta ); self.deltaTime = timeDelta; //type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, phase ); self.phase = phase; //return (myTouch)valueSelf; return(self); }