UE4中視窗模式切換
阿新 • • 發佈:2019-02-08
1、設定遊戲啟動的預設視窗模式
設定預設模式可通過修改配置檔案的方式,配置檔名DefaultGameUserSettings.ini,位於Config目錄下,如果沒有該檔案可新建一個,配置項如下
修改FullscreenMode的值可設定為全屏或視窗模式,0表示全屏模式,1表示視窗全屏模式,2表示視窗模式,UE4中定義為[/Script/Engine.GameUserSettings] bUseVSync=False ResolutionSizeX=1280 ResolutionSizeY=720 LastUserConfirmedResolutionSizeX=1280 LastUserConfirmedResolutionSizeY=720 WindowPosX=-1 WindowPosY=-1 bUseDesktopResolutionForFullscreen=True FullscreenMode=2 LastConfirmedFullscreenMode=2
UENUM(BlueprintType)
namespace EWindowMode
{
enum Type
{
/** The window is in true fullscreen mode */
Fullscreen,
/** The window has no border and takes up the entire area of the screen */
WindowedFullscreen,
/** The window has a border and may not take up the entire screen area */
Windowed,
};
}
修改ResolutionSizeX和ResolutionSizeY,可設定視窗解析度
2、執行中切換視窗模式
遊戲執行中可通過UGameUserSettings類實現視窗模式切換
void SetFullScreenMode(bool bFull) { if (bFull) { UGameUserSettings::GetGameUserSettings()->SetFullscreenMode(EWindowMode::WindowedFullscreen);//或者EWindowMode::Fullscreen } else { UGameUserSettings::GetGameUserSettings()->SetFullscreenMode(EWindowMode::Windowed); } UGameUserSettings::GetGameUserSettings()->ApplyResolutionSettings(false); }
以上程式碼在UE4.16中測試通過