static public bool Raycast (Vector3 inPos, ref RaycastHit hit)
{
for (int i = 0; i < mList.Count; ++i)
{
UICamera cam = mList[i];
// Skip inactive scripts
if (!cam.enabled || !NGUITools.GetActive(cam.gameObject)) continue;
// Convert to view space
currentCamera = cam.cachedCamera;
Vector3 pos = currentCamera.ScreenToViewportPoint(inPos);
// If it's outside the camera's viewport, do nothing
if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f) continue;
// Cast a ray into the screen
Ray ray = currentCamera.ScreenPointToRay(inPos);
// Raycast into the screen
int mask = currentCamera.cullingMask & (int)cam.eventReceiverMask;
float dist = (cam.rangeDistance > 0f) ? cam.rangeDistance : currentCamera.farClipPlane - currentCamera.nearClipPlane;
// If raycasts should be clipped by panels, we need to find a panel for each hit
if (cam.clipRaycasts)
{
RaycastHit[] hits = Physics.RaycastAll(ray, dist, mask);
if (hits.Length > 1)
{
System.Array.Sort(hits, delegate(RaycastHit r1, RaycastHit r2) { return r1.distance.CompareTo(r2.distance); });
for (int b = 0, bmax = hits.Length; b < bmax; ++b)
{
if (IsVisible(ref hits[b]))
{
hit = hits[b];
return true;
}
}
}
else if (hits.Length == 1 && IsVisible(ref hits[0]))
{
hit = hits[0];
return true;
}
continue;
}
if (Physics.Raycast(ray, out hit, dist, mask)) return true;
}
return false;
}