How can I change the
GameWindow
aspect ratio using C# within theUnity editor
Like this:
Thanks
CodePudding user response:
You can do this using reflection:
public static void ChangeResolution(int sizeIndex)
{
var assembly = typeof(Editor).Assembly;
var gameView = assembly.GetType("UnityEditor.GameView");
var instance = EditorWindow.GetWindow(gameView);
gameView.GetMethod("SizeSelectionCallback")!.Invoke(instance, new object[] { sizeIndex, null });
}
sizeIndex
is the index of the resolution in dropdown (0 - free aspect; 1 - 800x480)