我在Unity中做游戏,需要将我的结构列表转换为字符串。我的代码放在一个名为MonsterHandler的类中。C#如何将结构类型列表转换为字符串?
public enum S_STATE
{
S_IDLE,
S_PATROL,
S_ATTACK,
NONE
}
public struct MONSTERS
{
public string Name;
public int Health;
public int Damage;
public S_STATE State;
};
public List<MONSTERS> monsterList= new List<MONSTERS>();
void Start()
{
// add data into the monsterList
// Debug.Log(monsterList.Count); // print out 5
Debug.Log(monsterList.ToArray()); //printed out "MonsterHandler + MONSTERS"
// i want to do something like this
// "Monster_Zombie, 100, 20, S_IDLE, Monster_Donkey, 80, 30, S_IDLE, Monster_Chicken, 120 , 10, IDLE,.."
}
}
有没有办法把我的结构列表转换成字符串[],然后转换成字符串?或者有任何其他方式
你想印什么? –
@KeithNicholas我想打印出这样的东西 – Benjan
“Monster_Zombie,100,20,S_IDLE,Monster_Donkey,80,30,S_IDLE,Monster_Chicken,120,10,IDLE,..” – Benjan