Beispiel #1
0
    private void updateTouches()
    {
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_WEBGL
        if (isGetMouse)
        {
            if (Input.GetMouseButtonUp(0) || Input.GetMouseButton(0))
            {
                //Debug.Log("执行动作");
                touches.Add(touchesCache[0].updateByMouse());
            }
        }
#endif

        if (Input.touchCount > 0)
        {
            int touchLength = Mathf.Min(Input.touchCount, maxTouches);
            for (var i = 0; i < touchLength; i++)
            {
                Touch touch = Input.touches[i];
                if (touch.fingerId < maxTouches)
                {
                    touchesCache[i].updateByTouch(touch);
                    touches.Add(touchesCache[i]);
                }
            }
        }

        // recognizers
        if (touches.Count > 0 && recognizers.Count > 0)
        {
            if (canRecognize && triggeRecognizer == null)
            {
                for (var i = 0; i < recognizers.Count; i++)
                {
                    if (recognizers[i].canTrigger(touches))
                    {
                        triggeRecognizer = recognizers[i];
                        canRecognize     = false;
                    }
                }
            }
            if (triggeRecognizer != null)
            {
                triggeRecognizer.recognizeTouches(touches);
            }
        }
        else
        {
            triggeRecognizer = null;
            canRecognize     = true;
        }

        // post
        if (touches.Count > 0)
        {
            touches.Clear();
        }
    }
Beispiel #2
0
    public static void addRecognizer(AbstractRecognizer recognizer)
    {
        instance.recognizers.Add(recognizer);

        if (recognizer.zIndex > 0)
        {
            _instance.recognizers.Sort();
            _instance.recognizers.Reverse();
        }
    }
Beispiel #3
0
    public static void removeRecognizer(AbstractRecognizer recognizer)
    {
        if (_instance == null)
        {
            return;
        }

        if (!_instance.recognizers.Contains(recognizer))
        {
            Debug.LogError("Trying to remove recognizer that has not been added: " + recognizer);
            return;
        }

        recognizer.reset();
        instance.recognizers.Remove(recognizer);
    }