Skip to content

Instantly share code, notes, and snippets.

@fnuecke
Created March 27, 2020 16:23
Show Gist options
  • Save fnuecke/d4275087cc7969257eae0f939fac3d2f to your computer and use it in GitHub Desktop.
Save fnuecke/d4275087cc7969257eae0f939fac3d2f to your computer and use it in GitHub Desktop.
#if UNITY_EDITOR
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Little utility for opening a "Game" view in fullscreen. Will be opened on whatever Unity thinks is the "main"
/// monitor at the moment. The hotkey will toggle the window; however, if for some reason this breaks, fullscreen
/// windows can be closed via Alt+F4 as long as the editor is not in play mode.
/// </summary>
/// <remarks>
/// Confirmed to work in Unity 2019 and 2020. May work in earlier and later versions. No promises.
/// </remarks>
public static class FullscreenGameView
{
static readonly Type GameViewType = Type.GetType("UnityEditor.GameView,UnityEditor");
static readonly PropertyInfo ShowToolbarProperty = GameViewType.GetProperty("showToolbar", BindingFlags.Instance | BindingFlags.NonPublic);
static readonly object False = false; // Only box once. This is a matter of principle.
static EditorWindow instance;
[MenuItem("Window/General/Game (Fullscreen) %#&2", priority = 2)]
public static void Toggle()
{
if (GameViewType == null)
{
Debug.LogError("GameView type not found.");
return;
}
if (ShowToolbarProperty == null)
{
Debug.LogWarning("GameView.showToolbar property not found.");
}
if (instance != null)
{
instance.Close();
instance = null;
}
else
{
instance = (EditorWindow) ScriptableObject.CreateInstance(GameViewType);
ShowToolbarProperty?.SetValue(instance, False);
var desktopResolution = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
var fullscreenRect = new Rect(Vector2.zero, desktopResolution);
instance.ShowPopup();
instance.position = fullscreenRect;
instance.Focus();
}
}
}
#endif
@Roland09
Copy link

Roland09 commented Oct 11, 2024

I'm using 2 monitors and when I use this script it extends the fullscreen partially to the other monitor.

Any ideas?

@PalaNolho I had the same. Dividing the resolution by EditorGUIUtility.pixelsPerPoint worked for me.

@JorGra
Copy link

JorGra commented Dec 11, 2024

I extended the script to make it work in Unity 2022.3 and made it a package as I used Harmony to remove the toolbar.

You can find it here: https://github.com/JorGra/JG-UnityEditor-GameViewFullscreen

Don't forget to star the repo if you find it useful, also make sure to read the known issues section!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment