如何解决编辑器中的全屏模式游戏视图
我正在尝试让我的游戏全屏查看,但我在网上找到了几个脚本来实现这一点。不幸的是,我无法在 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",0)]
public static void PlayModeWindow () {
PlayerPrefs.SetInt ("PlayMode_FullScreen",0);
}
[MenuItem ("Tools/Editor/Play Mode/Window",0)]
public static bool PlayModeWindowValidate () {
return PlayerPrefs.GetInt ("PlayMode_FullScreen",0) == 1;
}
}
}
解决方法
大多数人会建议使用“最大化播放按钮”,这不是您想要的。
我建议如果您想在全屏模式下测试游戏的外观,只需在编辑构建设置/播放器设置并让游戏全屏显示后构建并运行,甚至可以使用 alt+enter 来完整显示筛选并测试您的外观。
这比在游戏脚本中使用简单得多,只是为了在编辑器中测试全屏,除非您想在全屏时查看控制台输出。商店中还有一个免费资产,请参阅构建中的控制台。
https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。