private static bool RaycastWorld(Vector2 position, out RaycastHit hit)
{
hit = new RaycastHit();
GameObject obj2 = HandleUtility.PickGameObject(position, false);
if (obj2 == null)
{
return false;
}
Ray ray = HandleUtility.GUIPointToWorldRay(position);
MeshFilter[] componentsInChildren = obj2.GetComponentsInChildren<MeshFilter>();
float positiveInfinity = float.PositiveInfinity;
foreach (MeshFilter filter in componentsInChildren)
{
RaycastHit hit2;
Mesh sharedMesh = filter.sharedMesh;
if (((sharedMesh != null) && HandleUtility.IntersectRayMesh(ray, sharedMesh, filter.transform.localToWorldMatrix, out hit2)) && (hit2.distance < positiveInfinity))
{
hit = hit2;
positiveInfinity = hit.distance;
}
}
if (positiveInfinity == float.PositiveInfinity)
{
Collider[] colliderArray = obj2.GetComponentsInChildren<Collider>();
foreach (Collider collider in colliderArray)
{
RaycastHit hit3;
if (collider.Raycast(ray, out hit3, float.PositiveInfinity) && (hit3.distance < positiveInfinity))
{
hit = hit3;
positiveInfinity = hit.distance;
}
}
}
if (positiveInfinity == float.PositiveInfinity)
{
Vector3 introduced15 = Vector3.Project(obj2.transform.position - ray.origin, ray.direction);
hit.point = introduced15 + ray.origin;
}
return true;
}