Created
November 3, 2014 21:09
-
-
Save MattRix/9205bc62d558fef98045 to your computer and use it in GitHub Desktop.
Revisions
-
MattRix created this gist
Nov 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ using UnityEngine; using UnityEditor; using System.Collections; using System; using System.Linq; using System.Reflection; [InitializeOnLoad] public class RXLookingGlass { public static Type type_HandleUtility; protected static MethodInfo meth_IntersectRayMesh; static RXLookingGlass() { var editorTypes = typeof(Editor).Assembly.GetTypes(); type_HandleUtility = editorTypes.FirstOrDefault(t => t.Name == "HandleUtility"); meth_IntersectRayMesh = type_HandleUtility.GetMethod("IntersectRayMesh",(BindingFlags.Static | BindingFlags.NonPublic)); } public static bool IntersectRayMesh(Ray ray, MeshFilter meshFilter, out RaycastHit hit) { return IntersectRayMesh(ray,meshFilter.mesh,meshFilter.transform.localToWorldMatrix,out hit); } public static bool IntersectRayMesh(Ray ray, Mesh mesh, Matrix4x4 matrix, out RaycastHit hit) { var parameters = new object[]{ray,mesh,matrix,null}; bool result = (bool)meth_IntersectRayMesh.Invoke(null,parameters); hit = (RaycastHit)parameters[3]; return result; } }