pixelWidth pixelHeight behaviour

I’m doing an editor script and when I access pixelWidth and pixelHeight properties of a given Camera (i.e. Camera.mainCamera) I get the values for the editor window instead of the game view

I would like to get 1024x768 as my game view but instead I get 254x289 as the editor window, if I resize the editor window for that specific script the values change, I don’t know how to correct this or if this is the intended behavior.

Thanks in advance!

Hi, I think this is what you need:

    public static Vector2 GetScreenSize() {
        Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
        MethodInfo GetSizeOfMainGameView = T.GetMethod("GetSizeOfMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
        object Res = GetSizeOfMainGameView.Invoke(null, null);
        return (Vector2)Res;
    }

in order to get the GameView size inside of an editor script, and you can use it to get pixelWidth or pixelHeight of a specific camera

int pixelWidth = GetScreenSize().x * camera.rect.width