我已经为图形和屏幕创建了UI选项菜单。问题是我能够为全屏模式添加一个布尔值。我需要添加一个带有3种模式的下拉列表:全屏,窗户和窗户没有框架(延伸到整个屏幕尺寸)。我如何获得第三种模式?
查看此示例代码。但是,它使用user32.dll
库,因此您很可能需要在项目中引用它。
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;
using UnityEngine;
public class WindowMod : MonoBehaviour
{
public Rect screenPosition;
[DllImport("user32.dll")]
static extern IntPtr SetWindowLong (IntPtr hwnd,int _nIndex ,int dwNewLong);
[DllImport("user32.dll")]
static extern bool SetWindowPos (IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow ();
// not used rigth now
//const uint SWP_NOMOVE = 0x2;
//const uint SWP_NOSIZE = 1;
//const uint SWP_NOZORDER = 0x4;
//const uint SWP_HIDEWINDOW = 0x0080;
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
void Start ()
{
SetWindowLong(GetForegroundWindow (), GWL_STYLE, WS_BORDER);
bool result = SetWindowPos (GetForegroundWindow (), 0,(int)screenPosition.x,(int)screenPosition.y, (int)screenPosition.width,(int) screenPosition.height, SWP_SHOWWINDOW);
}
使用此方法,您最好的选择是:
- 为所有选项创建枚举,例如
public enum WindowMode { FullScreen, Borderless, Window }
- 创建一个将枚举作为参数的方法创建一个经理类:
public void SetWindowMode(WindowMode wm // or int) {...}
- 将其连接起来,以便每当从uui的
EventSystem
Thingy thingy thingy
中选择一个从combobox中选择项目时,该方法就会调用。 - 几乎是这样。