public enum PosType
{
Up,
Down,
Left,
Right
}
获取在Enum内索引
PosType type = PosType.Down;
int index =type.GetHashCode(); ;
获取在Enum内对应名字
int type =0;
string name= Enum.GetName(typeof(PosType), type);
获取对应Enum值
int type =0;
PosType pos =(PosType)type;
//or
//PosType pos = (PosType)Enum.Parse(typeof(PosType), Enum.GetName(typeof(PosType), type));
获取随机Enum值
PosType pos = (PosType)Random.Range(0, 4);