SaveSystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. public static void Save(string path, List<Vector3[]> jointsSequence, List<float> recordingTimes)
  9. {
  10. BinaryFormatter formatter = new BinaryFormatter();
  11. FileStream stream = new FileStream(path, FileMode.Create);
  12. JointsDataSequence data = new JointsDataSequence(jointsSequence, recordingTimes);
  13. formatter.Serialize(stream, data);
  14. stream.Close();
  15. }
  16. public static JointsDataSequence Load(string path)
  17. {
  18. if (File.Exists(path))
  19. {
  20. BinaryFormatter formatter = new BinaryFormatter();
  21. FileStream stream = new FileStream(path, FileMode.Open);
  22. JointsDataSequence data = formatter.Deserialize(stream) as JointsDataSequence;
  23. stream.Close();
  24. return data;
  25. } else
  26. {
  27. Debug.LogError("Save file not found in " + path);
  28. return null;
  29. }
  30. }
  31. }