// Polls the mouse pointing device
protected void PollMouse(ref POINTER_INFO curPtr)
{
down = Input.GetMouseButton(0);
// If the device is pressed and it
// was already pressed, it's a drag
// or a repeat, depending on if there
// was movement:
if (down && curPtr.active)
{
// Drag:
if (Input.mousePosition != curPtr.devicePos)
{
curPtr.evt = POINTER_INFO.INPUT_EVENT.DRAG;
curPtr.inputDelta = Input.mousePosition - curPtr.devicePos;
curPtr.devicePos = Input.mousePosition;
// See if we have exceeded the drag threshold:
if (curPtr.isTap)
{
tempVec = curPtr.origPos - curPtr.devicePos;
if (Mathf.Abs(tempVec.x) > dragThreshold || Mathf.Abs(tempVec.y) > dragThreshold)
curPtr.isTap = false;
}
}
else
{
// Nothing to see here:
curPtr.evt = POINTER_INFO.INPUT_EVENT.NO_CHANGE;
curPtr.inputDelta = Vector3.zero;
}
}
else if (down && !curPtr.active) // Else if it's a new press, it's a press
{
curPtr.Reset(curActionID++);
curPtr.evt = POINTER_INFO.INPUT_EVENT.PRESS;
curPtr.active = true;
curPtr.inputDelta = Input.mousePosition - curPtr.devicePos;
curPtr.origPos = Input.mousePosition;
curPtr.isTap = true; // True for now, until it moves too much
}
else if (!down && curPtr.active) // A release
{
curPtr.inputDelta = Input.mousePosition - curPtr.devicePos;
curPtr.devicePos = Input.mousePosition;
// See if we have exceeded the drag threshold:
if (curPtr.isTap)
{
tempVec = curPtr.origPos - curPtr.devicePos;
if (Mathf.Abs(tempVec.x) > dragThreshold || Mathf.Abs(tempVec.y) > dragThreshold)
curPtr.isTap = false;
}
if (curPtr.isTap)
curPtr.evt = POINTER_INFO.INPUT_EVENT.TAP;
else
curPtr.evt = POINTER_INFO.INPUT_EVENT.RELEASE;
curPtr.active = false;
}
else if (!down && Input.mousePosition != curPtr.devicePos) // Mouse was moved
{
curPtr.evt = POINTER_INFO.INPUT_EVENT.MOVE;
curPtr.inputDelta = Input.mousePosition - curPtr.devicePos;
curPtr.devicePos = Input.mousePosition;
}
else
{
curPtr.evt = POINTER_INFO.INPUT_EVENT.NO_CHANGE;
curPtr.inputDelta = Vector3.zero;
}
curPtr.devicePos = Input.mousePosition;
curPtr.prevRay = curPtr.ray;
curPtr.ray = uiCameras[0].camera.ScreenPointToRay(curPtr.devicePos);
}