public
Button
hideCloseBtn
;
public
Button
showCloseBtn
;
public
Button
showMaxSizeBtn
;
private
void
Awake
(
)
var
hwd
=
GetForegroundWindow
(
)
;
hideBarBtn
.
onClick
.
AddListener
(
(
)
=>
var
wl
=
GetWindowLong
(
hwd
,
GWL_STYLE
)
;
wl
&=
~
WS_CAPTION
;
SetWindowLong
(
hwd
,
GWL_STYLE
,
wl
)
;
}
)
;
showBarBtn
.
onClick
.
AddListener
(
(
)
=>
var
wl
=
GetWindowLong
(
hwd
,
GWL_STYLE
)
;
wl
|=
WS_CAPTION
;
SetWindowLong
(
hwd
,
GWL_STYLE
,
wl
)
;
}
)
;
hideCloseBtn
.
onClick
.
AddListener
(
(
)
=>
var
wl
=
GetWindowLong
(
hwd
,
GWL_STYLE
)
;
wl
&=
~
WS_SYSMENU
;
SetWindowLong
(
hwd
,
GWL_STYLE
,
wl
)
;
}
)
;
showCloseBtn
.
onClick
.
AddListener
(
(
)
=>
var
wl
=
GetWindowLong
(
hwd
,
GWL_STYLE
)
;
wl
|=
WS_SYSMENU
;
SetWindowLong
(
hwd
,
GWL_STYLE
,
wl
)
;
}
)
;
showMaxSizeBtn
.
onClick
.
AddListener
(
(
)
=>
ShowWindow
(
hwd
,
SW_SHOWMAXIMIZED
)
;
}
)
;
private
void
OnApplicationQuit
(
)
Application
.
wantsToQuit
+=
(
)
=>
var
hwd
=
GetForegroundWindow
(
)
;
ShowWindow
(
hwd
,
SW_SHOWMINIMIZED
)
;
return
false
;
[
DllImport
(
"user32.dll"
)
]
public
static
extern
IntPtr
GetForegroundWindow
(
)
;
[
DllImport
(
"user32.dll"
)
]
public
static
extern
bool
ShowWindow
(
IntPtr
hwd
,
int
cmdShow
)
;
[
DllImport
(
"user32.dll"
)
]
public
static
extern
long
GetWindowLong
(
IntPtr
hwd
,
int
nIndex
)
;
[
DllImport
(
"user32.dll"
)
]
public
static
extern
void
SetWindowLong
(
IntPtr
hwd
,
int
nIndex
,
long
dwNewLong
)
;
const
int
SW_SHOWMINIMIZED
=
2
;
const
int
SW_SHOWMAXIMIZED
=
3
;
const
int
SW_SHOWRESTORE
=
1
;
const
int
GWL_STYLE
=
-
16
;
const
int
WS_CAPTION
=
0x00c00000
;
const
int
WS_SYSMENU
=
0x00080000
;
如果是需要尽早执行的话可以推荐将代码放到[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]特性下调用。
RuntimeInitializeOnLoadMethod介绍
代码using System;using System.Runtime.InteropServices;using UnityEngine;using UnityEngine.UI;public class WindowsStyle : MonoBehaviour{ public Button hideBarBtn; public Button showBarBtn; public Button hideCloseBtn; public Button showC
using System.Runtime.InteropServices;
public class
Windows
SET:MonoSingleton<
Windows
SET>
#region
窗口
最小化
定义
[DllImport("user32.d...
//通过非托管方式导入dll。这里是导入user32.dll。
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dl.
游戏
资源 -
Unity
中地块自动化生成 - 地形优化必备资源
该资源为在
游戏
中对地块自动化生成时使用,让我们的项目不用白白消耗性能。
具体使用方法可以来我博客搜索:地图自动化生成。查看具体的教程及详细的使用方法!
博客地址:https://xiaoy.blog.csdn.net/
public class ToolControlTaskBar
[DllImport("user32.dll")] //这里是引入 user32.dll 库, 这个库是
windows
系统自带的。
pub...
Unity
发布的PC 端程序怎么实现
隐藏
任务栏,
窗口
置顶,
隐藏
标题? 如果单单使用
Unity
的api 能否实现我不知道,反正查了很多 但是都没查到。那么,我想到了借助
windows
的编程库来实现,反正
Unity
是可以调用 c++ 和
C#
库函数的。
using System.Runtime.InteropServices;
//control the task bar hide or show
//liuyanlei
public class ToolControlTaskBar
//
最大化
窗口
Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, true);
//
最小化
窗口
Screen.SetResolution(1, 1, false);
希望能对您有所帮助。