在此项目中,您能够访问使用 Visual Effect Graph 制作的示例场景和效果。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

66 行
1.9 KiB

using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace GameOptionsUtility
{
[RequireComponent(typeof(Dropdown))]
public class DropDownResolution : MonoBehaviour
{
public DropDownRefreshRate dropDownRefreshRate;
private void OnEnable()
{
var dropdown = GetComponent<Dropdown>();
InitializeEntries();
dropdown.onValueChanged.AddListener(UpdateOptions);
UpdateOptions(dropdown.value);
}
private void OnDisable()
{
GetComponent<Dropdown>().onValueChanged.RemoveListener(UpdateOptions);
}
public void InitializeEntries()
{
var dropdown = GetComponent<Dropdown>();
dropdown.options.Clear();
int selected = 0;
int i = 0;
foreach (var res in Screen.resolutions.OrderByDescending(o => o.width))
{
string option = $"{res.width}x{res.height}";
if (!dropdown.options.Any(o => o.text == option))
{
dropdown.options.Add(new Dropdown.OptionData(option));
if (res.width == GameOptions.graphics.width && res.height == GameOptions.graphics.height)
selected = i;
i++;
}
}
dropdown.SetValueWithoutNotify(selected);
if (dropDownRefreshRate != null)
{
dropDownRefreshRate.InitializeEntries();
}
}
void UpdateOptions(int value)
{
string option = GetComponent<Dropdown>().options[value].text;
string[] values = option.Split('x');
GameOptions.graphics.width = int.Parse(values[0]);
GameOptions.graphics.height = int.Parse(values[1]);
}
}
}