【发布时间】:2015-05-30 00:52:52
【问题描述】:
我遇到了这个问题,不知道如何解决...我尝试了很多方法,但在网上找不到类似的帮助。
注意:另一个场景使用脚本来保存和使用相同的 .dat 文件,但不确定这是否是个问题。
public GameObject[] top10 = new GameObject[10];
[System.Serializable]
public class ScoreEntry
{
public string name;
public int score;
}
// Use this for initialization
void Start () {
if (File.Exists(Application.persistentDataPath + "/hiscores.dat"))
{
BinaryFormatter b = new BinaryFormatter();
var f = File.Open(Application.persistentDataPath + "/hiscores.dat", FileMode.Open);
List<ScoreEntry> hiScores = (List<ScoreEntry>)b.Deserialize(f);
f.Close();
for (int i = 0; i == hiScores.Count; i++)
top10[i].GetComponent<TextMesh>().text += hiScores[i].name + " - " + hiScores[i].score;
}
}
// Update is called once per frame
void Update () {
}
【问题讨论】:
标签: c# unity3d deserialization