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

45 行
1.4 KiB

using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace GameOptionsUtility
{
[RequireComponent(typeof(Dropdown))]
public class DropDownTargetFramerate : MonoBehaviour
{
public int[] TargetFramerates = new int[4] { -1, 15, 30, 60 };
public string InfiniteText = "Infinite";
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 framerate in TargetFramerates)
{
dropdown.options.Add(new Dropdown.OptionData(framerate == -1? InfiniteText : framerate.ToString()));
}
int current = GameOption.Get<GraphicOption>().targetFrameRate;
dropdown.SetValueWithoutNotify(dropdown.options.FindIndex(o => o.text == current.ToString()));
}
void UpdateOptions(int value)
{
GameOption.Get<GraphicOption>().targetFrameRate = TargetFramerates[value];
}
}
}