- 最后登录
- 2019-6-25
- 注册时间
- 2016-9-18
- 阅读权限
- 20
- 积分
- 193

- 纳金币
- 26
- 精华
- 0
|
首先,添加一个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;
- }
- }
复制代码 |
|