前一段项目中有个需求要求点击按钮后横屏切换为竖屏,在移动设备上设置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