Created
August 8, 2013 08:56
-
-
Save sfszh/6182925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
/* | |
* orignially posted | |
http://answers.unity3d.com/questions/179775/game-window-size-from-editor-window-in-editor-mode.html | |
*/ | |
public class SetGameViewSize : EditorWindow { | |
private Vector2 _size = new Vector2(800, 600); | |
[MenuItem("Window/Set Window Size")] | |
static void Init() { | |
SetGameViewSize window = (SetGameViewSize)(EditorWindow.GetWindow(typeof(SetGameViewSize))); | |
} // 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("X", (int)_size.x); | |
_size.y = EditorGUILayout.IntField("Y", (int)_size.y); | |
if (GUILayout.Button("Set")) { | |
Set(); | |
} | |
if (GUILayout.Button("2048*1536")) { | |
_size.Set(2048, 1536); | |
Set(); | |
} | |
if (GUILayout.Button("1024*768")) { | |
_size.Set(1024, 768); | |
Set(); | |
} | |
if (GUILayout.Button("960*640")) { | |
_size.Set(960, 640); | |
Set(); | |
} | |
if (GUILayout.Button("800*480")) { | |
_size.Set(800, 480); | |
Set(); | |
} | |
} // OnGUI() | |
void Set() { | |
EditorWindow gameView = GetMainGameView(); | |
Rect pos = gameView.position; | |
pos.y = pos.y - 0; | |
pos.width = _size.x; | |
pos.height = _size.y + 17; | |
gameView.position = pos; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment