unity 编辑器模式下修改屏幕分辨率

前一段项目中有个需求要求点击按钮后横屏切换为竖屏,在移动设备上设置Screen.orientation = ScreenOrientation.PortraitUpsideDown;就转过来了。但是在编辑器下转不过来。下面通过反射的方法改变编辑器窗口分辨率。

 

 

  1 #if UNITY_EDITOR
  2 using System;
  3 using System.Reflection;
  4 using UnityEditor;
  5 using UnityEngine;
  6 
  7 public static class GameViewUtils
  8 {
  9     static object gameViewSizesInstance;
 10     static MethodInfo getGroup;
 11 
 12     static GameViewUtils()
 13     {
 14         // gameViewSizesInstance  = ScriptableSingleton<GameViewSizes>.instance;
 15         var sizesType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes");
 16         var singleType = typeof(ScriptableSingleton<>).MakeGenericType(sizesType);
 17         var instanceProp = singleType.GetProperty("instance");
 18         getGroup = sizesType.GetMethod("GetGroup");
 19         gameViewSizesInstance = instanceProp.GetValue(null, null);
 20     }
 21 
 22     public enum GameViewSizeType
 23     {
 24         AspectRatio, FixedResolution
 25     }
 26 
 27     //[MenuItem("Test/AddSize")]
 28     //public static void AddTestSize()
 29     //{
 30     //    AddCustomSize(GameViewSizeType.AspectRatio, GameViewSizeGroupType.Standalone, 123, 456, "Test size");
 31     //}
 32 
 33     //[MenuItem("Test/SizeTextQuery")]
 34     //public static void SizeTextQueryTest()
 35     //{
 36     //    Debug.Log(SizeExists(GameViewSizeGroupType.Standalone, "Test size"));
 37     //}
 38 
 39     //[MenuItem("Test/Query16:9Test")]
 40     //public static void WidescreenQueryTest()
 41     //{
 4
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值