谁能告诉我我做错了什么?当我在编辑器中玩游戏时,一切正常。当我构建游戏并在那里尝试保存游戏作品时,但在加载游戏数据时出现此错误:ArgumentNullException: Value cannot be null. 我一直在寻找解决方案,但似乎找不到任何解决方案。
public void SaveGame()
{
checkGameData();
XmlSerializer serializer = new XmlSerializer(typeof(PoliceSave));
FileStream stream = new FileStream(Application.persistentDataPath + "/gameData.xml", FileMode.Create);
serializer.Serialize(stream, policeSave);
stream.Close();
policeSave.GameData.Clear();
policeSave.Characters.Clear();
policeSave.Vehicles.Clear();
vehicleDetails.passenger.characters.Clear();
Debug.Log("[Server] Your game has been saved.");
}
public void LoadGame()
{
clearGameObjects();
XmlSerializer serializer = new XmlSerializer(typeof(PoliceSave));
FileStream stream = new FileStream(Application.persistentDataPath + "/gameData.xml", FileMode.Open);
//try
//{
policeSave = serializer.Deserialize(stream) as PoliceSave;
//}catch
//{
Debug.Log("[Server] Error while loading game data!");
//}
stream.Close();
loadGameObjects();
policeSave.GameData.Clear();
policeSave.Characters.Clear();
policeSave.Vehicles.Clear();
vehicleDetails.passenger.characters.Clear();
Debug.Log("[Server] Your game has been loaded.");
}
[System.Serializable]
public class GameData
{
[XmlAttribute("Funds")]
public int funds;
[XmlAttribute("MissionID")]
public int missionId;
}
[System.Serializable]
public class Passenger
{
[XmlAttribute("Name")]
public List<string> characters;
}
[System.Serializable]
public class Vec2Position
{
[XmlAttribute("x")]
public float x;
[XmlAttribute("y")]
public float y;
}
[System.Serializable]
public class Rotation
{
[XmlAttribute("z")]
public float z;
}
[System.Serializable]
public class CharacterDetails
{
[XmlAttribute("Name")]
public string characterName;
[XmlAttribute("IsCameraSubject")]
public bool isCameraSubject;
public Vec2Position Position;
public Rotation Rotation;
}
繁星coding
相关分类