Beispiel #1
0
        protected void MouseUp(Vector2 mousePosition)
        {
            mouseTouchState = MouseTouchState.MouseUp;

            onMouseUp.OnNext((Vector2)Camera.main.ScreenToWorldPoint(mousePosition));
            mouseTouchState = MouseTouchState.Nothing;
        }
Beispiel #2
0
    public void ResetMouseTouchState()
    {
//		Debug.Log("ResetMouseTouchState");
        stillTouching   = true;
        mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
        touchTimer      = 0.0f;
        iTouchStateFlag = 1;
    }
Beispiel #3
0
 private void MouseDrag(Vector3 mousePosition)
 {
     if (Vector3.Distance(StartDragOnMouseDownPosition, mousePosition) > MinDragDistance)
     {
         MouseTouchState = MouseTouchState.MouseDrag;
         OnMouseFingerDrag(mousePosition);
     }
 }
Beispiel #4
0
    // Use this for initialization
    void Start()
    {
        fInitialX = 0.0f;
        fInitialY = 0.0f;
        fFinalX   = 0.0f;
        fFinalY   = 0.0f;

        inputX = 0.0f;
        inputY = 0.0f;

        iTouchStateFlag = 0;
        mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
    }
	// Use this for initialization
	void Start ()
	{
		fInitialX = 0.0f;
		fInitialY = 0.0f;
		fFinalX = 0.0f;
		fFinalY = 0.0f;
		
		inputX = 0.0f;
		inputY = 0.0f;
		
		iTouchStateFlag = 0;
		mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
	}
Beispiel #6
0
        protected void MouseDown(Vector2 mousePosition)
        {
            if (mouseTouchState.Equals(MouseTouchState.Nothing))
            {
                onMouseDown.OnNext((Vector2)Camera.main.ScreenToWorldPoint(mousePosition));
            }

            mouseTouchState = MouseTouchState.MouseDown;

            //For Android, WebGL, PC, Mac, Linux the drag happens here
#if UNITY_WEBGL || UNITY_EDITOR
            MouseDrag(mousePosition);
#endif
        }
Beispiel #7
0
    }    //end of gestureState function

    /*
     *	FUNCTION: Return gesture state.
     *	RETURNS: Returns MOUSE_TOUCH_WAITING if no gestures are detected.
     *			  Returns mouseTouchState if a valid gesture is detected
     */
    public MouseTouchState GetGestureState()
    {
//		Debug.Log("[getGestureState] called!");
        if (mouseTouchState != MouseTouchState.MOUSE_TOUCH_WAITING)
        {
            var eTempGestureState = mouseTouchState;
            mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;

            return(eTempGestureState);
        }
        else
        {
            return(MouseTouchState.MOUSE_TOUCH_WAITING);
        }
    }
Beispiel #8
0
        private void MouseDown(Vector3 mousePosition)
        {
            if (MouseTouchState == MouseTouchState.Nothing)
            {
                StartDragOnMouseDownPosition = mousePosition;
                OnMouseFingerDown(mousePosition);
                MouseTouchState = MouseTouchState.MouseDown;
            }

            //For Android, WebGL, PC, Mac, Linux the drag happens here
#if UNITY_WEBGL || UNITY_EDITOR || UNITY_STANDALONE || UNITY_FACEBOOK
            if (!_onStationaryTriggered && MouseTouchState == MouseTouchState.MouseDown && _stationaryTimer >= TimeToTriggerStationary &&
                Vector3.Distance(StartDragOnMouseDownPosition, mousePosition) < MinDragDistance)
            {
                _onStationaryTriggered = true;
                OnStationary(mousePosition);
            }

            _stationaryTimer += Time.deltaTime;
            MouseDrag(mousePosition);
#endif
        }
Beispiel #9
0
        private void MouseUp(Vector3 mousePosition)
        {
            _stationaryTimer       = 0;
            _onStationaryTriggered = false;
            MouseTouchState        = MouseTouchState.MouseUp;

            OnMouseFingerUp(mousePosition);
            MouseTouchState = MouseTouchState.Nothing;

            if (_tapCount == 0)
            {
                _tapCount++;
                _tapTimer = 0;

                OnSingleTap(mousePosition);
            }
            else if (_tapCount == 1 && _tapTimer <= TimeToTriggerTap)
            {
                OnDoubleTap(mousePosition);
                _tapCount = 0;
            }
        }
Beispiel #10
0
    void Update()
    {
        if (iTouchStateFlag == 0)
        {
            mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
        }

        if (iTouchStateFlag == 0 &&
            Input.GetMouseButtonDown(0))                //state 1 of mouse touch control
        {
            fInitialX = Input.mousePosition.x;          //get the initial x mouse/ finger value
            fInitialY = Input.mousePosition.y;          //get the initial y mouse/ finger value


            mouseTouchState = MouseTouchState.MOUSE_TOUCH_BEGAN;

            iTouchStateFlag = 1;

            touchTimer  = 0.0f;
            enableTimer = true;
        }

        if (iTouchStateFlag == 1)               //state 2 of mouse touch control
        {
            if (stillTouching)
            {
                stillTouching   = false;
                mouseTouchState = MouseTouchState.MOUSE_TOUCH_BEGAN;
                fInitialX       = Input.mousePosition.x;
                fInitialY       = Input.mousePosition.y;
            }
            else
            {
                fFinalX = Input.mousePosition.x;
                fFinalY = Input.mousePosition.y;
                if (mouseTouchState == MouseTouchState.MOUSE_TOUCH_ENDED)
                {
                    iTouchStateFlag = 2;
                }
            }
        }

        if (iTouchStateFlag == 2 ||
            Input.GetMouseButtonUp(0))                  //state 3 of mouse touch control
        {
//			Debug.Log ("fFinalX " + fFinalX + "\nfFinalY " + fFinalY);
            mouseTouchState = CheckGestureState();              //get the gesture direction
//			Debug.Log ("[MouseTouchControls] " + mouseTouchState);
            // call a function to reset the mouseTouchState
            enableTimer = false;
//			resetTouchTimer = 0.0f;

//			enableResetTimer = true;
            iTouchStateFlag = 0;
            stillTouching   = false;

            //woot

//			enableResetTimer = false;
//			resetTouchTimer = 0.0f;
            fInitialX = 0;
            fInitialY = 0;
            fFinalX   = 0;
            fFinalY   = 0;
            inputX    = 0;
            inputY    = 0;
        }


        if (enableTimer)
        {
            touchTimer += Time.deltaTime;
//			stillTouching = true;
        }

//		/* for the timers */
//		if (enableTimer)
//		{
////			Debug.Log("inputX = " + inputX + "\ninputY = " + inputY);
//			touchTimer += Time.deltaTime;
////			touchTimer += 0.5f;
//			if ( touchTimer >= longPressTime
//			    && inputX == 0
//			    && inputY == 0)
//			{
//				mouseTouchState = MouseTouchState.MOUSE_TOUCH_LONGPRESS_BEGAN;
////				Debug.Log(mouseTouchState);
//			}
//		}
//
//		if (enableResetTimer)
//		{
//			resetTouchTimer += Time.deltaTime;
////			resetTouchTimer += 0.5f;
//
//			if (resetTouchTimer >= 0.0175f) {
////			if (resetTouchTimer >= 2.5f) {
//				mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
//				enableResetTimer = false;
//				resetTouchTimer = 0.0f;
//				fInitialX = 0;
//				fInitialY = 0;
//				fFinalX = 0;
//				fFinalY = 0;
//				inputX = 0;
//				inputY = 0;
//			}
//		}
    }
	/*
	 *	FUNCTION: Calculate the swipe direction
	 */
	// issues with the long press not updating the touch state
	private MouseTouchState CheckGestureState()
	{
		//calculate the slope of the swipe
		inputX = fInitialX - fFinalX;
		inputY = fInitialY - fFinalY;
		slope = inputY / inputX;
//		Debug.Log ("[gestureState] inputX = " + inputX + "\ninputY = " + inputY + "\nslope + " + slope);
		//calculate the distance of tap start and end
//		fDistance = Mathf.Sqrt( Mathf.Pow((fFinalY-fInitialY), 2) + Mathf.Pow((fFinalX-fInitialX), 2) );
		if (inputX >= 0 
		    && inputY > 100
		    && slope > 1)//first octant MOUSE_TOUCH_SWIPE_DOWN
		{		
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN;
		}
		else if (inputX <= 0 
		         && inputY > 100
		         && slope < -1)//eighth octant MOUSE_TOUCH_SWIPE_DOWN
		{
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN;
		}
		else if (inputX > touchSensitivity
		         && inputY >= 0 
		         && slope < 1 
		         && slope >= 0)//second octant MOUSE_TOUCH_SWIPE_LEFT
		{
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT;
		}
		else if (inputX > touchSensitivity
		         && inputY <= 0 
		         && slope > -1 
		         && slope <= 0)//third octant MOUSE_TOUCH_SWIPE_LEFT
		{
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT;
		}
		else if (inputX < -touchSensitivity
		         && inputY >= 0 
		         && slope > -1 
		         && slope <= 0)//seventh octant MOUSE_TOUCH_SWIPE_RIGHT
		{
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT;
		}
		else if (inputX < -touchSensitivity
		         && inputY <= 0 
		         && slope >= 0 
		         && slope < 1)//sixth octant  MOUSE_TOUCH_SWIPE_RIGHT
		{
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT;
		}
		else if (inputX >= 0 
		         && inputY < -touchSensitivity
		         && slope < -1)//fourth octant MOUSE_TOUCH_SWIPE_UP
		{
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_UP;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_UP;
		}
		else if (inputX <= 0 
		         && inputY < -touchSensitivity
		         && slope > 1)//fifth octant MOUSE_TOUCH_SWIPE_UP
		{
			currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_UP;
			return MouseTouchState.MOUSE_TOUCH_SWIPE_UP;
		}
		else //if (inputX == 0
		         //&& inputY == 0)
		{
			if (touchTimer >= longPressTime) {
				currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_LONGPRESS_ENDED;
				return MouseTouchState.MOUSE_TOUCH_LONGPRESS_ENDED;
			} else {
				currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_TAP;
				return MouseTouchState.MOUSE_TOUCH_TAP;
			}
		}
//		return MouseTouchState.MOUSE_TOUCH_WAITING;
	}//end of gestureState function
Beispiel #12
0
    private float slope;                                                        //slope (m) of the the
//	private float fDistance;							//magnitude of distance between two positions

    void Awake()
    {
        currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
    }
	}//end of gestureState function
	
	/*
	*	FUNCTION: Return gesture state.
	*	RETURNS: Returns MOUSE_TOUCH_WAITING if no gestures are detected.
	*			  Returns mouseTouchState if a valid gesture is detected
	*/
	public MouseTouchState GetGestureState()
	{
//		Debug.Log("[getGestureState] called!");
		if (mouseTouchState != MouseTouchState.MOUSE_TOUCH_WAITING)
		{
			var eTempGestureState = mouseTouchState;
			mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
			
			return eTempGestureState;
		}
		else
			return MouseTouchState.MOUSE_TOUCH_WAITING;
	}
	public void ResetMouseTouchState () {
//		Debug.Log("ResetMouseTouchState");
		stillTouching = true;
		mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
		touchTimer = 0.0f;
		iTouchStateFlag = 1;
	}
Beispiel #15
0
    /*
     *	FUNCTION: Calculate the swipe direction
     */
    // issues with the long press not updating the touch state
    private MouseTouchState CheckGestureState()
    {
        //calculate the slope of the swipe
        inputX = fInitialX - fFinalX;
        inputY = fInitialY - fFinalY;
        slope  = inputY / inputX;
//		Debug.Log ("[gestureState] inputX = " + inputX + "\ninputY = " + inputY + "\nslope + " + slope);
        //calculate the distance of tap start and end
//		fDistance = Mathf.Sqrt( Mathf.Pow((fFinalY-fInitialY), 2) + Mathf.Pow((fFinalX-fInitialX), 2) );
        if (inputX >= 0 &&
            inputY > 100 &&
            slope > 1)           //first octant MOUSE_TOUCH_SWIPE_DOWN
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN);
        }
        else if (inputX <= 0 &&
                 inputY > 100 &&
                 slope < -1)           //eighth octant MOUSE_TOUCH_SWIPE_DOWN
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_DOWN);
        }
        else if (inputX > touchSensitivity &&
                 inputY >= 0 &&
                 slope < 1 &&
                 slope >= 0)           //second octant MOUSE_TOUCH_SWIPE_LEFT
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT);
        }
        else if (inputX > touchSensitivity &&
                 inputY <= 0 &&
                 slope > -1 &&
                 slope <= 0)           //third octant MOUSE_TOUCH_SWIPE_LEFT
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_LEFT);
        }
        else if (inputX < -touchSensitivity &&
                 inputY >= 0 &&
                 slope > -1 &&
                 slope <= 0)           //seventh octant MOUSE_TOUCH_SWIPE_RIGHT
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT);
        }
        else if (inputX < -touchSensitivity &&
                 inputY <= 0 &&
                 slope >= 0 &&
                 slope < 1)           //sixth octant  MOUSE_TOUCH_SWIPE_RIGHT
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_RIGHT);
        }
        else if (inputX >= 0 &&
                 inputY < -touchSensitivity &&
                 slope < -1)           //fourth octant MOUSE_TOUCH_SWIPE_UP
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_UP;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_UP);
        }
        else if (inputX <= 0 &&
                 inputY < -touchSensitivity &&
                 slope > 1)           //fifth octant MOUSE_TOUCH_SWIPE_UP
        {
            currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_SWIPE_UP;
            return(MouseTouchState.MOUSE_TOUCH_SWIPE_UP);
        }
        else         //if (inputX == 0
        //&& inputY == 0)
        {
            if (touchTimer >= longPressTime)
            {
                currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_LONGPRESS_ENDED;
                return(MouseTouchState.MOUSE_TOUCH_LONGPRESS_ENDED);
            }
            else
            {
                currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_TAP;
                return(MouseTouchState.MOUSE_TOUCH_TAP);
            }
        }
//		return MouseTouchState.MOUSE_TOUCH_WAITING;
    }    //end of gestureState function
Beispiel #16
0
        protected void MouseDrag(Vector2 mousePosition)
        {
            mouseTouchState = MouseTouchState.MouseDrag;

            onMouseDrag.OnNext((Vector2)Camera.main.ScreenToWorldPoint(mousePosition));
        }
	private float slope;								//slope (m) of the the 
//	private float fDistance;							//magnitude of distance between two positions
	
	void Awake () {
		currentMouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
	}
	void Update()
	{
		if ( iTouchStateFlag == 0 )
		{
			mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
		}

		if (iTouchStateFlag == 0 
		    && Input.GetMouseButtonDown(0))	//state 1 of mouse touch control
		{	
			fInitialX = Input.mousePosition.x;	//get the initial x mouse/ finger value
			fInitialY = Input.mousePosition.y;	//get the initial y mouse/ finger value


			mouseTouchState = MouseTouchState.MOUSE_TOUCH_BEGAN;

			iTouchStateFlag = 1;

			touchTimer = 0.0f;
			enableTimer = true;
		}		

		if (iTouchStateFlag == 1)	//state 2 of mouse touch control
		{
			if (stillTouching)
			{
				stillTouching = false;
				mouseTouchState = MouseTouchState.MOUSE_TOUCH_BEGAN;
				fInitialX = Input.mousePosition.x;
				fInitialY = Input.mousePosition.y;
			} 
			else
			{
				fFinalX = Input.mousePosition.x;
				fFinalY = Input.mousePosition.y;
				if (mouseTouchState == MouseTouchState.MOUSE_TOUCH_ENDED)
					iTouchStateFlag = 2;
			}
		}

		if (iTouchStateFlag == 2 
		    || Input.GetMouseButtonUp(0))	//state 3 of mouse touch control
		{
//			Debug.Log ("fFinalX " + fFinalX + "\nfFinalY " + fFinalY);
			mouseTouchState = CheckGestureState();	//get the gesture direction
//			Debug.Log ("[MouseTouchControls] " + mouseTouchState);
			// call a function to reset the mouseTouchState
			enableTimer = false;
//			resetTouchTimer = 0.0f;

//			enableResetTimer = true;
			iTouchStateFlag = 0;
			stillTouching = false;

			//woot

//			enableResetTimer = false;
//			resetTouchTimer = 0.0f;
			fInitialX = 0;
			fInitialY = 0;
			fFinalX = 0;
			fFinalY = 0;
			inputX = 0;
			inputY = 0;


		}


		if ( enableTimer )
		{
			touchTimer += Time.deltaTime;
//			stillTouching = true;
		}

//		/* for the timers */
//		if (enableTimer)
//		{
////			Debug.Log("inputX = " + inputX + "\ninputY = " + inputY);
//			touchTimer += Time.deltaTime;
////			touchTimer += 0.5f;
//			if ( touchTimer >= longPressTime
//			    && inputX == 0
//			    && inputY == 0)
//			{
//				mouseTouchState = MouseTouchState.MOUSE_TOUCH_LONGPRESS_BEGAN;
////				Debug.Log(mouseTouchState);
//			}
//		}
//
//		if (enableResetTimer) 
//		{
//			resetTouchTimer += Time.deltaTime;
////			resetTouchTimer += 0.5f;
//			
//			if (resetTouchTimer >= 0.0175f) {
////			if (resetTouchTimer >= 2.5f) {
//				mouseTouchState = MouseTouchState.MOUSE_TOUCH_WAITING;
//				enableResetTimer = false;
//				resetTouchTimer = 0.0f;
//				fInitialX = 0;
//				fInitialY = 0;
//				fFinalX = 0;
//				fFinalY = 0;
//				inputX = 0;
//				inputY = 0;
//			}
//		}
	}