I’m writing some scripts that run at edit-time as well as runtime, and I’ve discovered that when running the game, the camera correctly reports the width and height, in pixels, of the game view. But when the game is stopped, any camera you check will report the width and height of the scene view instead of the game view. This leads to very unexpected behavior.
Is there any way to get the size of the game view viewport when the game is not running?
That doesn’t seem intuitive to me since depending on whether the game is running or not, the same value (the viewport size) has an entirely different meaning. And the cameras do exist when the game is not running, or else the game view wouldn’t be able to give an accurate preview of what the game will look like when running.
It would seem to be a shame if there’s no way to get the size of the game view and only the scene view. Somewhere inside Unity something has to know the size of the game view for it to draw it.
The game view really has no size as it can be changed dynamically and without being initialized its just 0.
would you prefer you crash the dx context completely by trying to initialize 0 sized stuff?
The simple solution is to not make it run in edit mode if you only want the game window size.
For SM2, not running in edit mode is not an option. The developer needs a preview of what they’re working on. And for some features, the size of the area being rendered is needed.
There has to be a way, that information has to be there somewhere. If not as part of a camera component, then somewhere else.
Until you go into game mode its nowhere.
but that does not prevent you from detecting that you went into game mode and store the info.
then they will at least be valid until the user changes the size.
the info thats there is not available to you as you have no access to any layout related stuff as far as I’m aware.
on the iphone it would be simple. detect the orientation setting → ding
but as you see at latest by ipad your code will have to work differently as it has to handle the size at runtime not editor time
If you ask me you don’t need the screen size at all, as the orthographic cam size kind of defines the whole field, independent on if the screen is 10 pixel or 10 million pixel in size