标签:
System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor"); System.Reflection.MethodInfo GetMainGameView = T.GetMethod("GetMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); System.Object Res = GetMainGameView.Invoke(null, null); var gameView = (UnityEditor.EditorWindow)Res; var prop = gameView.GetType().GetProperty("currentGameViewSize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var gvsize = prop.GetValue(gameView, new object[0] { }); var gvSizeType = gvsize.GetType(); var debug_h = (int)gvSizeType.GetProperty("height", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0] { }); var debug_w = (int)gvSizeType.GetProperty("width", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0] { });
以上代码可获取Game View中当前选择的分辨率,而非Using resolution。取到的值可用于动态设置NGUI组件(如UIScrollView)的参数等。
[Unity3D]通过反射方式获取Game View当前选择的分辨率
标签:
原文地址:http://www.cnblogs.com/angel271/p/5644554.html