简体   繁体   English

编辑器中的全屏模式游戏视图

[英]Full screen mode game view in editor

I am trying to make my game view full screen and I have found few scripts online in order to achieve this.我正在尝试让我的游戏视图全屏显示,我在网上找到了一些脚本来实现这一点。 Unfortunately I am not able to execute them in 2020 version (or 2018+).不幸的是,我无法在 2020 版本(或 2018+)中执行它们。 Is there a method to enable full screen game window during editor mode?有没有办法在编辑器模式下启用全屏游戏 window? From the below script, I get exception error at System.Object Res = GetMainGameView.Invoke (null, null);从下面的脚本中,我在System.Object Res = GetMainGameView.Invoke (null, null);处收到异常错误。 Is the current Unity version not accessible for the GetMainGameView? GetMainGameView 是否无法访问当前的 Unity 版本?

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/General/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;
        }
    }
}

Most people would suggest use "maximize on play button" which is not you want.大多数人会建议使用您不想要的“最大化播放按钮”。

I would suggest if you want to test the look of your game in full screen just build and run after you edit Build settings/Player settings and make the game there full screen or even let use to use alt+enter to go full screen and test your look.我建议如果您想全屏测试游戏的外观,只需在编辑构建设置/播放器设置并使游戏全屏后构建并运行,甚至让使用 alt+enter 进入 go 全屏并测试你的样子。

This will be much easier than using in game scripts just to test full screen in editor UNLESS you want to see console output while in full screen.这将比在游戏脚本中使用仅在编辑器中测试全屏要容易得多,除非您想在全屏时查看控制台 output。 There is also a free asset in store see the console in build.商店中还有一个免费资产,请参阅构建中的控制台。

https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068 https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068

I know this was asked a year ago but maybe this will be useful to someone.我知道这是在一年前提出的,但也许这对某人有用。

If you can afford it, I recommend this asset called Fullscreen Editor.如果你能负担得起,我推荐这个名为 Fullscreen Editor 的资产。 https://assetstore.unity.com/packages/tools/utilities/fullscreen-editor-69534 https://assetstore.unity.com/packages/tools/utilities/fullscreen-editor-69534

Alternatively, unity has a built-in package in the package manager with an editor recorder.或者,Unity 在 package 管理器中具有内置的 package 和编辑器记录器。 This will automatically record your gameplay with none of the editor UI or your app bar in the way.这将自动记录您的游戏玩法,而不会妨碍您的编辑器 UI 或应用栏。

Or as someone else stated, make a test build or use the "maximize on play button" in the editor panel.或者正如其他人所说,进行测试构建或使用编辑器面板中的“最大化播放按钮”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM