码迷,mamicode.com
首页 > 编程语言 > 详细

[Unity3D]通过反射方式获取Game View当前选择的分辨率

时间:2016-07-05 18:49:46      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!