Skip to content

Instantly share code, notes, and snippets.

@fnuecke
Created March 27, 2020 16:23
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@Tymski
Copy link

Tymski commented Mar 16, 2021

Before using this

  • Make sure to set the game window to the same aspect ratio as your screen or this will break your rendering
    image
  • And also open the window after entering play mode or this will break your window layout.

@PowZone
Copy link

PowZone commented Apr 6, 2021

Works perfectly, thanks!

@StevenLightning
Copy link

Thanks so much for this! However, closing the window doesn't usually work this way for me, so I found it useful to also add another MenuItem shortcut that changes the layout back to normal. Something like this:

[MenuItem("Window/LayoutShortcuts/Default %q", false, 2)]
static void DefaultLayout()
{
    EditorApplication.ExecuteMenuItem("Window/Layouts/Default");
}

(Based on https://answers.unity.com/questions/23668/editor-layout-hotkeys.html)

@Chillu1
Copy link

Chillu1 commented Jun 14, 2021

Thanks a lot, this was the only solution that worked for me on my Linux. Improved it a bit to fit for my purposes:
https://gist.github.com/Chillu1/4c209308dc81104776718b1735c639f7

@donsledzion
Copy link

Awesome dude! Works perfectly. I've needed it to record my VR application gameplay (before building it) with the highest resollution possible. Thank You!

@IAMAdamN
Copy link

for other users

using ctrl+shift+alt+F as shortcutkey

watch this youtube video for more info: https://youtu.be/ebRRYUawPZk

#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) %#&f", 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

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