我一直在尝试为我的统一游戏制作一个 dll,方法是将对象 SaveGame 发送到插件,然后保存到独立存储中。但它不起作用。这是用于保存的代码:
public static void Save(SaveGame filetobeSaved)
{
using (IsolatedStorageFile armz = IsolatedStorageFile.GetUserStoreForApplication())
{
if (armz.FileExists("save.gd"))
{
armz.DeleteFile("save.gd");
}
using (IsolatedStorageFileStream file = new IsolatedStorageFileStream("save.gd", System.IO.FileMode.Create, armz))
{
XmlSerializer serializer = new XmlSerializer(typeof(SaveGame));
serializer.Serialize(file, filetobeSaved);
}} }
当我使用 IsoStoreSpy 检查此文件时,该文件只有以下内容:
<?xml version="1.0" encoding="utf-8"?>
<SaveGame xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
为什么不能正确保存?
保存游戏.cs
public class SaveGame
{
public static int gold { get; set; }
public static int BalasMais { get; set; }
public static int DanoMais { get; set; }
public static int SpeedMais { get; set; }
public static int LifeMais { get; set; }
public int getGold() { return gold; }
public int getBalas() { return BalasMais; }
public int getDano() { return DanoMais; }
public int getSpeed() { return SpeedMais; }
public int getLife() { return LifeMais; }
public SaveGame()
{
gold = 0;
BalasMais = 0;
DanoMais = 0;
SpeedMais = 0;
LifeMais = 0;
}
public SaveGame(int g, int b, int d, int s, int l)
{
gold = g;
BalasMais = b;
DanoMais = d;
SpeedMais = s;
LifeMais = l;
}
}
}