Created
April 23, 2018 05:04
-
-
Save jackycute/73fe06d74827e762af913a89346b578e 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 UnityEditor; | |
using UnityEngine; | |
using System.Collections; | |
[InitializeOnLoad] | |
public class FullscreenPlayMode : MonoBehaviour { | |
//The size of the toolbar above the game view, excluding the OS border. | |
private static int tabHeight = 22; | |
static FullscreenPlayMode() | |
{ | |
EditorApplication.playmodeStateChanged -= CheckPlayModeState; | |
EditorApplication.playmodeStateChanged += CheckPlayModeState; | |
} | |
static void CheckPlayModeState() | |
{ | |
if (EditorApplication.isPlaying) | |
{ | |
FullScreenGameWindow(); | |
} | |
else | |
{ | |
CloseGameWindow(); | |
} | |
} | |
static EditorWindow GetMainGameView(){ | |
EditorApplication.ExecuteMenuItem("Window/Game"); | |
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; | |
} | |
static void FullScreenGameWindow(){ | |
EditorWindow gameView = GetMainGameView(); | |
float width = Screen.currentResolution.width / 2; | |
float height = Screen.currentResolution.height / 2; | |
gameView.title = "Game (Stereo)"; | |
Rect newPos = new Rect(0, 0 - tabHeight, width, height + tabHeight); | |
gameView.position = newPos; | |
gameView.minSize = new Vector2(width, height + tabHeight); | |
gameView.maxSize = gameView.minSize; | |
gameView.position = newPos; | |
} | |
static void CloseGameWindow(){ | |
EditorWindow gameView = GetMainGameView(); | |
gameView.Close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment