我正在尝试将我的 pc XNA 游戏移植到 xbox,并尝试将 xna easystorage 与我现有的 pc 文件管理一起实施以获取高分。基本上试图结合http://xnaessentials.com/tutorials/highscores.aspx/tutorials/highscores.aspx与http://easystorage.codeplex.com/
我遇到了一个关于 LoadHighScores() 的特定错误,因为“return (data);”错误 - 使用未分配的局部变量“数据”。
我想这是由于easystorage/xbox的异步设计!?但不确定如何解决 - 以下是代码示例:
原始 PC 代码:(适用于 PC)
public static HighScoreData LoadHighScores(string filename) { HighScoreData data; // 获取游戏保存路径
string fullpath = "Content/highscores.lst";
// Open the file
FileStream stream = File.Open(fullpath, FileMode.Open,FileAccess.Read);
try
{ // Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{ // Close the file
stream.Close();
}
return (data);
}
XBOX 端口:(有错误)
public static HighScoreData LoadHighScores(string container, string filename) { HighScoreData data;
if (Global.SaveDevice.FileExists(container, filename))
{
Global.SaveDevice.Load(container, filename, stream =>
{
File.Open(Global.fileName_options, FileMode.Open,//FileMode.OpenOrCreate,
FileAccess.Read);
try
{
// Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{
// Close the file
stream.Close();
}
});
}
return (data);
}
有任何想法吗?