Unity Dropdown 控件 更改 屏幕分辨率

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yuhijk2055/article/details/74332282
首先,新建一个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;
    }
}


展开阅读全文

没有更多推荐了,返回首页