Beispiel #1
0
    public static void SavePersistentCharacterData <T>(this T characterData) where T : IPlayerCharacterData
    {
        var savingData = new PlayerCharacterData();

        characterData.CloneTo(savingData);
        if (string.IsNullOrEmpty(savingData.Id))
        {
            return;
        }
        savingData.LastUpdate = (int)(System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond);
        var binaryFormatter   = new BinaryFormatter();
        var surrogateSelector = new SurrogateSelector();

        surrogateSelector.AddAllUnitySurrogate();
        surrogateSelector.AddAllCharacterRelatesDataSurrogate();
        binaryFormatter.SurrogateSelector = surrogateSelector;
        var path = Application.persistentDataPath + "/" + savingData.Id + ".sav";

        Debug.Log("Character Saving to: " + path);
        var file = File.Open(path, FileMode.OpenOrCreate);

        binaryFormatter.Serialize(file, savingData);
        file.Close();
        Debug.Log("Character Saved to: " + path);
    }
Beispiel #2
0
 public static T LoadPersistentCharacterData <T>(this T characterData, string path) where T : IPlayerCharacterData
 {
     if (File.Exists(path))
     {
         var binaryFormatter   = new BinaryFormatter();
         var surrogateSelector = new SurrogateSelector();
         surrogateSelector.AddAllUnitySurrogate();
         surrogateSelector.AddAllCharacterRelatesDataSurrogate();
         binaryFormatter.SurrogateSelector = surrogateSelector;
         var file = File.Open(path, FileMode.Open);
         PlayerCharacterData loadedData = (PlayerCharacterData)binaryFormatter.Deserialize(file);
         file.Close();
         loadedData.CloneTo(characterData);
     }
     return(characterData);
 }
Beispiel #3
0
    public void SavePersistentData(string id)
    {
        BinaryFormatter   binaryFormatter   = new BinaryFormatter();
        SurrogateSelector surrogateSelector = new SurrogateSelector();

        surrogateSelector.AddAllUnitySurrogate();
        StorageCharacterItemSerializationSurrogate storageCharacterItemSS = new StorageCharacterItemSerializationSurrogate();
        StorageSaveDataSerializationSurrogate      storageSaveDataSS      = new StorageSaveDataSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(StorageCharacterItem), new StreamingContext(StreamingContextStates.All), storageCharacterItemSS);
        surrogateSelector.AddSurrogate(typeof(StorageSaveData), new StreamingContext(StreamingContextStates.All), storageSaveDataSS);
        binaryFormatter.SurrogateSelector = surrogateSelector;
        string     path = Application.persistentDataPath + "/" + id + "_storage.sav";
        FileStream file = File.Open(path, FileMode.OpenOrCreate);

        binaryFormatter.Serialize(file, this);
        file.Close();
    }
    public void SavePersistentData(string id, string map)
    {
        BinaryFormatter   binaryFormatter   = new BinaryFormatter();
        SurrogateSelector surrogateSelector = new SurrogateSelector();

        surrogateSelector.AddAllUnitySurrogate();
        BuildingSaveDataSerializationSurrogate buildingSaveDataSS = new BuildingSaveDataSerializationSurrogate();
        WorldSaveDataSerializationSurrogate    worldSaveDataSS    = new WorldSaveDataSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(BuildingSaveData), new StreamingContext(StreamingContextStates.All), buildingSaveDataSS);
        surrogateSelector.AddSurrogate(typeof(WorldSaveData), new StreamingContext(StreamingContextStates.All), worldSaveDataSS);
        binaryFormatter.SurrogateSelector = surrogateSelector;
        string     path = Application.persistentDataPath + "/" + id + "_world_" + map + ".sav";
        FileStream file = File.Open(path, FileMode.OpenOrCreate);

        binaryFormatter.Serialize(file, this);
        file.Close();
    }
Beispiel #5
0
    public void LoadPersistentData(string id, string map)
    {
        var path = Application.persistentDataPath + "/" + id + "_world_" + map + ".sav";

        if (File.Exists(path))
        {
            var binaryFormatter   = new BinaryFormatter();
            var surrogateSelector = new SurrogateSelector();
            surrogateSelector.AddAllUnitySurrogate();
            var buildingSaveDataSS = new BuildingSaveDataSerializationSurrogate();
            var worldSaveDataSS    = new WorldSaveDataSerializationSurrogate();
            surrogateSelector.AddSurrogate(typeof(BuildingSaveData), new StreamingContext(StreamingContextStates.All), buildingSaveDataSS);
            surrogateSelector.AddSurrogate(typeof(WorldSaveData), new StreamingContext(StreamingContextStates.All), worldSaveDataSS);
            binaryFormatter.SurrogateSelector = surrogateSelector;
            var file   = File.Open(path, FileMode.Open);
            var result = (WorldSaveData)binaryFormatter.Deserialize(file);
            buildings = result.buildings;
            file.Close();
        }
    }
Beispiel #6
0
    public void LoadPersistentData(string id)
    {
        string path = Application.persistentDataPath + "/" + id + "_storage.sav";

        storageItems.Clear();
        if (File.Exists(path))
        {
            BinaryFormatter   binaryFormatter   = new BinaryFormatter();
            SurrogateSelector surrogateSelector = new SurrogateSelector();
            surrogateSelector.AddAllUnitySurrogate();
            StorageCharacterItemSerializationSurrogate storageCharacterItemSS = new StorageCharacterItemSerializationSurrogate();
            StorageSaveDataSerializationSurrogate      storageSaveDataSS      = new StorageSaveDataSerializationSurrogate();
            surrogateSelector.AddSurrogate(typeof(StorageCharacterItem), new StreamingContext(StreamingContextStates.All), storageCharacterItemSS);
            surrogateSelector.AddSurrogate(typeof(StorageSaveData), new StreamingContext(StreamingContextStates.All), storageSaveDataSS);
            binaryFormatter.SurrogateSelector = surrogateSelector;
            FileStream      file   = File.Open(path, FileMode.Open);
            StorageSaveData result = (StorageSaveData)binaryFormatter.Deserialize(file);
            storageItems = result.storageItems;
            file.Close();
        }
    }