做项目的时候,经常把一些数据序列化一下进行存储。但是序列化的类中包含UnityEngine.Color(其实UnityEngine里的基本都无法序列化,包括Vector3之类的)就无法序列化,打印出来错误显示“Type UnityEngine.Color is not marked as Serializable.”。想要使用,就只能自己手动转换一下,比如:
float[] color = new color[4];
public Color GetColor()
{
return new Color(color[0], color[1], color[2], color[3]);
}
public void SetColor(Color c)
{
color[0] = c.r;
color[1] = c.g;
color[2] = c.b;
color[3] = c.a;
}