Home > database >  How to change aspect ratio of Game View using c# script
How to change aspect ratio of Game View using c# script

Time:09-30

How can I change the GameWindow aspect ratio using C# within the Unity editor

Like this:

Example

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)

  • Related