Skip to content

Instantly share code, notes, and snippets.

@LightGive
Created October 6, 2017 08:34
Show Gist options
  • Save LightGive/19ff454c01bf575e8e517f89c1afe82a to your computer and use it in GitHub Desktop.
Save LightGive/19ff454c01bf575e8e517f89c1afe82a to your computer and use it in GitHub Desktop.
Enumの値をUnityのDropDwonに設定するテストプログラム
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EnumToDropDown : MonoBehaviour
{
[SerializeField]
private Dropdown dropDown;
/// <summary>
/// ステータスのタイプ
/// </summary>
public enum StatusType
{
None,
Attack,
Defense,
Magic,
Speed,
}
void Awake()
{
//EnumをStringの配列に変換
string[] enumNames = System.Enum.GetNames(typeof(StatusType));
//Stringの配列をリストに変換
List<string> names = new List<string>(enumNames);
//DropDownの要素にリストを追加
dropDown.AddOptions(names);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment