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;
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        private void UpdateInputs(bool enableMouse, bool enableTouch, bool emulateTouch)
        {
#if !UNITY_STANDALONE && !UNITY_EDITOR
            enableMouse = false;
#endif
            if (enableMouse)
            {
                // mouse move
                if (_mousePos != UnityEngine.Input.mousePosition)
                {
                    _mousePos = UnityEngine.Input.mousePosition;
                    UnityEngine.Vector2 mouse = ProjectPointer(_mousePos.x, _mousePos.y);

                    if (emulateTouch && _touchEmulated)
                    {
                        Noesis_TouchMove(_rendererId, mouse.x, mouse.y, 0);
                    }
                    else
                    {
                        Noesis_MouseMove(_rendererId, mouse.x, mouse.y);
                    }
                }

                // mouse wheel
                int mouseWheel = (int)(UnityEngine.Input.GetAxis("Mouse ScrollWheel") * 10.0f);
                if (mouseWheel != 0)
                {
                    UnityEngine.Vector2 mouse = ProjectPointer(_mousePos.x, _mousePos.y);
                    Noesis_MouseWheel(_rendererId, mouse.x, mouse.y, mouseWheel);
                }
            }

            if (enableTouch)
            {
                for (int i = 0; i < UnityEngine.Input.touchCount; i++)
                {
                    UnityEngine.Touch touch = UnityEngine.Input.GetTouch(i);
                    int id = touch.fingerId;
                    UnityEngine.Vector2    pos   = ProjectPointer(touch.position.x, touch.position.y);
                    UnityEngine.TouchPhase phase = touch.phase;

                    if (phase == UnityEngine.TouchPhase.Began)
                    {
                        Noesis_TouchDown(_rendererId, pos.x, pos.y, id);
                    }
                    else if (phase == UnityEngine.TouchPhase.Moved ||
                             phase == UnityEngine.TouchPhase.Stationary)
                    {
                        Noesis_TouchMove(_rendererId, pos.x, pos.y, id);
                    }
                    else
                    {
                        Noesis_TouchUp(_rendererId, pos.x, pos.y, id);
                    }
                }
            }
        }
예제 #3
0
    private void UpdateTouch()
    {
        for (int i = 0; i < UnityEngine.Input.touchCount; i++)
        {
            UnityEngine.Touch touch = UnityEngine.Input.GetTouch(i);
            uint id = (uint)touch.fingerId;
            UnityEngine.Vector2    pos   = ProjectPointer(touch.position.x, touch.position.y);
            UnityEngine.TouchPhase phase = touch.phase;

            if (phase == UnityEngine.TouchPhase.Began)
            {
                _uiView.TouchDown((int)pos.x, (int)pos.y, id);
            }
            else if (phase == UnityEngine.TouchPhase.Moved || phase == UnityEngine.TouchPhase.Stationary)
            {
                _uiView.TouchMove((int)pos.x, (int)pos.y, id);
            }
            else
            {
                _uiView.TouchUp((int)pos.x, (int)pos.y, id);
            }
        }
    }
예제 #4
0
        /// <summary>
        /// Create a gesture touch object from a virtual touch object and updates the previous position internally
        /// </summary>
        /// <param name="touchId">Virtual touch/finger id</param>
        /// <param name="touchPosition">Virtual touch position</param>
        /// <param name="touchPrevPosition">Virtual touch position</param>
        /// <param name="touchPhase">Virtual touch phase</param>
        /// <param name="touchPressure">Virtual touch pressure</param>
        /// <returns>GestureTouch</returns>
        public GestureTouch GestureTouchFromVirtualTouch(int touchId, Vector2 touchPosition, UnityEngine.TouchPhase touchPhase, float touchPressure = 0.0f)
        {
            // convert Unity touch to Gesture touch
            Vector2 prev;

            if (!previousTouchPositions.TryGetValue(touchId, out prev))
            {
                prev.x = touchPosition.x;
                prev.y = touchPosition.y;
            }
            DigitalRubyShared.TouchPhase mappedTouchPhase;
            switch (touchPhase)
            {
            case UnityEngine.TouchPhase.Began:
                mappedTouchPhase = TouchPhase.Began;
                break;

            case UnityEngine.TouchPhase.Canceled:
                mappedTouchPhase = TouchPhase.Cancelled;
                break;

            case UnityEngine.TouchPhase.Ended:
                mappedTouchPhase = TouchPhase.Ended;
                break;

            case UnityEngine.TouchPhase.Moved:
                mappedTouchPhase = TouchPhase.Moved;
                break;

            case UnityEngine.TouchPhase.Stationary:
                mappedTouchPhase = TouchPhase.Stationary;
                break;

            default:
                mappedTouchPhase = TouchPhase.Unknown;
                break;
            }
            GestureTouch touch = new GestureTouch(touchId, touchPosition.x, touchPosition.y, prev.x, prev.y, touchPressure, null, mappedTouchPhase);

            prev.x = touchPosition.x;
            prev.y = touchPosition.y;
            previousTouchPositions[touchId] = prev;
            return(touch);
        }
예제 #5
0
        private void AddTouch(int id, Vector2 position, UnityEngine.TouchPhase phase, float pressure = 1.0f)
        {
            GestureTouch touch = FingersScript.Instance.GestureTouchFromVirtualTouch(id, position, phase, pressure);

            virtualTouches[id] = touch;
        }