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();
}