Created
October 6, 2017 08:34
-
-
Save LightGive/19ff454c01bf575e8e517f89c1afe82a to your computer and use it in GitHub Desktop.
Enumの値をUnityのDropDwonに設定するテストプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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