public static Vector2 GetLocalDelta()
    {
        var localValue = Vector2.zero;

        if (MouseToGlitchTouchManager.GetTouches().Count > 0)
        {
            GlitchTouch t = MouseToGlitchTouchManager.GetTouches()[0];
            localValue = MouseToGlitchTouchManager.GetSafeDeltaPosition(t.fingerId);
        }
        return(localValue);
    }
Exemplo n.º 2
0
    private void BeginFakeTouch()
    {
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new GlitchTouch();
        }

        lastFakeTouch.phase         = TouchPhase.Began;
        lastFakeTouch.deltaPosition = Vector2.zero;
        lastFakeTouch.deltaTime     = Time.unscaledDeltaTime;
        lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        lastFakeTouch.fingerId      = GlitchTouch.MAXFINGERS + 1;
    }
Exemplo n.º 3
0
    private void EndFakeTouch()
    {
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new GlitchTouch();
        }

        lastFakeTouch.phase = TouchPhase.Ended;
        //lastFakeTouch.deltaPosition = lastFakeTouch.deltaPosition;
        //lastFakeTouch.deltaTime = lastFakeTouch.deltaTime;
        //lastFakeTouch.position = lastFakeTouch.position;
        lastFakeTouch.fingerId = GlitchTouch.MAXFINGERS + 1;
        queueRelease           = false;
    }
Exemplo n.º 4
0
    private void MoveFakeTouch()
    {
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new GlitchTouch();
        }

        lastFakeTouch.phase = TouchPhase.Moved;
        Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

        lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
        lastFakeTouch.deltaTime     = Time.unscaledDeltaTime;
        lastFakeTouch.position      = newPosition;
        lastFakeTouch.fingerId      = GlitchTouch.MAXFINGERS + 1;
    }
    void Update()
    {
        if (touchStartPositions == null)
        {
            InitVectors();
        }

        touches = new List <GlitchTouch>();

#if !UNITY_STANDALONE
        for (int i = 0; i < Input.touchCount; i++)
        {
            var touch = Input.GetTouch(i);
            touches.Add(new GlitchTouch(touch));
            if (touch.phase == TouchPhase.Began)
            {
                touchStartPositions[touch.fingerId]    = touch.position;
                touchLastLastPositions[touch.fingerId] = touch.position;
                touchLastPositions[touch.fingerId]     = touch.position;
            }
            else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Ended)
            {
                touchLastLastPositions[touch.fingerId] = touchLastPositions[touch.fingerId];
                touchLastPositions[touch.fingerId]     = touch.position;
            }
        }
#endif

#if (UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_WEBGL)
        if (lastFakeTouch == null)
        {
            lastFakeTouch = new GlitchTouch();
        }

        if ((Input.GetMouseButtonDown(0)) || (Input.GetMouseButtonUp(0)) || queueRelease)
        {
            if (Input.GetMouseButtonDown(0))
            {
                lastFakeTouch.phase         = TouchPhase.Began;
                lastFakeTouch.deltaPosition = new Vector2(0, 0);
                lastFakeTouch.position      = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                lastFakeTouch.fingerId      = 0;
            }

            if (Input.GetMouseButtonUp(0) || queueRelease)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    queueRelease = true;
                }
                else
                {
                    lastFakeTouch.phase = TouchPhase.Ended;
                    Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                    lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
                    lastFakeTouch.position      = newPosition;
                    lastFakeTouch.fingerId      = 0;
                    queueRelease = false;
                }
            }
        }
        else if (Input.GetMouseButton(0))
        {
            lastFakeTouch.phase = TouchPhase.Moved;
            Vector2 newPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            lastFakeTouch.deltaPosition = newPosition - lastFakeTouch.position;
            lastFakeTouch.position      = newPosition;
            lastFakeTouch.fingerId      = 0;
        }
        else
        {
            lastFakeTouch = null;
        }

        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch);

            if (lastFakeTouch.phase == TouchPhase.Began)
            {
                touchStartPositions[0] = lastFakeTouch.position;
                touchLastLastPositions[lastFakeTouch.fingerId] = lastFakeTouch.position;
                touchLastPositions[lastFakeTouch.fingerId]     = lastFakeTouch.position;
            }
            else if (lastFakeTouch.phase == TouchPhase.Moved || lastFakeTouch.phase == TouchPhase.Stationary)
            {
                touchLastLastPositions[lastFakeTouch.fingerId] = touchLastPositions[lastFakeTouch.fingerId];
                touchLastPositions[lastFakeTouch.fingerId]     = lastFakeTouch.position;
            }
        }
#endif
    }
Exemplo n.º 6
0
    void Update()
    {
        touches = new List <GlitchTouch>();

        for (int i = 0; i < Input.touchCount; i++)
        {
            touches.Add(new GlitchTouch(Input.GetTouch(i)));
        }

#if (UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_WEBGL)
        if (queueRelease)
        {
            //Mouse tap received last frame, end touch this frame to simulate a tap.
            EndFakeTouch();
        }
        else if (Input.GetMouseButtonDown(0) && IsMouseWithinScreenBounds())
        {
            //Begin touch because mouse is within bounds
            BeginFakeTouch();

            //NOTE: (Down and Up in the same frame) == Mouse tap
            //Did we only recieve a tap? Schedule a release next frame!
            if (Input.GetMouseButtonUp(0))
            {
                queueRelease = true;
            }
        }
        else if (Input.GetMouseButtonUp(0) || !IsMouseWithinScreenBounds())
        {
            //If the touch had previously been registered, and mouse up or mouse leaves screen bounds, end the fake touch.
            if (lastFakeTouch != null && lastFakeTouch.phase != TouchPhase.Ended)
            {
                EndFakeTouch();
            }
            else
            {
                lastFakeTouch = null;
            }
        }
        else if (Input.GetMouseButton(0) && IsMouseWithinScreenBounds())
        {
            //NOTE: TouchPhase.Cancelled is never used for FakeTouches, so can be ignored.
            //If the touch previously began, moved or stayed, update the fake touch.
            if (lastFakeTouch != null && lastFakeTouch.phase != TouchPhase.Ended)
            {
                if ((new Vector2(Input.mousePosition.x, Input.mousePosition.y) - lastFakeTouch.position).magnitude < 0.1f)
                {
                    StayFakeTouch();
                }
                else
                {
                    MoveFakeTouch();
                }
            }
            else
            {
                //NOTE: For some reason GetMouseButton does not return true if OnMouseDown happens outside of screen.
                //Mouse was down outside screen bounds, meaning we should simulate a new touch, when it comes back!
                BeginFakeTouch();
            }
        }
        else
        {
            lastFakeTouch = null;
        }

        if (lastFakeTouch != null)
        {
            touches.Add(lastFakeTouch);
        }
#endif
    }