我正在尝试让我的游戏全屏显示,并且我在网上找到了一些脚本来实现这一点。不幸的是,我无法在 2020 版本(或 2018+)中执行它们。有没有办法在编辑器模式下启用全屏游戏窗口?
从下面的脚本中,我在 System.Object Res = GetMainGameView.Invoke (null, null);
处收到异常错误 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;
}
}
}
最佳答案
我知道这是一年前被问到的,但也许这对某人有用。
如果您负担得起,我推荐这个名为全屏编辑器的 Assets 。 https://assetstore.unity.com/packages/tools/utilities/fullscreen-editor-69534
或者,unity 在包管理器中有一个内置的包,带有编辑记录器。这将自动记录您的游戏过程,而不会妨碍编辑器 UI 或您的应用栏。
或者如其他人所述,进行测试构建或使用编辑器面板中的“播放时最大化按钮”。
关于c# - 编辑器中的全屏模式游戏 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66385610/