SaveSystem.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. using UnityEngine;
  6. public static class SaveSystem
  7. {
  8. private static readonly string path = Application.dataPath + "/joints.sav";
  9. public static void Save(List<Vector3[]> jointsSequence, List<float> recordingTimes)
  10. {
  11. BinaryFormatter formatter = new BinaryFormatter();
  12. FileStream stream = new FileStream(path, FileMode.Create);
  13. JointsDataSequence data = new JointsDataSequence(jointsSequence, recordingTimes);
  14. formatter.Serialize(stream, data);
  15. stream.Close();
  16. }
  17. public static JointsDataSequence Load()
  18. {
  19. if (File.Exists(path))
  20. {
  21. BinaryFormatter formatter = new BinaryFormatter();
  22. FileStream stream = new FileStream(path, FileMode.Open);
  23. JointsDataSequence data = formatter.Deserialize(stream) as JointsDataSequence;
  24. stream.Close();
  25. return data;
  26. } else
  27. {
  28. Debug.LogError("Save file not found in " + path);
  29. return null;
  30. }
  31. }
  32. }