}
using UnityEngine;
using System;
public class WindowMod1 : MonoBehaviour
{
private float aspect16_9;
private int screenWidth = 1280;
private int screenHeight = 720;
private int widthScal = 16;
private int heightScal = 9;
void Start()
{
//16:9固定比例
aspect16_9 = (float)widthScal / heightScal;
}
void Update()
{
SetResolution();
}
void SetResolution()
{
int curScreenWidth = Screen.width;
int curScreenHeight = Screen.height;
if(curScreenWidth == screenWidth && curScreenHeight == screenHeight)
{
return;
}
float curScale = (float)curScreenWidth / curScreenHeight;
if (curScale > aspect16_9)
{
int h = (int)((heightScal * curScreenWidth) / widthScal);
Screen.SetResolution(curScreenWidth, h, false);
screenWidth = curScreenWidth;
}
else if (curScale < aspect16_9)
{
int w = (int)((widthScal * curScreenHeight) / heightScal);
Screen.SetResolution(w, curScreenHeight, false);
screenHeight = curScreenHeight;
}
}
void OnApplicationQuit()
{
Application.CancelQuit();
int returnNum = Message.MessageBox(IntPtr.Zero, "确定退出游戏吗?", "我的游戏", 1);
if(returnNum == 1)
{
//点击确定按钮
Application.Quit();
}
}
}