Ejemplo n.º 1
0
    void Update()
    {
        Input.multiTouchEnabled = multitouch;

        // update old touches
        foreach (Touch t in Input.touches)
        {
            // see if we already have a TouchWrapper for this particular Touch.
            VCTouchWrapper tw = null;
            foreach (VCTouchWrapper touchWrapper in touches)
            {
                if (touchWrapper.fingerId == t.fingerId)
                {
                    tw = touchWrapper;
                    break;
                }
            }

            if (tw == null)
            {
                // this is a new touch, add it to our active list

                // find an available TouchWrapper to use.
                VCTouchWrapper availableTw = null;
                foreach (VCTouchWrapper touchWrapper in touches)
                {
                    if (touchWrapper.fingerId == -1)
                    {
                        availableTw = touchWrapper;
                        break;
                    }
                }

                if (availableTw == null)
                {
                    Debug.LogWarning("Cannot find an available TouchWrapper to assign Touch info from!  Consider increasing VCTouchController.kMaxTouches.");
                }
                else
                {
                    availableTw.Set(t);
                }
            }
            else
            // touch we're already tracking, update it.
            {
                tw.visited = true;

                tw.deltaPosition = t.position - tw.position;
                tw.position      = t.position;
                tw.phase         = t.phase;
            }
        }

#if UNITY_EDITOR
        // use mouse input to emulate a touch.
        if (Input.GetMouseButtonDown(0))
        {
            VCTouchWrapper availableTw = null;
            foreach (VCTouchWrapper touchWrapper in touches)
            {
                if (touchWrapper.fingerId == -1)
                {
                    availableTw = touchWrapper;
                    break;
                }
            }

            if (availableTw == null)
            {
                // we're out of touches, can't emulate.
                Debug.LogWarning("Cannot find an available TouchWrapper to assign Mouse Emulated Touch info from!  Consider increasing VCTouchController.kMaxTouches.");
            }
            else
            {
                // populate the TouchWrapper with mouse input data.
                availableTw.phase           = TouchPhase.Began;
                availableTw.fingerId        = kEmulatedTouchFingerId;
                availableTw.deltaPosition.x = 0.0f;
                availableTw.deltaPosition.y = 0.0f;
                availableTw.position.x      = Input.mousePosition.x;
                availableTw.position.y      = Input.mousePosition.y;
                availableTw.visited         = true;
            }
        }
        else if (Input.GetMouseButton(0))
        {
            // find the emulated TouchWrapper
            VCTouchWrapper emulatedTw = null;
            foreach (VCTouchWrapper touchWrapper in touches)
            {
                if (touchWrapper.fingerId == kEmulatedTouchFingerId)
                {
                    emulatedTw = touchWrapper;
                    break;
                }
            }

            // update it
            emulatedTw.phase           = TouchPhase.Moved;
            emulatedTw.deltaPosition.x = Input.mousePosition.x - emulatedTw.position.x;
            emulatedTw.deltaPosition.y = Input.mousePosition.y - emulatedTw.position.y;
            emulatedTw.position.x      = Input.mousePosition.x;
            emulatedTw.position.y      = Input.mousePosition.y;
            emulatedTw.visited         = true;
        }
#endif

        // reset any previously active, but no longer active touch
        foreach (VCTouchWrapper tw in touches)
        {
            if (!tw.visited)
            {
                tw.Reset();
            }
            else
            {
                tw.visited = false;                 // ready to cull next frame
            }
        }

        // invalidate the ActiveTouches cache so it updates next time the user wants it.
        _activeTouchesCacheNeedsUpdate = true;
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (this.touches == null)
        {
            return;
        }
        try
        {
            Input.multiTouchEnabled = this.multitouch;
            if (Input.touches != null && Input.touchCount > 0)
            {
                Touch[] array = Input.touches;
                int     i     = 0;
                Touch   t;
                while (i < array.Length)
                {
                    t = array[i];
                    if (t.phase != TouchPhase.Began || !UICamera.Raycast(t.position, out UICamera.lastHit))
                    {
                        goto IL_C6;
                    }
                    if (!(UICamera.lastHit.collider == null))
                    {
                        if (UICamera.lastHit.collider.gameObject.name.Equals("JoyFront"))
                        {
                            goto IL_C6;
                        }
                    }
IL_1B4:
                    i++;
                    continue;
IL_C6:
                    VCTouchWrapper vCTouchWrapper = this.touches.FirstOrDefault((VCTouchWrapper x) => x.fingerId == t.fingerId);
                    if (vCTouchWrapper == null)
                    {
                        VCTouchWrapper vCTouchWrapper2 = this.touches.FirstOrDefault((VCTouchWrapper x) => x.fingerId == -1);
                        if (vCTouchWrapper2 != null)
                        {
                            vCTouchWrapper2.Set(t);
                        }
                        goto IL_1B4;
                    }
                    vCTouchWrapper.visited = true;
                    if (this.ignoreMultitouchErrorMovement && Input.touchCount > 1 && (vCTouchWrapper.position - t.position).sqrMagnitude > this.multiTouchErrorSqrMagnitudeMax)
                    {
                        goto IL_1B4;
                    }
                    vCTouchWrapper.deltaPosition = t.position - vCTouchWrapper.position;
                    vCTouchWrapper.position      = t.position;
                    vCTouchWrapper.phase         = t.phase;
                    goto IL_1B4;
                }
            }
            if (this.touches.Count > 0)
            {
                foreach (VCTouchWrapper current in this.touches)
                {
                    if (current != null)
                    {
                        if (!current.visited)
                        {
                            current.Reset();
                        }
                        else
                        {
                            current.visited = false;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LogSystem.LogError(new object[]
            {
                "Update VCTouchController",
                ex.ToString()
            });
        }
        this._activeTouchesCache = null;
    }