Unity Runtime控制编辑器的一些操作

运行时修改Game窗口尺寸

cs 复制代码
//设置竖屏
public void ChangePortrait()
{
    Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
    Type type = assembly.GetType("UnityEditor.GameView");
    var gameView= UnityEditor.EditorWindow.GetWindow(type);
    //可以反射出其他字段和方法,看看是否有可以修改Game视图字段或者方法   
    PropertyInfo targetProperty = type.GetProperty("selectedSizeIndex");
    targetProperty.SetValue(gameView,18);
    UIModule.Instance.UIRoot.GetComponent<CanvasScaler>().referenceResolution = new Vector2(768, 1720);
}

//设置横屏
public void ChangeLandscape()
{
    Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
    Type type = assembly.GetType("UnityEditor.GameView");
    var gameView= UnityEditor.EditorWindow.GetWindow(type);
    //可以反射出其他字段和方法,看看是否有可以修改Game视图字段或者方法   
    PropertyInfo targetProperty = type.GetProperty("selectedSizeIndex");
    targetProperty.SetValue(gameView, 19);
    UIModule.Instance.UIRoot.GetComponent<CanvasScaler>().referenceResolution = new Vector2(1920, 1080);
}

请注意selectedSizeIndex属性修改的是下图的尺寸编号

相关推荐
HoneyMoose3 小时前
Jenkins Cloudflare 部署提示错误
java·servlet·jenkins
阿丰资源3 小时前
基于SpringBoot的物流信息管理系统设计与实现(附资料)
java·spring boot·后端
Predestination王瀞潞3 小时前
Java EE3-我独自整合(第四章:Spring bean标签的常见配置)
java·spring·java-ee
overmind3 小时前
oeasy Python 121[专业选修]列表_多维列表运算_列表相加_列表相乘
java·windows·python
资深数据库专家3 小时前
总账EBS 应用服务器1 的监控分析
java·网络·数据库
房开民3 小时前
可变参数模板
java·开发语言·算法
一只蝉nahc3 小时前
vue使用iframe内嵌unity模型,并且向模型传递信息,接受信息
前端·vue.js·unity
t***5443 小时前
如何在现代C++中更有效地应用这些模式
java·开发语言·c++
_深海凉_3 小时前
LeetCode热题100-最小栈
java·数据结构·leetcode
不知名的忻3 小时前
Morris遍历(力扣第99题)
java·算法·leetcode·morris遍历