Skip to main content
Up and Coming
June 5, 2013

Game view set size & position

I have the Game view in a floating window on my 2nd monitor and i'm constantly had to adjust it for when running on the Rift when testing my game. So I made an editor script that sets the window size and its position. The default values work for my monitor setup but you will probably need to tweak them for your setup.

I'm no programmer, so this could do bad things but it works for me!

got most of the code from:
http://answers.unity3d.com/questions/179775/game-window-size-from-editor-window-in-editor-mode.html


using UnityEngine;
using UnityEditor;

public class SetGameSizeWindow: EditorWindow {

private Vector2 _size = new Vector2(1920, 800);
private Vector2 _pos = new Vector2(7, 200);


[MenuItem ("Window/Set Game Size...")]
static void Init () {
SetGameSizeWindow window = (SetGameSizeWindow)(EditorWindow.GetWindow(typeof(SetGameSizeWindow)));
} // Init()

public static EditorWindow GetMainGameView() {
System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
System.Reflection.MethodInfo GetMainGameView = T.GetMethod("GetMainGameView",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
System.Object Res = GetMainGameView.Invoke(null,null);
return (EditorWindow)Res;
} // GetMainGameView()

void OnGUI () {
_size.x = EditorGUILayout.IntField("size X", (int)_size.x);
_size.y = EditorGUILayout.IntField("size Y", (int)_size.y);
_pos.x = EditorGUILayout.IntField("position X", (int)_pos.x);
_pos.y = EditorGUILayout.IntField("position Y", (int)_pos.y);



if (GUILayout.Button("Set")) {
EditorWindow gameView = GetMainGameView();
Rect pos = gameView.position;
Rect xypos = GetMainGameView().position;
xypos.x = _pos.x;
xypos.y = _pos.y;
pos.width = _size.x;
pos.height = _size.y;
gameView.position = pos;
GetMainGameView().position = xypos;

}
} // OnGUI()

}
    This topic has been closed for replies.

    2 replies

    Inspiring
    June 11, 2013
    Hey, this is a great script, thank you! I didn't realize it was possible to have that much control over the editor, let alone just taking the game window out onto its own screen. I'm going to have to rethink my monitor setup! All this time, I've just been building a new executable every time I want to test with the Rift. :oops:
    Titans of Space PLUS for Quest is now available on DrashVR.com
    zwickarrAuthor
    Up and Coming
    June 12, 2013
    yeah being able to test your game while in the editor is one advantage over UDK, where you do have to build. Im often changing the camera settings while in the rift. I look down through those lil vent holes :D