public static bool RaycastMesh(this GameObject gameObject, Ray ray, out GameObjectRayHit objectRayHit)
        {
            objectRayHit = null;
            Mesh objectMesh = gameObject.GetMeshFromFilterOrSkinnedMeshRenderer();

            if (objectMesh == null)
            {
                return(false);
            }

            EditorMesh editorMesh = EditorMeshDatabase.Instance.GetEditorMesh(objectMesh);

            if (editorMesh != null)
            {
                MeshRayHit meshRayHit = editorMesh.Raycast(ray, gameObject.transform.GetWorldMatrix());
                if (meshRayHit == null)
                {
                    return(false);
                }

                objectRayHit = new GameObjectRayHit(ray, gameObject, null, meshRayHit, null, null);
                return(true);
            }
            else
            {
                MeshCollider meshCollider = gameObject.GetComponent <MeshCollider>();
                if (meshCollider != null)
                {
                    RaycastHit rayHit;
                    if (meshCollider.Raycast(ray, out rayHit, float.MaxValue))
                    {
                        MeshRayHit meshRayHit = new MeshRayHit(ray, rayHit.distance, rayHit.triangleIndex, rayHit.point, rayHit.normal);
                        objectRayHit = new GameObjectRayHit(ray, gameObject, null, meshRayHit, null, null);
                        return(true);
                    }
                }
                else
                {
                    return(gameObject.RaycastBox(ray, out objectRayHit));
                }
            }

            return(false);
        }
        public GameObjectRayHit(Ray ray, GameObject hitObject, OrientedBoxRayHit objectBoxHit, MeshRayHit objectMeshHit, TerrainRayHit objectTerrainHit, SpriteRayHit objectSpriteHit)
        {
            _ray       = ray;
            _hitObject = hitObject;

            // Only one kind of entity can be registered as a hit, so we will take the first
            // non-null hit instance using the following priority: terrain, mesh, sprite, box.
            if (objectTerrainHit != null)
            {
                _objectTerrainHit = objectTerrainHit;
                _objectBoxHit     = null;
                _objectMeshHit    = null;
                _objectSpriteHit  = null;
            }
            else
            if (objectMeshHit != null)
            {
                _objectTerrainHit = null;
                _objectBoxHit     = null;
                _objectMeshHit    = objectMeshHit;
                _objectSpriteHit  = null;
            }
            else
            if (objectSpriteHit != null)
            {
                _objectTerrainHit = null;
                _objectBoxHit     = null;
                _objectMeshHit    = null;
                _objectSpriteHit  = objectSpriteHit;
            }
            if (objectBoxHit != null)
            {
                _objectTerrainHit = null;
                _objectBoxHit     = objectBoxHit;
                _objectMeshHit    = null;
                _objectSpriteHit  = null;
            }
        }