Ejemplo n.º 1
0
        void GetHitTarget()
        {
            if (_frameGotHitTarget == Time.frameCount)
            {
                return;
            }

            _frameGotHitTarget = Time.frameCount;

            if (_customInput)
            {
                Vector2 pos = _customInputPos;
                pos.y = stageHeight - pos.y;

                TouchInfo touch = _touches[0];
                _touchTarget = HitTest(pos, true);
                touch.target = _touchTarget;
            }
            else if (touchScreen)
            {
                _touchTarget = null;
                for (int i = 0; i < Input.touchCount; ++i)
                {
                    Touch uTouch = Input.GetTouch(i);

                    Vector2 pos = uTouch.position;
                    pos.y = stageHeight - pos.y;

                    TouchInfo touch = null;
                    TouchInfo free  = null;
                    for (int j = 0; j < 5; j++)
                    {
                        if (_touches[j].touchId == uTouch.fingerId)
                        {
                            touch = _touches[j];
                            break;
                        }

                        if (_touches[j].touchId == -1)
                        {
                            free = _touches[j];
                        }
                    }
                    if (touch == null)
                    {
                        touch = free;
                        if (touch == null || uTouch.phase != TouchPhase.Began)
                        {
                            continue;
                        }

                        touch.touchId = uTouch.fingerId;
                    }

                    if (uTouch.phase == TouchPhase.Stationary)
                    {
                        _touchTarget = touch.target;
                    }
                    else
                    {
                        _touchTarget = HitTest(pos, true);
                        touch.target = _touchTarget;
                    }
                }
            }
            else
            {
                Vector2 pos;
                int     displayIndex;
#if (UNITY_5 || UNITY_5_3_OR_NEWER)
                if (Display.displays.Length > 1)
                {
                    Vector3 p = Display.RelativeMouseAt(Input.mousePosition);
                    pos          = p;
                    displayIndex = (int)p.z;
                    pos.y        = Display.displays[displayIndex].renderingHeight - pos.y;
                }
                else
#endif
                {
                    pos          = Input.mousePosition;
                    pos.y        = stageHeight - pos.y;
                    displayIndex = -1;
                }

                TouchInfo touch = _touches[0];
                if (pos.x < 0 || pos.y < 0)                 //outside of the window
                {
                    _touchTarget = this;
                }
                else
                {
                    _touchTarget = HitTest(pos, true, displayIndex);
                }
                touch.target = _touchTarget;
            }

            HitTestContext.ClearRaycastHitCache();
        }
Ejemplo n.º 2
0
        void GetHitTarget()
        {
            if (_frameGotHitTarget == Time.frameCount)
            {
                return;
            }

            _frameGotHitTarget = Time.frameCount;

            if (_customInput)
            {
                Vector2 pos = _customInputPos;
                pos.y = stageHeight - pos.y;

                TouchInfo touch = _touches[0];
                _touchTarget = HitTest(pos, true);
                touch.target = _touchTarget;
            }
            else if (touchScreen)
            {
                for (int i = 0; i < Input.touchCount; ++i)
                {
                    Touch uTouch = Input.GetTouch(i);
                    if (uTouch.phase == TouchPhase.Stationary)
                    {
                        continue;
                    }

                    Vector2 pos = uTouch.position;
                    pos.y = stageHeight - pos.y;

                    _touchTarget = null;
                    TouchInfo touch = null;
                    for (int j = 0; j < 5; j++)
                    {
                        if (_touches[j].touchId == uTouch.fingerId)
                        {
                            touch = _touches[j];
                            break;
                        }

                        if (_touches[j].touchId == -1)
                        {
                            touch = _touches[j];
                            //下面的赋值避免了touchMove在touchDown前触发
                            touch.x = uTouch.position.x;
                            touch.y = stageHeight - uTouch.position.y;
                        }
                    }
                    if (touch == null)
                    {
                        return;
                    }

                    touch.touchId = uTouch.fingerId;
                    DisplayObject ht = HitTest(pos, true);
                    touch.target = ht;
                    if (ht != null)
                    {
                        _touchTarget = ht;
                    }
                }
            }
            else
            {
                Vector2 pos = Input.mousePosition;
                pos.y = stageHeight - pos.y;

                TouchInfo touch = _touches[0];
                if (pos.x < 0 || pos.y < 0)
                {
                    pos.x = touch.x;
                    pos.y = touch.y;
                }

                _touchTarget = HitTest(pos, true);
                touch.target = _touchTarget;
            }

            HitTestContext.ClearRaycastHitCache();
        }
Ejemplo n.º 3
0
        void GetHitTarget()
        {
            //Debug.Log("GetHitTarget  :"+ _frameGotHitTarget +"   :"+ Time.frameCount);
            if (_frameGotHitTarget == Time.frameCount)
            {
                return;
            }

            _frameGotHitTarget = Time.frameCount;

            if (_customInput)
            {
                Vector2 pos = _customInputPos;
                pos.y = stageHeight - pos.y;

                TouchInfo touch = _touches[0];
                _touchTarget = HitTest(pos, true);
                touch.target = _touchTarget;
                //Debug.Log("_customInput  :" + _customInput);
            }
            else if (touchScreen)
            {
                _touchTarget = null;

                for (int i = 0; i < Input.touchCount; ++i)
                {
                    Touch uTouch = Input.GetTouch(i);
                    //Debug.Log("Input.touchCount  :" + Input.touchCount);

                    Vector2 pos = uTouch.position;
                    pos.y = stageHeight - pos.y;

                    TouchInfo touch = null;
                    TouchInfo free  = null;
                    for (int j = 0; j < 5; j++)
                    {
                        if (_touches[j].touchId == uTouch.fingerId)
                        {
                            touch = _touches[j];
                            break;
                        }

                        if (_touches[j].touchId == -1)
                        {
                            free = _touches[j];
                        }
                    }
                    if (touch == null)
                    {
                        touch = free;
                        if (touch == null || uTouch.phase != TouchPhase.Began)
                        {
                            continue;
                        }

                        touch.touchId = uTouch.fingerId;
                    }

                    if (uTouch.phase == TouchPhase.Stationary)
                    {
                        _touchTarget = touch.target;
                    }
                    else
                    {
                        _touchTarget = HitTest(pos, true);
                        //Debug.Log("hittest:" + _touchTarget);
                        touch.target = _touchTarget;
                    }
                }
            }
            else
            {
                Vector2 pos = Input.mousePosition;
                pos.y = stageHeight - pos.y;

                TouchInfo touch = _touches[0];
                if (pos.x < 0 || pos.y < 0)                 //outside of the window
                {
                    _touchTarget = this;
                }
                else
                {
                    _touchTarget = HitTest(pos, true);
                }
                touch.target = _touchTarget;
            }

            HitTestContext.ClearRaycastHitCache();
        }