马上注册,加入CGJOY,让你轻松玩转CGJOY。
您需要 登录 才可以下载或查看,没有帐号?立即注册
×
首先,添加一个Dropdown
效果
将下面的代码挂在物体上- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections.Generic;
- public class SetScreenResolving : MonoBehaviour
- {
- private Resolution[] reso;
- public Dropdown mDropdown;
- private List<Dropdown.OptionData> odList = new List<Dropdown.OptionData>();
- void Start()
- {
- reso = Screen.resolutions;
- mDropdown.options.Clear();
- for (int i = 0; i < reso.Length; i++)
- {
- odList.Add(new Dropdown.OptionData());
- odList[i].text = ShowResolving(reso[i]);
- mDropdown.value = i;
- mDropdown.options.Add(odList[i]);
- mDropdown.onValueChanged.AddListener(index =>
- {
- mDropdown.captionText.text = ShowResolving(reso[index]);
- Screen.SetResolution(reso[index].width, reso[index].height, true);
- });
- mDropdown.captionText.text = "屏幕分辨率";
- }
- }
- string ShowResolving(Resolution res)
- {
- return res.width + "X" + res.height;
- }
- }
复制代码
|