1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| public enum GameViewSizeType { AspectRatio, FixedResolution } [MenuItem("Window/Add Resolution")] static void AddGameViewResolution() {
List<(GameViewSizeType type, int width, int heigth, string title)> listCustomResolution = new List<(GameViewSizeType, int, int, string)>(); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1024, 1280, "1024x1280 (5:4==1.25)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1280, 1024, "1280x1024")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 768, 1024, "768x1024 (4:3==1.333)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1024, 768, "1024x768")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1536, 2048, "1536x2048 (4:3=1.333)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 2048, 1536, "2048x1536")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1200, 2000, "1200x2000 (5:3=1.667)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 2000, 1200, "2000x1200")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1080, 2340, "1080x2340 (9.5:9=2.167)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 2340, 1080, "2340x1080")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1600, 2560, "1600x2560 (16:10==1.6)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 2560, 1600, "2560x1600")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1080, 1920, "1080x1920 (16:9==1.778)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1920, 1080, "1920x1080")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 2160, 4096, "2160x4096 (17:9==1.889)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 4096, 2160, "4096x2160")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1080, 2400, "1080x2400 (30:13.5=2.222)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 2400, 1080, "2400x1080")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 1176, 2400, "1176x2400 (20.5:9=2.278)")); listCustomResolution.Add((GameViewSizeType.FixedResolution, 2400, 1176, "2400x1176"));
var sizesType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes"); var singleType = typeof(ScriptableSingleton<>).MakeGenericType(sizesType); var instance = singleType.GetProperty("instance").GetValue(null, null); var group = instance.GetType().GetProperty("currentGroup", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).GetValue(instance); var addCustomSize = group.GetType().GetMethod("AddCustomSize");
Assembly assembly = Assembly.Load("UnityEditor.dll"); Type gameViewSize = assembly.GetType("UnityEditor.GameViewSize"); Type gameViewSizeType = assembly.GetType("UnityEditor.GameViewSizeType");
foreach (var item in listCustomResolution) { ConstructorInfo ctor = gameViewSize.GetConstructor(new Type[] { gameViewSizeType, typeof(int), typeof(int), typeof(string) }); var newSize = ctor.Invoke(new object[] { (int)item.type, item.width, item.heigth, item.title }); addCustomSize.Invoke(group, new object[] { newSize }); } var saveMethod = instance.GetType().GetMethod("SaveToHDD"); saveMethod.Invoke(instance, null); }
|