I’m encountering a problem writing Editor scripts in that I need access to the “Game” window and its Screen dimensions, but I don’t seem to be able to access them. This is particularly problematic because Camera.ScreenToWorldPoint is completely hosed from inside the editor scripts. Here’s an example of what’s wrong:
///////////////////////////////////////
// Inside MyGameObject.cs//////////////
///////////////////////////////////////
public void DoSomething(){
// When previewing the game using the "Play" button, this works as expected.
Debug.Log(Screen.width + " " + Screen.height);
Vector3 adjustedPoint = renderCamera.ScreenToWorldPoint( vecScreenPoint );
}
///////////////////////////////////////
// Inside MyEditor.cs...
///////////////////////////////////////
override public void OnInspectorGUI(){
MyGameObject g = target as MyGameObject;
// But when I call from here, the Screen dimensions (both Screen and
// camera.ScreenToWorldPoint) report the dimensions of the inspector,
// not the dimensions of the Game window
g.DoSomething();
}
void OnSceneGUI(){
MyGameObject g = target as MyGameObject;
// And called from here, the dimensions match the active Scene window
// but still, never the "Game" window!
g.DoSomething();
}
So, is there some way to access the Game window? There doesn’t appear to be an OnGameGUI callback, unfortunately. If not, can you at least convince the camera to believe its screen dimensions match the Game window somehow? Is there some other utility that can offer this data? Can I manually translate screen to world without going through a camera?