Last active
February 27, 2024 03:15
-
-
Save nicoplv/e6253677d5bb2841b0451d308923c232 to your computer and use it in GitHub Desktop.
Full screen game view on Unity editor (works only with 2017.2 or +)
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; | |
namespace FullScreenPlayModes | |
{ | |
[InitializeOnLoad] | |
public class FullScreenPlayMode : Editor | |
{ | |
//The size of the toolbar above the game view, excluding the OS border. | |
private static int toolbarHeight = 22; | |
static FullScreenPlayMode() | |
{ | |
EditorApplication.playModeStateChanged -= PlayModeStateChanged; | |
EditorApplication.playModeStateChanged += PlayModeStateChanged; | |
} | |
static void PlayModeStateChanged(PlayModeStateChange _playModeStateChange) | |
{ | |
if (PlayerPrefs.GetInt("PlayMode_FullScreen", 0) == 1) | |
{ | |
// Get game editor window | |
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); | |
EditorWindow gameView = (EditorWindow)Res; | |
switch (_playModeStateChange) | |
{ | |
case PlayModeStateChange.EnteredPlayMode: | |
Rect newPos = new Rect(0, 0 - toolbarHeight, Screen.currentResolution.width, Screen.currentResolution.height + toolbarHeight); | |
gameView.position = newPos; | |
gameView.minSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height + toolbarHeight); | |
gameView.maxSize = gameView.minSize; | |
gameView.position = newPos; | |
break; | |
case PlayModeStateChange.EnteredEditMode: | |
gameView.Close(); | |
break; | |
} | |
} | |
} | |
[MenuItem("Tools/Editor/Play Mode/Full Screen", false, 0)] | |
public static void PlayModeFullScreen() | |
{ | |
PlayerPrefs.SetInt("PlayMode_FullScreen", 1); | |
} | |
[MenuItem("Tools/Editor/Play Mode/Full Screen", true, 0)] | |
public static bool PlayModeFullScreenValidate() | |
{ | |
return PlayerPrefs.GetInt("PlayMode_FullScreen", 0) == 0; | |
} | |
[MenuItem("Tools/Editor/Play Mode/Window", false, 0)] | |
public static void PlayModeWindow() | |
{ | |
PlayerPrefs.SetInt("PlayMode_FullScreen", 0); | |
} | |
[MenuItem("Tools/Editor/Play Mode/Window", true, 0)] | |
public static bool PlayModeWindowValidate() | |
{ | |
return PlayerPrefs.GetInt("PlayMode_FullScreen", 0) == 1; | |
} | |
} | |
} |
can you make it work for unity 2018?
Checked on 2020 - doesn't work at all.
Edit: For 2020 there is this https://gist.github.com/fnuecke/d4275087cc7969257eae0f939fac3d2f with some bugs but works
Checked on 2020 - doesn't work at all.
Edit: For 2020 there is this https://gist.github.com/fnuecke/d4275087cc7969257eae0f939fac3d2f with some bugs but works
I improved on that one with some automation QoL: https://gist.github.com/Chillu1/4c209308dc81104776718b1735c639f7
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update of https://gist.github.com/mandarinx/b9f2dbcba611aa926ca98020b4538371