“EnumTest”脚本具体代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class EnumTest : MonoBehaviour {
///
/// E test. 定义一个枚举类型,长度个数为3
///
public enum ETest
{ one,
two,
three
}
// Use this for initialization
void Start () {
//新建一个枚举
ETest e = new ETest ();
/*
* 通过Enum.GetNames获取对应枚举类型的数组
* 然后把结果保存到一个数组中
*/
string[] arrayETest = System.Enum.GetNames (e.GetType ());
//循环打印枚举数组
for(int i = 0; i
print (String.Format ("ETest[{0}] : {1}", i, arrayETest[i]));
}
}
// Update is called once per frame
void Update () {
}
}