Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;
public static class LoadSaveController {
// Save
public static void Save (object obj, string type) {
Stream stream = File.Open (Application.persistentDataPath + "/Saves." + type, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter ();
bf.Serialize (stream, obj);
stream.Close ();
}
// Load
public static object Load (string type) {
Stream stream = File.Open (Application.persistentDataPath + "/Saves." + type, FileMode.Open);
BinaryFormatter bf = new BinaryFormatter ();
object data = bf.Deserialize (stream);
stream.Close ();
return data;
}
}