Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
1.5 KiB

using System;
using System.Collections;
using System.Collections.Generic;
namespace NaughtyAttributes
{
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class DropdownAttribute : DrawerAttribute
{
public string ValuesFieldName { get; private set; }
public DropdownAttribute(string valuesFieldName)
{
this.ValuesFieldName = valuesFieldName;
}
}
public interface IDropdownList : IEnumerable<KeyValuePair<string, object>>
{
}
public class DropdownList<T> : IDropdownList
{
private List<KeyValuePair<string, object>> values;
public DropdownList()
{
this.values = new List<KeyValuePair<string, object>>();
}
public void Add(string displayName, T value)
{
this.values.Add(new KeyValuePair<string, object>(displayName, value));
}
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
return this.values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public static explicit operator DropdownList<object>(DropdownList<T> target)
{
DropdownList<object> result = new DropdownList<object>();
foreach (var kvp in target)
{
result.Add(kvp.Key, kvp.Value);
}
return result;
}
}
}