NG_/Scripts/UI/全局/FullScreenToggle.cs
2024-12-13 18:49:44 +08:00

32 lines
892 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class FullScreenToggle : MonoBehaviour,IPointerClickHandler
{
private void Start()
{
// 设置默认窗口大小
// Screen.SetResolution(1920, 1080, true);
}
public void OnPointerClick(PointerEventData eventData)
{
// 切换全屏模式
Screen.fullScreen =!Screen.fullScreen;
// 如果当前是全屏模式,重置窗口大小为原始分辨率
if (Screen.fullScreen)
{
// 获取原始分辨率
int originalWidth = Screen.currentResolution.width;
int originalHeight = Screen.currentResolution.height;
// 设置窗口大小为原始分辨率
Screen.SetResolution(originalWidth, originalHeight, false);
}
}
}