예제 #1
0
    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();
        }
    }
예제 #2
0
    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);
    }
예제 #3
0
	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;
	}
예제 #4
0
    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);
    }
예제 #6
0
    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;
    }
예제 #7
0
    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
    }
예제 #8
0
 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;
 }
예제 #9
0
    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();
        }
    }
예제 #10
0
    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);
    }
예제 #11
0
/* 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)
예제 #12
0
    // 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)
예제 #13
0
 public virtual void onTouchMoved(UIFakeTouch touch, Vector2 touchPos)
예제 #14
0
	public virtual void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
예제 #15
0
	// 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 )
예제 #16
0
	public override void onTouchMoved( UIFakeTouch touch, Vector2 touchPos )
예제 #17
0
	// 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 )
예제 #18
0
/* 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 )
예제 #19
0
	public void resetWithTouch( UIFakeTouch touch )
예제 #20
0
	// Touch handlers
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
	public override void onTouchBegan( UIFakeTouch touch, Vector2 touchPos )
예제 #21
0
    // Touch handlers
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
    public override void onTouchBegan(UIFakeTouch touch, Vector2 touchPos)
예제 #22
0
	public override void onTouchEnded( UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
예제 #23
0
 public override void onTouchMoved(UIFakeTouch touch, Vector2 touchPos)
예제 #24
0
	public virtual void onTouchMoved( UIFakeTouch touch, Vector2 touchPos )
예제 #25
0
 public override void onTouchEnded(UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame)
예제 #26
0
    // 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)
예제 #27
0
	// 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 ) {
예제 #28
0
 public virtual void onTouchEnded(UIFakeTouch touch, Vector2 touchPos, bool touchWasInsideTouchFrame)
예제 #29
0
 public void resetWithTouch(UIFakeTouch touch)