protected void Update() { // only do our touch processing if we have some touches if (Input.touchCount > 0) { // Examine all current touches for (int i = 0; i < Input.touchCount; i++) { #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER lookAtTouch(UIFakeTouch.fromTouch(Input.GetTouch(i))); #else lookAtTouch(Input.GetTouch(i)); #endif } } // end if Input.touchCount #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER else { // no touches. so check the mouse input if we are in the editor if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { lookAtTouch(UIFakeTouch.fromInput(ref lastMousePosition)); } } #endif // take care of updating our UVs, colors or bounds if necessary if (meshIsDirty) { meshIsDirty = false; updateMeshProperties(); } }
public static UIFakeTouch fromInput(UIMouseState mouseState, ref Vector2?lastMousePosition) { var fakeTouch = new UIFakeTouch(); fakeTouch.fingerId = 2; // if we have a lastMousePosition use it to get a delta if (lastMousePosition.HasValue) { fakeTouch.deltaPosition = Input.mousePosition - (Vector3)lastMousePosition; } if (mouseState == UIMouseState.DownThisFrame) // equivalent to touchBegan { fakeTouch.phase = TouchPhase.Began; lastMousePosition = Input.mousePosition; } else if (mouseState == UIMouseState.UpThisFrame) // equivalent to touchEnded { fakeTouch.phase = TouchPhase.Ended; lastMousePosition = null; } else // UIMouseState.HeldDown - equivalent to touchMoved/Stationary { fakeTouch.phase = TouchPhase.Moved; lastMousePosition = Input.mousePosition; } fakeTouch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); return(fakeTouch); }
public static UIFakeTouch fromInput( UIMouseState mouseState, ref Vector2? lastMousePosition ) { var fakeTouch = new UIFakeTouch(); fakeTouch.fingerId = 2; // if we have a lastMousePosition use it to get a delta if( lastMousePosition.HasValue ) fakeTouch.deltaPosition = Input.mousePosition - (Vector3)lastMousePosition; if( mouseState == UIMouseState.DownThisFrame ) // equivalent to touchBegan { fakeTouch.phase = TouchPhase.Began; lastMousePosition = Input.mousePosition; } else if( mouseState == UIMouseState.UpThisFrame ) // equivalent to touchEnded { fakeTouch.phase = TouchPhase.Ended; lastMousePosition = null; } else // UIMouseState.HeldDown - equivalent to touchMoved/Stationary { fakeTouch.phase = TouchPhase.Moved; lastMousePosition = Input.mousePosition; } fakeTouch.position = new Vector2( Input.mousePosition.x, Input.mousePosition.y ); return fakeTouch; }
public static UIFakeTouch fromInput(ref Vector2?lastMousePosition) { var fakeTouch = new UIFakeTouch(); fakeTouch.fingerId = 2; // if we have a lastMousePosition use it to get a delta if (lastMousePosition.HasValue) { fakeTouch.deltaPosition = Input.mousePosition - (Vector3)lastMousePosition; } if (Input.GetMouseButtonDown(0)) // equivalent to touchBegan { fakeTouch.phase = TouchPhase.Began; lastMousePosition = Input.mousePosition; } else if (Input.GetMouseButtonUp(0)) // equivalent to touchEnded { fakeTouch.phase = TouchPhase.Ended; lastMousePosition = null; } else // equivalent to touchMoved/Stationary { fakeTouch.phase = TouchPhase.Moved; lastMousePosition = Input.mousePosition; } fakeTouch.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); return(fakeTouch); }
public override void onTouchMoved(Touch touch, Vector2 touchPos) #endif { // increment deltaTouch so we can pass on the touch if necessary _deltaTouch += touch.deltaPosition.y; _lastTouch = touch; // once we move too far unhighlight and stop tracking the touchable if (Mathf.Abs(_deltaTouch) > TOUCH_MAX_DELTA_FOR_ACTIVATION && _activeTouchable != null) { _activeTouchable.onTouchEnded(touch, touchPos, true); _activeTouchable = null; } var newTop = _scrollPosition - touch.deltaPosition.y; newTop = Mathf.Clamp(newTop, _minEdgeInset.y, _maxEdgeInset.y); _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 static UIFakeTouch fromInput( ref Vector2? lastMousePosition ) { var fakeTouch = new UIFakeTouch(); fakeTouch.fingerId = 2; if( Input.GetMouseButtonDown( 0 ) ) { fakeTouch.phase = TouchPhase.Began; lastMousePosition = Input.mousePosition; } else if( Input.GetMouseButtonUp( 0 ) ) { fakeTouch.phase = TouchPhase.Ended; lastMousePosition = null; } else { fakeTouch.phase = TouchPhase.Moved; lastMousePosition = Input.mousePosition; } fakeTouch.position = new Vector2( Input.mousePosition.x, Input.mousePosition.y ); // if we have a lastMousePosition use it to get a delta if( lastMousePosition.HasValue ) fakeTouch.deltaPosition = Input.mousePosition - (Vector3)lastMousePosition.Value; return fakeTouch; }
protected void Update() { // only do our touch processing if we have some touches if (Input.touchCount > 0) { // Examine all current touches for (int i = 0; i < Input.touchCount; i++) { #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER lookAtTouch(UIFakeTouch.fromTouch(Input.GetTouch(i))); #else lookAtTouch(Input.GetTouch(i)); #endif } } // end if Input.touchCount #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER else { // no touches. so check the mouse input if we are in the editor // check for each mouse state in turn, no elses here. They can all occur on the same frame! if (Input.GetMouseButtonDown(0)) { lookAtTouch(UIFakeTouch.fromInput(UIMouseState.DownThisFrame, ref lastMousePosition)); } if (Input.GetMouseButton(0)) { lookAtTouch(UIFakeTouch.fromInput(UIMouseState.HeldDown, ref lastMousePosition)); } if (Input.GetMouseButtonUp(0)) { lookAtTouch(UIFakeTouch.fromInput(UIMouseState.UpThisFrame, ref lastMousePosition)); } // handle hover states // if we have a previously hovered sprite unhover it for (int i = 0, totalTouchables = _touchableSprites.Count; i < totalTouchables; i++) { if (_touchableSprites[i].hoveredOver) { _touchableSprites[i].hoveredOver = false; } } var fixedMousePosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); var hoveredSprite = getButtonForScreenPosition(fixedMousePosition); if (hoveredSprite != null) { if (!hoveredSprite.highlighted) { hoveredSprite.hoveredOver = true; } } } #endif }
public static UIFakeTouch fromTouch( Touch touch ) { var fakeTouch = new UIFakeTouch(); fakeTouch.fingerId = touch.fingerId; fakeTouch.position = touch.position; fakeTouch.deltaPosition = touch.deltaPosition; fakeTouch.deltaTime = touch.deltaTime; fakeTouch.phase = touch.phase; return fakeTouch; }
protected void Update() { // only do our touch processing if we have some touches if (Input.touchCount > 0) { // Examine all current touches for (int i = 0; i < Input.touchCount; i++) { #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER lookAtTouch(UIFakeTouch.fromTouch(Input.GetTouch(i))); #else lookAtTouch(Input.GetTouch(i)); #endif } } // end if Input.touchCount #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER else { // no touches. so check the mouse input if we are in the editor if (Input.GetMouseButton(0) || Input.GetMouseButtonUp(0)) { lookAtTouch(UIFakeTouch.fromInput(ref lastMousePosition)); } // handle hover states // if we have a previously hovered sprite unhover it for (int i = 0, totalTouchables = _touchableSprites.Count; i < totalTouchables; i++) { if (_touchableSprites[i].hoveredOver) { _touchableSprites[i].hoveredOver = false; } } var fixedMousePosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); var hoveredSprite = getButtonForScreenPosition(fixedMousePosition); if (hoveredSprite != null) { if (!hoveredSprite.highlighted) { hoveredSprite.hoveredOver = true; } } } #endif // take care of updating our UVs, colors or bounds if necessary if (meshIsDirty) { meshIsDirty = false; updateMeshProperties(); } }
public static UIFakeTouch fromTouch(Touch touch) { var fakeTouch = new UIFakeTouch(); fakeTouch.fingerId = touch.fingerId; fakeTouch.position = touch.position; fakeTouch.deltaPosition = touch.deltaPosition; fakeTouch.deltaTime = touch.deltaTime; fakeTouch.phase = touch.phase; return(fakeTouch); }
/* Only used for debugging #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER * public override void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame ) #else * public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame ) #endif * { * //Debug.Log( "TOUCH ENDED" ); * //Debug.Log( string.Format( "x: {0}, y: {1}", touch.position.x, touch.position.y ) ); * } */ #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER private bool processTouchInfoWithTouch(TouchInfo touchInfo, UIFakeTouch touch)
// examines a touch and sends off began, moved and ended events #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER private void lookAtTouch(UIFakeTouch touch)
public virtual void onTouchMoved(UIFakeTouch touch, Vector2 touchPos)
public virtual void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
// Touch handlers. Subclasses should override these to get their specific behaviour #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER public virtual void onTouchBegan( UIFakeTouch touch, Vector2 touchPos )
public override void onTouchMoved( UIFakeTouch touch, Vector2 touchPos )
// examines a touch and sends off began, moved and ended events #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER private void lookAtTouch( UIFakeTouch touch )
/* Only used for debugging #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER public override void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame ) #else public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame ) #endif { //Debug.Log( "TOUCH ENDED" ); //Debug.Log( string.Format( "x: {0}, y: {1}", touch.position.x, touch.position.y ) ); } */ #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER private bool processTouchInfoWithTouch( TouchInfo touchInfo, UIFakeTouch touch )
public void resetWithTouch( UIFakeTouch touch )
// Touch handlers #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER public override void onTouchBegan( UIFakeTouch touch, Vector2 touchPos )
// Touch handlers #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER public override void onTouchBegan(UIFakeTouch touch, Vector2 touchPos)
public override void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public override void onTouchMoved(UIFakeTouch touch, Vector2 touchPos)
public virtual void onTouchMoved( UIFakeTouch touch, Vector2 touchPos )
public override void onTouchEnded(UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame)
// Touch handlers. Subclasses should override these to get their specific behaviour #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER public virtual void onTouchBegan(UIFakeTouch touch, Vector2 touchPos)
// examines a touch and sends off began, moved and ended events #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER private void lookAtTouch( UIFakeTouch touch, Action<UIFakeTouch> miss_handler ) {
public virtual void onTouchEnded(UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame)
public void resetWithTouch(UIFakeTouch touch)