public void ProcessMouse ()
{
bool updateRaycast = (useMouse && Time.timeScale < 0.9f);
if (!updateRaycast)
{
for (int i = 0; i < 3; ++i)
{
if (Input.GetMouseButton(i) || Input.GetMouseButtonUp(i))
{
updateRaycast = true;
break;
}
}
}
// Update the position and delta
mMouse[0].pos = Input.mousePosition;
mMouse[0].delta = mMouse[0].pos - lastTouchPosition;
bool posChanged = (mMouse[0].pos != lastTouchPosition);
lastTouchPosition = mMouse[0].pos;
// Update the object under the mouse
if (updateRaycast)
{
hoveredObject = Raycast(Input.mousePosition, ref lastHit) ? lastHit.collider.gameObject : fallThrough;
if (hoveredObject == null) hoveredObject = genericEventHandler;
mMouse[0].current = hoveredObject;
}
// Propagate the updates to the other mouse buttons
for (int i = 1; i < 3; ++i)
{
mMouse[i].pos = mMouse[0].pos;
mMouse[i].delta = mMouse[0].delta;
mMouse[i].current = mMouse[0].current;
}
// Is any button currently pressed?
bool isPressed = false;
for (int i = 0; i < 3; ++i)
{
if (Input.GetMouseButton(i))
{
isPressed = true;
break;
}
}
if (isPressed)
{
// A button was pressed -- cancel the tooltip
mTooltipTime = 0f;
}
else if (useMouse && posChanged && (!stickyTooltip || mHover != mMouse[0].current))
{
if (mTooltipTime != 0f)
{
// Delay the tooltip
mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
}
else if (mTooltip != null)
{
// Hide the tooltip
ShowTooltip(false);
}
}
// The button was released over a different object -- remove the highlight from the previous
if (useMouse && !isPressed && mHover != null && mHover != mMouse[0].current)
{
if (mTooltip != null) ShowTooltip(false);
Highlight(mHover, false);
mHover = null;
}
// Process all 3 mouse buttons as individual touches
if (useMouse)
{
for (int i = 0; i < 3; ++i)
{
bool pressed = Input.GetMouseButtonDown(i);
bool unpressed = Input.GetMouseButtonUp(i);
currentTouch = mMouse[i];
currentTouchID = -1 - i;
// We don't want to update the last camera while there is a touch happening
if (pressed) currentTouch.pressedCam = currentCamera;
else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;
// Process the mouse events
ProcessTouch(pressed, unpressed);
}
currentTouch = null;
}
// If nothing is pressed and there is an object under the touch, highlight it
if (useMouse && !isPressed && mHover != mMouse[0].current)
{
mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
mHover = mMouse[0].current;
Highlight(mHover, true);
}
}