您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

42 行
1.1 KiB

using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace GameOptionsUtility
{
[RequireComponent(typeof(Dropdown))]
public class DropDownQuality : MonoBehaviour
{
private void OnEnable()
{
var dropdown = GetComponent<Dropdown>();
InitializeEntries(dropdown);
dropdown.onValueChanged.AddListener(UpdateOptions);
UpdateOptions(dropdown.value);
}
private void OnDisable()
{
GetComponent<Dropdown>().onValueChanged.RemoveListener(UpdateOptions);
}
public void InitializeEntries(Dropdown dropdown)
{
dropdown.options.Clear();
foreach(var quality in QualitySettings.names)
dropdown.options.Add(new Dropdown.OptionData(quality));
int current = GameOption.Get<GraphicOption>().quality;
dropdown.SetValueWithoutNotify(current);
}
void UpdateOptions(int value)
{
GameOption.Get<GraphicOption>().quality = value;
}
}
}