Example #1
0
        public static void DebugTouchData( int finger_id, Vector3 pos, TouchPhase phase ) {

            var touch_data = touches.Find( _ => _.FingerId == finger_id );
            if ( touch_data != null ) {
                TouchData new_touch = new TouchData( finger_id, pos );
                touches.Add( new_touch );
            }

            touch_data.Phase = phase;

            switch ( phase ) {
            case TouchPhase.Began:
                EventTouchBegan.Invoke( touch_data );
                break;
            case TouchPhase.Moved:
                EventTouchMoved.Invoke( touch_data );
                break;
            case TouchPhase.Stationary:
                EventTouchStationary.Invoke( touch_data );
                break;
            case TouchPhase.Ended:
            case TouchPhase.Canceled:
                EventTouchEnd.Invoke( touch_data );
                break;
            }

        }
Example #2
0
		internal bool SetWithMouseData( ulong updateTick, float deltaTime )
		{
			// Unity Remote and possibly some platforms like WP8 simulates mouse with
			// touches so detect that situation and reject the mouse.
			if (Input.touchCount > 0)
			{
				return false;
			}

			var mousePosition = new Vector2( Mathf.Round( Input.mousePosition.x ), Mathf.Round( Input.mousePosition.y ) );
			
			if (Input.GetMouseButtonDown( 0 ))
			{
				phase = TouchPhase.Began;
				tapCount = 1;

				deltaPosition = Vector2.zero;
				lastPosition = mousePosition;
				position = mousePosition;

				this.deltaTime = deltaTime;
				this.updateTick = updateTick;

				return true;
			}

			if (Input.GetMouseButtonUp( 0 ))
			{
				phase = TouchPhase.Ended;	

				tapCount = 1;

				deltaPosition = mousePosition - lastPosition;
				lastPosition = position;
				position = mousePosition;

				this.deltaTime = deltaTime;
				this.updateTick = updateTick;

				return true;
			}

			if (Input.GetMouseButton( 0 ))
			{
				phase = TouchPhase.Moved;

				tapCount = 1;

				deltaPosition = mousePosition - lastPosition;
				lastPosition = position;
				position = mousePosition;

				this.deltaTime = deltaTime;
				this.updateTick = updateTick;

				return true;
			}

			return false;
		}
Example #3
0
 public void In(
     [FriendlyName("A", "First value to compare.")] TouchPhase A,
     [FriendlyName("B", "Second value to compare.")] TouchPhase B
     )
 {
     m_CompareValue = A == B;
 }
Example #4
0
        public void SetTouch(int touchId, TouchPhase phase, Vector2 position, float pressure, Vector2 delta = default, bool queueEventOnly = true,
                             Touchscreen screen = null, double time = -1, double timeOffset = 0)
        {
            if (screen == null)
            {
                screen = Touchscreen.current;
                if (screen == null)
                {
                    throw new InvalidOperationException("No touchscreen has been added");
                }
            }

            InputSystem.QueueStateEvent(screen, new TouchState
            {
                touchId  = touchId,
                phase    = phase,
                position = position,
                delta    = delta,
                pressure = pressure,
            }, (time >= 0 ? time : InputRuntime.s_Instance.currentTime) + timeOffset);
            if (!queueEventOnly)
            {
                InputSystem.Update();
            }
        }
Example #5
0
        /// <summary>
        /// 处理手指当前交互状态
        /// </summary>
        protected override void UpdatePressedAndReleased(ref RaycastResult raycast)
        {
            currentDis = raycastDistance;
            if (raycast.isValid && raycast.gameObject != null)
            {
                currentDis = Vector3.Distance(raycast.worldPosition, origin);
            }

            if (currentDis >= checkDistance)
            {
                phase = TouchPhase.Canceled;
            }
            else if (currentDis < pressedDis)
            {
                if (phase == TouchPhase.Canceled || phase == TouchPhase.Ended)
                {
                    phase = TouchPhase.Began;
                }
                else if (phase == TouchPhase.Began)
                {
                    phase = TouchPhase.Moved;
                }
            }
            else
            {
                phase = TouchPhase.Ended;
            }
        }
Example #6
0
		internal void SetWithTouchData( UnityEngine.Touch touch, ulong updateTick, float deltaTime )
		{
			phase = touch.phase;
			tapCount = touch.tapCount;

			var touchPosition = touch.position;

			// Deal with Unity Remote weirdness.
			if (touchPosition.x < 0.0f)
			{
				touchPosition.x = Screen.width + touchPosition.x;
			}

			if (phase == TouchPhase.Began)
			{
				deltaPosition = Vector2.zero;
				lastPosition = touchPosition;
				position = touchPosition;
			}
			else
			{
				if (phase == TouchPhase.Stationary)
				{
					phase = TouchPhase.Moved;
				}

				deltaPosition = touchPosition - lastPosition;
				lastPosition = position;
				position = touchPosition;
			}

			this.deltaTime = deltaTime;
			this.updateTick = updateTick;
		}
Example #7
0
    void Update()
    {
        if (frameTouches.Length > 0 && frameTouches[0].phase == TouchPhase.Ended)
        {
            frameTouches = new Touch[0];
        }

        Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

        if (Input.GetMouseButtonDown(0) && touchCount == 0)
        {
            // New touch
            Touch t = new Touch(0, pos, Vector2.zero, 0f, 0, TouchPhase.Began);
            frameTouches = new Touch[1] {
                t
            };
            touchCount = 1;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            // Removed touch
            Vector2 deltaPos = frameTouches[0].position - pos;
            Touch   t        = new Touch(0, pos, deltaPos, 0f, 0, TouchPhase.Ended);
            frameTouches[0] = t;
            touchCount      = 0;
        }
        else if (Input.GetMouseButton(0))
        {
            Vector2    deltaPos = frameTouches[0].position - pos;
            TouchPhase phase    = deltaPos == Vector2.zero ? TouchPhase.Stationary : TouchPhase.Moved;
            Touch      t        = new Touch(0, pos, deltaPos, 0f, 0, phase);
            frameTouches[0] = t;
        }
    }
Example #8
0
        public (TouchPhase, Vector2) GetMouseTouch(out bool isClicked)
        {
            isClicked = true;
            TouchPhase touchPhase = TouchPhase.Began;
            Vector2    position   = Input.mousePosition;

            if (Input.GetMouseButtonDown(0))
            {
                touchPhase = TouchPhase.Began;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                touchPhase = TouchPhase.Ended;
            }
            else if (Input.GetMouseButton(0))
            {
                touchPhase = TouchPhase.Moved;
            }
            else
            {
                isClicked = false;
            }


            return(touchPhase, position);
        }
Example #9
0
    //funcion que recibe los toques o clicks
    private void HandleTouch(int touchFingerId, Vector3 touchPosition, TouchPhase touchPhase)
    {
        switch (touchPhase)
        {
        //fase 1 (cuandos se presiona)
        case TouchPhase.Began:
            //si esta en modo seleccion de objetivos genero el raycast
            if (this.selectingTarget)
            {
                RaycastHit hit;
                Ray        ray = mainCamera.ScreenPointToRay(touchPosition);
                Debug.DrawRay(ray.origin, ray.direction * 50, Color.red, 50000000f);
                if (Physics.Raycast(ray, out hit))
                {
                    GameObject character = hit.collider.gameObject;
                    //si el raycast golpea un personaje
                    if (character.name.Equals("Character(Clone)"))
                    {
                        //solidifico el personaje
                        foreach (Renderer renderer in character.GetComponentsInChildren <Renderer>())
                        {
                            renderer.material.shader = Shader.Find("Standard");
                        }

                        //termino la fase de seleccion de objetivo
                        this.selectingTarget = false;

                        //desactivo el boton del personaje
                        lastButtonActPressed.buttonChar.GetComponent <ButtonChar>().isActive = false;

                        //desbloqueo el menu de personajes
                        foreach (Button charButton in GameObject.Find("Character Menu").GetComponentsInChildren <Button>())
                        {
                            if (charButton.GetComponent <ButtonChar>().isActive)
                            {
                                charButton.GetComponent <CanvasGroup>().interactable = true;
                            }
                        }

                        //guardo la accion en el arreglo de acciones
                        actions.Add(new Action(lastButtonActPressed.character, character, lastButtonActPressed.skill));

                        //solidifico los personajes dentro de unos segundos
                        StartCoroutine(waitforSolidificateCharacters(0.7f));
                    }
                }
            }
            break;

        //fase 2 (cuando se mantiene)
        case TouchPhase.Moved:

            break;

        //fase 3 (cuando se suelta)
        case TouchPhase.Ended:
            // TODO
            break;
        }
    }
Example #10
0
    public void Dragchoice(PointerEventData pointer, TouchPhase state)
    {
        switch (state)
        {
        case TouchPhase.Began:
            GameObject.Find("choicemask").transform.GetChild(0).gameObject.SetActive(true);
            GameObject.Find("koreamask").transform.GetChild(0).gameObject.SetActive(false);
            GameObject.Find("chinamask").transform.GetChild(0).gameObject.SetActive(false);
            GameObject.Find("japanmask").transform.GetChild(0).gameObject.SetActive(false);
            break;

        case TouchPhase.Moved:
            _deltaInputPos = GetInputCanvasPosition(pointer.delta);
            GameObject.Find("choicemask").transform.GetChild(0).gameObject.SetActive(true);
            GameObject.Find("koreamask").transform.GetChild(0).gameObject.SetActive(false);
            GameObject.Find("chinamask").transform.GetChild(0).gameObject.SetActive(false);
            GameObject.Find("japanmask").transform.GetChild(0).gameObject.SetActive(false);
            _movementCtrl.SetMovement(_deltaInputPos, true);
            break;

        case TouchPhase.Ended:
            if (_movementCtrl.IsMovementEnded() == true)
            {
                Invoke("ListDone", 2);
            }
            _movementCtrl.SetMovement(_deltaInputPos / Time.deltaTime, false);
            break;
        }
    }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        // Get the touches
        Touch[] touches = Input.touches;

        if (touches.Length > 0)
        {
            if (touches.Length == 1)
            {
                //Get the phase of the first touch
                TouchPhase phase = touches [0].phase;

                switch (phase)
                {
                case TouchPhase.Moved:

                    // If the camera isn't blocked
                    if (!blockCameraMovement)
                    {
                        // Create a movement vector that saves the delta position and translate it
                        Vector2 movement = Input.touches [0].deltaPosition * speedMovement * Time.deltaTime;
                        transform.Translate(movement.x * -1, 0, 0);

                        // We clamp the area of the camera movement and check the position
                        Vector3 pos = transform.position;
                        pos.x = Mathf.Clamp(transform.position.x, 2, 6);
                        transform.position = pos;
                    }


                    break;
                }
            }
        }
    }
Example #12
0
        internal bool GetActionToggleDebugMenuWithTouch()
        {
#if USE_INPUT_SYSTEM
            var touches    = InputSystem.EnhancedTouch.Touch.activeTouches;
            var touchCount = touches.Count;
            const InputSystem.TouchPhase touchPhaseBegan = InputSystem.TouchPhase.Began;
#else
            var touches    = Input.touches;
            var touchCount = Input.touchCount;
            const TouchPhase touchPhaseBegan = TouchPhase.Began;
#endif
            if (touchCount == 3)
            {
                foreach (var touch in touches)
                {
                    // Gesture: 3-finger double-tap
                    if (touch.phase == touchPhaseBegan && touch.tapCount == 2)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override void SetTouch(ref Touch touch, int count, float deltaTime)
        {
            // 無効指定されているなら処理しない.
            // 2本指のタッチがあった時点で処理しない.
            if (!_enabled || count > 0)
            {
                return;
            }

            TouchPhase phase = touch.phase;

            if (phase == TouchPhase.Began)
            {
                _startPos = touch.position;
                _timer    = 0.0f;
            }

            if (phase == TouchPhase.Ended)
            {
                Vector2 now     = touch.position;
                Vector2 diffPos = new Vector2(now.x - _startPos.x, now.y - _startPos.y);

                if (Check(diffPos, _timer))
                {
                    _position = touch.position;
                    _callback();
                }
            }

            _timer += deltaTime;
        }
Example #14
0
    // Update is called once per frame
    void Update()
    {
        if ((!alreadyShoot) && Input.touchCount >= 1)
        {
            Debug.Log("Touched");

            Touch touch = Input.touches[0];

            TouchPhase tp = touch.phase;

            if (tp == TouchPhase.Began)
            {
                start = screenToWorld(touch.position);
            }

            if (tp == TouchPhase.Ended)
            {
                end = screenToWorld(touch.position);

                rb.AddForce((end - start) * force);
                alreadyShoot = true;
                Invoke("TestGoal", 3f);
            }
        }
    }
Example #15
0
    void UpdateOnDesktop()
    {
        touchCount = 0;
        position   = Input.mousePosition;

        if (Input.GetMouseButton(0))
        {
            touchCount    = 1;
            phase         = TouchPhase.Began;
            _lastPosition = position;
            deltaPosition = Vector2.zero;
            return;
        }

        if (Input.GetMouseButton(0))
        {
            touchCount    = 1;
            phase         = TouchPhase.Ended;
            deltaPosition = position - _lastPosition;
            return;
        }

        if (Input.GetMouseButton(0))
        {
            touchCount = 1;
        }

        deltaPosition = position - _lastPosition;
        phase         = deltaPosition == Vector2.zero ? TouchPhase.Stationary : TouchPhase.Moved;
        _lastPosition = position;
    }
 private void HandleTouch(int touchFingerId, Vector2 touchPosition, TouchPhase touchPhase)
 {
     Vector3 point = Camera.main.ScreenToWorldPoint(touchPosition);
     RaycastHit hit;
     Ray ray = Camera.main.ScreenPointToRay(touchPosition);
     Physics.Raycast(ray, out hit,100f, layer.value);
     if (hit.collider)
     {
         switch(hit.collider.tag)
         {
             case JUMP_TAG:
                 HandleJump(hit.collider.gameObject, touchFingerId, touchPosition, touchPhase);
                 break;
             case TELEPORT_BUTTON_TAG:
                 HandleTeleportSwitch(hit.collider.gameObject, touchFingerId, touchPosition, touchPhase);
                 break;
             case CRUSHER_TAG:
                 HandleCrusher(hit.collider.gameObject, touchFingerId, touchPosition, touchPhase);
                 break;
             case LEVER_TAG:
                 HandleLever(hit.collider.gameObject, touchFingerId, touchPosition, touchPhase);
                 break;
             default:
                 break;
         }
     }
 }
Example #17
0
    static public List <int> GetTouchIndexes(TouchPhase touchPhase)
    {
        List <int> indexes = new List <int> ();

                #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
        foreach (Touch touch in Input.touches)
        {
            if (touch.phase == touchPhase)
            {
                indexes.Add(touch.fingerId);
            }
        }
                #else
        if (Input.GetMouseButtonDown(0) && touchPhase == TouchPhase.Began)
        {
            indexes.Add(0);
        }
        else if (Input.GetMouseButton(0) && (touchPhase == TouchPhase.Moved || touchPhase == TouchPhase.Stationary))
        {
            indexes.Add(0);
        }
        else if (Input.GetMouseButtonUp(0) && (touchPhase == TouchPhase.Ended || touchPhase == TouchPhase.Canceled))
        {
            indexes.Add(0);
        }
                #endif
        return(indexes);
    }
Example #18
0
    void CalculateTouches(TouchPhase phase)
    {
        switch (phase)
        {
        case TouchPhase.Began:
            if (CurrentGameState == GameState.AwakeTap)
            {
                if (OnStickStartGrow != null)
                {
                    OnStickStartGrow();
                }
                CurrentGameState = GameState.ClickDown;
            }
            break;

        case TouchPhase.Ended:
            if (CurrentGameState == GameState.ClickDown)
            {
                if (OnStickStopGrow != null)
                {
                    OnStickStopGrow();
                }
                CurrentGameState = GameState.ClickUp;
            }
            break;
        }
    }
Example #19
0
        public override void OnTouch(Vector3 position, TouchPhase status)
        {
//			if (status == TouchPhase.Ended) {
//
//			}

//			if (status == TouchPhase.Ended) {
//				if (Input.GetKey (KeyCode.LeftShift)) {
//					Vector2Int coordinates = GetCoordinates (position);
//					Debug.Log (coordinates + " " + GetPiece(coordinates));
//					if (GetPiece (coordinates) != null) {
//						Debug.Log (GetPiece (coordinates).state);
//					}
//				} else {
//					matchFinder.FindMatches ();
//				}
            //			Vector2Int coordinates = GetCoordinates (position);
            //			Debug.Log (coordinates);
            //			if (HasPiece (coordinates)) {
            ////				mopiece.spriteRenderer.color = Color.white;
            ////				mopiece.MoveTo (GetPiecePosition (coordinates), OnPieceArrived);
            //				DestroyPieces(new Vector2Int[] {coordinates, coordinates + new Vector2Int(0, 0	), coordinates + new Vector2Int(0, 2)});
            //			}
//			}
        }
Example #20
0
 static public int GetTouchIndex(TouchPhase touchPhase)
 {
     if (!IsHasTouch())
     {
         return(-1);
     }
             #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
     foreach (Touch touch in Input.touches)
     {
         if (touch.phase == touchPhase)
         {
             return(touch.fingerId);
         }
     }
             #else
     if (Input.GetMouseButtonDown(0) && touchPhase == TouchPhase.Began)
     {
         return(0);
     }
     else if (Input.GetMouseButton(0) && (touchPhase == TouchPhase.Moved || touchPhase == TouchPhase.Stationary))
     {
         return(0);
     }
     else if (Input.GetMouseButtonUp(0) && (touchPhase == TouchPhase.Ended || touchPhase == TouchPhase.Canceled))
     {
         return(0);
     }
             #endif
     return(-1);
 }
Example #21
0
        internal void SetWithTouchData(UnityEngine.Touch touch, ulong updateTick, float deltaTime)
        {
            phase    = touch.phase;
            tapCount = touch.tapCount;

            var touchPosition = touch.position;

            // Deal with Unity Remote weirdness.
            if (touchPosition.x < 0.0f)
            {
                touchPosition.x = Screen.width + touchPosition.x;
            }

            if (phase == TouchPhase.Began)
            {
                deltaPosition = Vector2.zero;
                lastPosition  = touchPosition;
                position      = touchPosition;
            }
            else
            {
                if (phase == TouchPhase.Stationary)
                {
                    phase = TouchPhase.Moved;
                }

                deltaPosition = touchPosition - lastPosition;
                lastPosition  = position;
                position      = touchPosition;
            }

            this.deltaTime  = deltaTime;
            this.updateTick = updateTick;
        }
    private void updateSingle()
    {
        //单指触摸
        mIsSingleTouch = true;

        Touch      touch   = Input.GetTouch(0);
        TouchPhase phase   = touch.phase;
        float      nowTime = Time.time;
        Vector2    pos     = touch.position;

        switch (phase)
        {
        case TouchPhase.Began:
            onTouchBegin(nowTime, pos);
            break;

        case TouchPhase.Canceled:
            onTouchCancle();
            break;

        case TouchPhase.Ended:
            onTouchEnd(nowTime, pos);
            break;

        case TouchPhase.Moved:
            Vector2 delta = touch.deltaPosition;
            onTouchMove(pos, delta);
            break;

        case TouchPhase.Stationary:
            onStaionary(nowTime, pos);
            break;
        }
    }
Example #23
0
    private void MapTouchPhase(TouchPhase phase)
    {
        switch (phase)
        {
        case TouchPhase.Began:
            Captured = true;
            pressed  = true;
            released = false;
            held     = false;
            break;

        case TouchPhase.Ended:
            Captured = true;
            pressed  = false;
            held     = false;
            released = true;
            break;

        case TouchPhase.Moved:
        case TouchPhase.Stationary:
            Captured = true;
            pressed  = false;
            held     = true;
            released = false;
            break;

        case TouchPhase.Canceled:
            Captured = false;
            pressed  = false;
            held     = false;
            released = false;
            break;
        }
    }
Example #24
0
 public W7Touch(uint touchId, Vector2 touchPosition)
 {
     this.id = touchId;
     UpdateTouch(touchPosition);
     phase = TouchPhase.Began;
     updated = true;
 }
    void Update()
    {
        ///Verifico a quantidade de toques na tela
        int nbTouches = Input.touchCount;

        ///Se for maior q 0, verifico o que será feito com cada um desses toques
        if (nbTouches > 0)
        {
            ///Para cada toque
            for (int i = 0; i < nbTouches; i++)
            {
                ///Pego o toque de posição i no Array de toques
                Touch touch = Input.GetTouch(i);

                ///Verifico qual é a fase do toque
                TouchPhase phase = touch.phase;

                switch (phase)
                {
                case TouchPhase.Began:

                    if (touch.position.y > Screen.height / 2)
                    {
                        SendMessageToTargets(true);
                    }
                    else
                    {
                        SendMessageToTargets(false);
                    }

                    break;
                }
            }
        }
    }
Example #26
0
    void UpdateOnDesktop()
    {
        touchCount = 0;
        position = Input.mousePosition;

        if (Input.GetMouseButton(0))
        {
            touchCount = 1;
            phase = TouchPhase.Began;
            _lastPosition = position;
            deltaPosition = Vector2.zero;
            return;
        }

        if (Input.GetMouseButton(0))
        {
            touchCount = 1;
            phase = TouchPhase.Ended;
            deltaPosition = position - _lastPosition;
            return;
        }

        if (Input.GetMouseButton(0))
        {
            touchCount = 1;
        }

        deltaPosition = position - _lastPosition;
        phase = deltaPosition == Vector2.zero ? TouchPhase.Stationary : TouchPhase.Moved;
        _lastPosition = position;
    }
        /// <summary>
        /// event listener of wall touched
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="cameraIndex"></param>
        /// <param name="phase"></param>
        /// <param name="index"></param>
        private void WallTouched(Vector2 pos, int cameraIndex, TouchPhase phase, int index)
        {
            if (paintFinished)
            {
                return;
            }

            Camera cam = AbstractImmersiveCamera.CurrentImmersiveCamera.cameras[cameraIndex];

            switch (phase)
            {
            case TouchPhase.Began:
                CheckWipeAssets(index);
                //EnableDisableBrushParticle(true, index);
                OnWipe(pos, phase, index, cam);
                break;

            case TouchPhase.Moved:
                OnWipe(pos, phase, index, cam);
                break;

            case TouchPhase.Ended:
                EnableDisableBrushParticle(false, index);
                break;
            }
        }
        public void Touch(int id, Vector2 position, TouchPhase phase)
        {
            m_LastEventFrame = Time.frameCount;

            var newPhase = ToLegacy(phase);

            m_NextTouch.position  = position;
            m_NextTouch.phase     = newPhase;
            m_NextTouch.fingerId  = id;
            m_NextTouch.deltaTime = (float)(EditorApplication.timeSinceStartup - m_LastEventTime);
            m_LastEventTime       = EditorApplication.timeSinceStartup;

            if (newPhase == UnityEngine.TouchPhase.Began)
            {
                m_TouchInProgress     = true;
                m_NextTouch.tapCount  = GetTapCount(m_NextTouch.position);
                m_NextTouch.deltaTime = 0;
            }
            else if (m_NextTouch.phase == UnityEngine.TouchPhase.Ended || m_NextTouch.phase == UnityEngine.TouchPhase.Canceled)
            {
                m_TouchInProgress = false;
                if (m_NextTouch.phase == UnityEngine.TouchPhase.Ended)
                {
                    m_EndedTouches.Add(new EndedTouch(m_NextTouch.position, EditorApplication.timeSinceStartup, m_NextTouch.tapCount));
                }
            }
            Input.SimulateTouch(m_NextTouch);
        }
 /// <summary>
 /// On Wipe Occuring
 /// </summary>
 /// <param name="phase"></param>
 /// <param name="position"></param>
 /// <param name="currentPercentage"></param>
 void WipeOccuring(TouchPhase phase, Vector2 position, float currentPercentage)
 {
     foreach (var handler in onWipeEventHandlers)
     {
         handler.WipeOccuring(phase, position, currentPercentage);
     }
 }
Example #30
0
		internal void SetWithTouchData( UnityEngine.Touch touch, ulong updateTick, float deltaTime )
		{
			phase = touch.phase;
			tapCount = touch.tapCount;

			if (phase == TouchPhase.Began)
			{
				deltaPosition =  Vector2.zero;
				lastPosition = touch.position;
				position = touch.position;
			}
			else
			{
				if (phase == TouchPhase.Stationary)
				{
					phase = TouchPhase.Moved;
				}

				deltaPosition = touch.position - lastPosition;
				lastPosition = position;
				position = touch.position;
			}

			this.deltaTime = deltaTime;
			this.updateTick = updateTick;
		}
 void CastTouchRay(Vector2 position, TouchPhase phase)
 {
     Vector2 worldPoint = this.camera.ScreenToWorldPoint(position);
     RaycastHit2D hit = Physics2D.Raycast(new Vector2(worldPoint.x, worldPoint.y), Vector2.zero, 0);
     bool didHit = null != hit.collider;
     JollyDebug.Watch (this, "CastTouchRayHit", didHit.ToString());
     if (didHit)
     {
         GameObject recipient = hit.transform.gameObject;
         switch (phase)
         {
         case TouchPhase.Began:
             recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
             break;
         case TouchPhase.Ended:
             recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
             break;
         case TouchPhase.Stationary:
         case TouchPhase.Moved:
             recipient.SendMessage ("OnTouch", hit.point, SendMessageOptions.DontRequireReceiver);
             break;
         case TouchPhase.Canceled:
             recipient.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
             break;
         }
     }
 }
Example #32
0
    //this function handles touch input

    /*
     * touchFingerId is the touch index, 10 for mouse
     * touchPosition is where on the screen the touch is
     * touchPhase is either Began, Moved, or Ended
     * deltaPosition is a vector of the difference in position since last tick
     */
    private void HandleTouch(int touchFingerId, Vector3 touchPosition, TouchPhase touchPhase)
    {
        switch (touchPhase)
        {
        case TouchPhase.Began:
            Ray ray = Camera.main.ScreenPointToRay(touchPosition);
            touchTarget = null;
            touchStart  = new Vector2(touchPosition.x, touchPosition.y);
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("Tile")))
            {
                touchTarget = hit.collider.gameObject;
            }
            break;

        case TouchPhase.Moved:
            break;

        case TouchPhase.Ended:
            findTouchVector(touchTarget, ((Vector2)touchPosition) - touchStart);
            break;

        default:
            break;
        }
    }
Example #33
0
    private void processTouchInput()
    {
        if (Input.touchCount == 0)
        {
            return;
        }

        Touch      touch = Input.touches [0];
        TouchPhase phase = touch.phase;

        if (phase == TouchPhase.Began)
        {
            touchStartPos = touch.position;
        }
        else if (phase == TouchPhase.Ended || phase == TouchPhase.Canceled)
        {
            if (touch.position.x - touchStartPos.x < 0)
            {
                runDirection -= 90;
            }
            else
            {
                runDirection += 90;
            }
        }
    }
            public static EventBase MakeEvent(TouchPhase phase, Vector2 position, EventModifiers modifiers = EventModifiers.None, MouseButton button = MouseButton.LeftMouse)
            {
                var touch = MakeDefaultTouch();

                touch.position = position;
                touch.phase    = phase;

                if (button != MouseButton.LeftMouse)
                {
                    PointerDeviceState.PressButton(touch.fingerId, (int)button);
                }

                switch (touch.phase)
                {
                case TouchPhase.Began:
                    return(PointerDownEvent.GetPooled(touch, modifiers));

                case TouchPhase.Moved:
                    return(PointerMoveEvent.GetPooled(touch, modifiers));

                case TouchPhase.Ended:
                    return(PointerUpEvent.GetPooled(touch, modifiers));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        public void Touch(int id, Vector2 position, TouchPhase phase)
        {
            // Input.SimulateTouch expects a single event each frame and if sent two like Moved then Ended will create a separate touch.
            // So we delay calling Input.SimulateTouch until update.
            var newPhase = ToLegacy(phase);

            if (Time.frameCount == m_LastEventFrame)
            {
                if (m_NextPhase == UnityEngine.TouchPhase.Began)
                {
                    return;
                }
                else if (m_NextPhase == UnityEngine.TouchPhase.Moved && newPhase == UnityEngine.TouchPhase.Ended)
                {
                    m_NextPhase    = UnityEngine.TouchPhase.Ended;
                    m_NextPosition = position;
                }
            }
            else
            {
                m_NextPosition   = position;
                m_NextPhase      = newPhase;
                m_NextId         = id;
                m_LastEventFrame = Time.frameCount;
            }
        }
Example #36
0
        public void Operate(Vector3 pos, TouchPhase touchPhase)
        {
            switch (touchPhase)
            {
            case TouchPhase.Began:
                Selected(pos);
                break;

            case TouchPhase.Moved:
                Moved(pos);
                break;

            case TouchPhase.Stationary:
                Stationary(pos);
                break;

            case TouchPhase.Ended:
                Released(pos);
                break;

            case TouchPhase.Canceled:
                Canceled(pos);
                break;
            }
        }
    void rotationEnabled()
    {
        if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);
            switch (touch.phase)
            {
            case TouchPhase.Began:

                lastTouchPhase = TouchPhase.Began;

                selectObject(touch);
                return;

            case TouchPhase.Moved:

                lastTouchPhase = TouchPhase.Moved;
                rotateAcrossYusingX(touch);
                return;

            case TouchPhase.Ended:
                if (lastTouchPhase == TouchPhase.Moved)
                {
                    deselectGameObject();
                }

                lastTouchPhase = TouchPhase.Moved;
                return;
            }
        }
    }
Example #38
0
        public override void Reset () {
            base.Reset();

            fingerId = new ConcreteIntVar();
            touchPhase = TouchPhase.Began;
            storeFingerId = new ConcreteIntVar();
            storeTouchPos = new ConcreteVector3Var();
        }
Example #39
0
 public tk2dUITouch(TouchPhase phase, int fingerID, Vector2 position, Vector2 deltaPosition, float deltaTime) : this()
 {
     this.phase = phase;
     this.fingerId = fingerId;
     this.position = position;
     this.deltaPosition = deltaPosition;
     this.deltaTime = deltaTime;
 }
Example #40
0
 public void UpdateTouch(Vector2 touchPosition) {
     position = touchPosition;
     position.Scale(new Vector2(1f / (float)Screen.currentResolution.width, 1f / (float)Screen.currentResolution.height));
     position.y = 1 - position.y;
     position.Scale(new Vector2((float)Screen.width, (float)Screen.height));
     phase = TouchPhase.Moved;
     updated = true;
 }
 private void HandleTeleportSwitch(GameObject subject, int touchFingerId, Vector3 touchPosition, TouchPhase touchPhase)
 {
     Button button = subject.GetComponent<Button>();
     if (button)
     {
         button.OnTouched(touchPhase);
     }
 }
Example #42
0
 public tk2dUITouch(TouchPhase _phase, int _fingerId, Vector2 _position, Vector2 _deltaPosition, float _deltaTime) : this()
 {
     this.phase = _phase;
     this.fingerId = _fingerId;
     this.position = _position;
     this.deltaPosition = _deltaPosition;
     this.deltaTime = _deltaTime;
 }
 private void HandleJump(GameObject subject, int touchFingerId, Vector3 touchPosition, TouchPhase touchPhase)
 {
     Jump jump = subject.GetComponent<Jump>();
     if (jump)
     {
         jump.OnTouched(touchPhase);
     }
 }
Example #44
0
    //Coroutine, which gets Started in "Start()" and runs over the whole game to check for swipes
    public IEnumerator CheckHorizontalSwipes(System.Action onDownSwipe, System.Action onUpSwipe, System.Action onRightSwipe, System.Action onLeftSwipe)
    {
        while (true)
        { //Loop. Otherwise we wouldnt check continuously ;-)
            foreach (Touch touch in Input.touches)
            { //For every touch in the Input.touches - array...
                switch (touch.phase)
                {
                case TouchPhase.Began: //The finger first touched the screen --> It could be(come) a swipe
                    couldBeSwipe = true;
                    startPos = touch.position;  //Position where the touch started
                    swipeStartTime = Time.time; //The time it started
                    stationaryForFrames = 0;
                    break;
                case TouchPhase.Stationary: //Is the touch stationary? --> No swipe then!
                    if (isContinouslyStationary(frames:6))
                        couldBeSwipe = false;
                    break;
                case TouchPhase.Ended:
                    if (isASwipe(touch))
                    {
                        couldBeSwipe = false; //<-- Otherwise this part would be called over and over again.
                        if (Mathf.Sign(touch.position.y - startPos.y) == 1f) //Swipe-direction, either 1 or -1.
                            onUpSwipe(); //Right-swipe

                        else
                            onDownSwipe(); //Left-swipe

        //						if (Mathf.Sign(touch.position.x - startPos.x) == 1f) //Swipe-direction, either 1 or -1.
        //							onRightSwipe(); //Right-swipe
        //
        //						else
        //							onLeftSwipe(); //Left-swipe
                    }

                    if (isASwipe2(touch))
                    {
                        couldBeSwipe = false; //<-- Otherwise this part would be called over and over again.
        //						if (Mathf.Sign(touch.position.y - startPos.y) == 1f) //Swipe-direction, either 1 or -1.
        //							onUpSwipe(); //Right-swipe
        //
        //						else
        //							onDownSwipe(); //Left-swipe

                        if (Mathf.Sign(touch.position.x - startPos.x) == 1f) //Swipe-direction, either 1 or -1.
                            onRightSwipe(); //Right-swipe

                        else
                            onLeftSwipe(); //Left-swipe
                    }

                    break;
                }
                lastPhase = touch.phase;
            }
            yield return null;
        }
    }
Example #45
0
        public override void Reset () {
            base.Reset();

            position = new ConcreteRectVar(new Rect(0f,0f,1f,1f));
            fingerId = new ConcreteIntVar();
            touchPhase = TouchPhase.Began;
            storeFingerId = new ConcreteIntVar();
            storeTouchPos = new ConcreteVector3Var();
        }
Example #46
0
		public TouchInfo(TouchInfo otherTouch) {
			fingerId = otherTouch.fingerId;
			beginFingerId = otherTouch.beginFingerId;
			deltaPosition = otherTouch.deltaPosition;
			position = otherTouch.position;
			beginPosition = otherTouch.beginPosition;
			beginTime = otherTouch.beginTime;
			phase = otherTouch.phase;
		}
Example #47
0
 public WHumanInput(Vector2 deltaPosition, float deltaTime, int buttonIndex, TouchPhase phase, Vector2 position, int tapCount)
 {
     _deltaPosition = deltaPosition;
     _deltaTime = deltaTime;
     _buttonIndex = buttonIndex;
     _phase = phase;
     _position = position;
     _tapCount = tapCount;
 }
    // Update is called once per frame
    void Update()
    {
        touchDown = Input.touchCount > 0;

        if( touchDown )
        {
            Phase = Input.touches[0].phase;
        }
    }
Example #49
0
 // Chech if touch exist
 public bool TouchAnyWhere(TouchPhase? phase = null)
 {
     foreach (var touch in Input.touches)
     {
         if (phase == null || touch.phase == phase)
             if (touch.position.x > baseGame.screenStartX && touch.position.x < baseGame.screenEndX)
                 return true;
     }
     return false;
 }
Example #50
0
 // Check if touch down
 public bool TouchDown(TouchPhase? phase = null)
 {
     foreach (var touch in Input.touches)
     {
         if (phase == null || touch.phase == phase)
             if (touch.position.y > baseGame.screenStartY && touch.position.y < baseGame.screenMiddleY)
                 return TouchAnyWhere(phase);
     }
     return false;
 }
Example #51
0
    public GKTouch populateWithTouch( Touch touch )
    {
        position = touch.position;
        deltaPosition = touch.deltaPosition;
        deltaTime = touch.deltaTime;
        tapCount = touch.tapCount;
        phase = touch.phase;

        return this;
    }
Example #52
0
 public KZTouch(int id, Vector2 pos, Vector2 dpos, 
                float dtime, int tap, TouchPhase p)
 {
     fingerId=id;
     position=pos;
     deltaPosition=dpos;
     deltaTime=dtime;
     tapCount=tap;
     phase=p;
 }
Example #53
0
 //>>> enum KZTouchPhase {Hovered, Dragged} ?
 public KZTouch(Touch t)
 {
     fingerId=t.fingerId;//fid; //t.fingerId;
     //[ since fingerId didn't start with
     //  0 after resume
     position=t.position;
     deltaPosition=t.deltaPosition;
     deltaTime=t.deltaTime;
     tapCount=t.tapCount;
     phase=t.phase;
 }
Example #54
0
 void UpdateOnDevice()
 {
     touchCount = Input.touchCount;
     if (touchCount > 0)
     {
         Touch touch = Input.GetTouch(0);
         position = touch.position;
         deltaPosition = touch.deltaPosition;
         phase = touch.phase;
     }
 }
Example #55
0
 // Check touch in a vertical area
 public bool TouchInAreaY(float beginRatio, float endRatio, TouchPhase? phase = null)
 {
     int beginPixel = (int)(baseGame.screenHeight * beginRatio) + baseGame.screenStartY;
     int endPixel = (int)(baseGame.screenHeight * endRatio) + baseGame.screenStartY;
     foreach (var touch in Input.touches)
     {
         if (phase == null || touch.phase == phase)
             if (touch.position.y > beginPixel && touch.position.y < endPixel)
                 return TouchAnyWhere(phase);
     }
     return false;
 }
Example #56
0
 // Check touch in a horizontally area
 public bool TouchInAreaX(float beginRatio, float endRatio, TouchPhase? phase = null)
 {
     int beginPixel = (int)(baseGame.screenWidth * beginRatio) + baseGame.screenStartX;
     int endPixel = (int)(baseGame.screenWidth * endRatio) + baseGame.screenStartX;
     foreach (var touch in Input.touches)
     {
         if (phase == null || touch.phase == phase)
             if (touch.position.x > beginPixel && touch.position.x < endPixel)
                 return true;
     }
     return false;
 }
Example #57
0
		internal bool SetWithMouseData( ulong updateTick, float deltaTime )
		{
			var mousePosition = new Vector2( Mathf.Round( Input.mousePosition.x ), Mathf.Round( Input.mousePosition.y ) );
			
			if (Input.GetMouseButtonDown( 0 ))
			{
				phase = TouchPhase.Began;
				tapCount = 1;

				deltaPosition = Vector2.zero;
				lastPosition = mousePosition;
				position = mousePosition;

				this.deltaTime = deltaTime;
				this.updateTick = updateTick;

				return true;
			}

			if (Input.GetMouseButtonUp( 0 ))
			{
				phase = TouchPhase.Ended;	

				tapCount = 1;

				deltaPosition = mousePosition - lastPosition;
				lastPosition = position;
				position = mousePosition;

				this.deltaTime = deltaTime;
				this.updateTick = updateTick;

				return true;
			}

			if (Input.GetMouseButton( 0 ))
			{
				phase = TouchPhase.Moved;

				tapCount = 1;

				deltaPosition = mousePosition - lastPosition;
				lastPosition = position;
				position = mousePosition;

				this.deltaTime = deltaTime;
				this.updateTick = updateTick;

				return true;
			}

			return false;
		}
Example #58
0
        public override void Reset () {
            base.Reset();

            gameObject = new ConcreteGameObjectVar(this.self);
            fingerId = new ConcreteIntVar();
            touchPhase = TouchPhase.Began;
            distance = Mathf.Infinity;
            layerMask = -1;
            storeFingerId = new ConcreteIntVar();
            storeTouchPos = new ConcreteVector3Var();
            storePoint = new ConcreteVector3Var();
        }
		protected override void onSelected (GameObject f, TouchPhase phase)
		{
				if (viewlayer == 0) {
						if (phase == TouchPhase.Ended) {
								cammovetouch touch = GetComponent<cammovetouch> ();
								touch.PanTo (f);
								tweenUI (true);
								viewlayer = 1;
						}
						
				}
		}
Example #60
0
    public dfTouchInfo( int fingerID, TouchPhase phase, int tapCount, Vector2 position, Vector2 positionDelta, float timeDelta )
    {
        this.m_FingerId = fingerID;
        this.m_Phase = phase;
        this.m_Position = position;
        this.m_PositionDelta = positionDelta;
        this.m_TapCount = tapCount;
        this.m_TimeDelta = timeDelta;

        #if !UNITY_4_2
        this.m_RawPosition = position;
        #endif
    }