这篇文章记录自己的一些学习,这些功能还是比较简单的,只需要知道对用的内部方法调用或者一些特性
首先是窗口化
需要写一个特性,定义对用的字段
//窗口化
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
const int SW_SHOWRESTORE = 1; //还原
const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}
const int SW_SHOWMAXIMIZED = 3; //最大化
在UI界面添加3个按钮,最小化、最大化、还原按钮
//窗口化按钮
private Button Min, Max, Reduction,Offers;
设置屏幕分辨率给按钮添加按钮监听事件
//获取设置当前屏幕分辩率
Resolution[] resolutions = Screen.resolutions;
//设置当前分辨率
Screen.SetResolution(resolutions[resolutions.Length - 1].width,
resolutions[resolutions.Length - 1].height, FullScreenMode.Windowed);
Screen.fullScreen = false;
Min.onClick.AddListener(OnClickMinimize);
Max.onClick.AddListener(OnClickMaximize);
Reduction.onClick.AddListener(OnClickRestore);
下面具体的实现
/// <summary>
/// 三种窗口化
/// </summary>
public void OnClickMinimize()
{
ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);
}
public void OnClickMaximize()
{
ShowWindow(GetForegroundWindow(), SW_SHOWMAXIMIZED);
}
public void OnClickRestore()
{
ShowWindow(GetForegroundWindow(), SW_SHOWRESTORE);
}
编辑模式下的退出/程序模式下的退出
这个就非常简单了,添加好按钮和监听事件
//Unity编译器模式下
UnityEditor.EditorApplication.isPlaying = false;
//App程序运行下
Application.Quit();
获取系统时间
在UI界面制作显示时间的文本框
//将这个方法放到Update方法内调用
private void RealTimes()
{
DateTime NowTime = DateTime.Now.ToLocalTime();
Time.text = NowTime.ToString("yyyy - MM - dd HH: mm:ss");
}