With the help of the IRC communauty, I pull out saving and loading data into/from savegame.
So to help other people who might need to save/load data, here is how I did it:
So at New Game and Save Game, OnLoadData() is called on all the class "SerializableDataExtensionBase".
There you need to load the data with the manager according to the name you save them under.
It seems that currently, at newgame or if the save doesn't have your data, it will return a null pointer and not an empty byte[].
Then you take the data and store it where you need it.
At Save time, it will call the OnSaveData() data, where you need to feed the manager with the name and the serialized data.
And that's it.
Note: I'm still trying to have nicer serialize/deserialize method so any idea is welcome.
So to help other people who might need to save/load data, here is how I did it:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using ICities;
using UnityEngine;
namespace DifficultyOptions
{
public class DifficultySettings : SerializableDataExtensionBase
{
private static int _maintenanceCostMod = 100;
private static int _constructionCostMod = 100;
public void setMaintenanceCost(int value) { _maintenanceCostMod = value; }
public int getMaintenanceCost() { return _maintenanceCostMod; }
public void setConstructionCost(int value) { _constructionCostMod = value; }
public int getConstructionCost() { return _constructionCostMod; }
public byte[] serialize()
{
IEnumerable<byte> maintenanceCostData = BitConverter.GetBytes(_maintenanceCostMod);
IEnumerable<byte> constructionCostData = BitConverter.GetBytes(_constructionCostMod);
IEnumerable<byte> serialized = maintenanceCostData.Concat(constructionCostData)
return serialized.ToArray<byte>();
}
public void deserialize(byte[] data)
{
_maintenanceCostMod = BitConverter.ToInt32(data, 0);
_constructionCostMod = BitConverter.ToInt32(data, 4);
}
public override void OnSaveData()
{
this.serializableDataManager.SaveData("ZarineDifficultyMod", this.serialize());
}
public override void OnLoadData()
{
byte[] data = this.serializableDataManager.LoadData("ZarineDifficultyMod");
if (data == null) { return; }
this.deserialize(data);
}
}
}
So at New Game and Save Game, OnLoadData() is called on all the class "SerializableDataExtensionBase".
There you need to load the data with the manager according to the name you save them under.
It seems that currently, at newgame or if the save doesn't have your data, it will return a null pointer and not an empty byte[].
Then you take the data and store it where you need it.
At Save time, it will call the OnSaveData() data, where you need to feed the manager with the name and the serialized data.
And that's it.
Note: I'm still trying to have nicer serialize/deserialize method so any idea is welcome.
Last edited: