1
我一直在嘗試爲我的統一遊戲製作一個dll,通過向插件發送一個對象SaveGame並保存到IsolatedStorage中。但它不起作用。 這是所使用的代碼保存:XMLSerializer與IsolatedStorage不一起工作
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" />
爲什麼不保存是否正確?
SaveGame.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;
}
}
}
請寄''SaveGame'來源。 – andreycha
剛剛修好。你有什麼主意嗎? – TheKilz