[英]check if winform is hidden behind a game running in exclusive full screen mode
[英]Full screen mode game view in editor
我正在嘗試讓我的游戲視圖全屏顯示,我在網上找到了一些腳本來實現這一點。 不幸的是,我無法在 2020 版本(或 2018+)中執行它們。 有沒有辦法在編輯器模式下啟用全屏游戲 window? 從下面的腳本中,我在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;
}
}
}
大多數人會建議使用您不想要的“最大化播放按鈕”。
我建議如果您想全屏測試游戲的外觀,只需在編輯構建設置/播放器設置並使游戲全屏后構建並運行,甚至讓使用 alt+enter 進入 go 全屏並測試你的樣子。
這將比在游戲腳本中使用僅在編輯器中測試全屏要容易得多,除非您想在全屏時查看控制台 output。 商店中還有一個免費資產,請參閱構建中的控制台。
https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068
我知道這是在一年前提出的,但也許這對某人有用。
如果你能負擔得起,我推薦這個名為 Fullscreen Editor 的資產。 https://assetstore.unity.com/packages/tools/utilities/fullscreen-editor-69534
或者,Unity 在 package 管理器中具有內置的 package 和編輯器記錄器。 這將自動記錄您的游戲玩法,而不會妨礙您的編輯器 UI 或應用欄。
或者正如其他人所說,進行測試構建或使用編輯器面板中的“最大化播放按鈕”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.