Guest User

Untitled

a guest
Apr 15th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. protected string SaveCinematicToFile(string cinematicName, List<CinematicTimelineNode> cinematicKeys)
  2. {
  3. if ((cinematicKeys == null) || (cinematicKeys.Count == 0)) return null;
  4.  
  5. string filePath = FilePathForCinematic(cinematicName);
  6.  
  7. // Open the file for writing...
  8. BinaryWriter bWriter;
  9. try { bWriter = new BinaryWriter(new FileStream(filePath, FileMode.Create)); }
  10. catch (IOException e) { Debug.LogError("Cannot create cinematic file '" + filePath + "', exception: " + e.Message); return null; }
  11.  
  12. // ... and write it out!
  13. try
  14. {
  15. // (so that the loader can handle cases where we're loading an old file)
  16. bWriter.Write((int)CinematicTimelineNode.DataVersion);
  17.  
  18. for (int index = 0; index < cinematicKeys.Count; index++)
  19. {
  20. cinematicKeys[index].SaveToBinary(bWriter);
  21. }
  22. }
  23. catch (IOException e) { Debug.LogError("Failed writing cinematic file '" + filePath + "', exception: " + e.Message); return null; }
  24.  
  25. // Then we're done!
  26. bWriter.Close();
  27.  
  28. return filePath;
  29. }
  30.  
  31. protected bool LoadCinematicFromFile(string cinematicName)
  32. {
  33. // (even if we fail to load, any old cinematic is toast)
  34. ClearCinematic();
  35.  
  36. string cinematicDirectory = Application.streamingAssetsPath + Path.DirectorySeparatorChar + CinematicFilesRelativePath;
  37. string filePath = cinematicDirectory + Path.DirectorySeparatorChar + cinematicName + CinematicFileExtension;
  38.  
  39. // Open the file for reading...
  40. BinaryReader bReader;
  41. try { bReader = new BinaryReader(new FileStream(filePath, FileMode.Open)); }
  42. catch (IOException e) { Debug.LogError("Cannot load cinematic file '" + filePath + "', exception: " + e.Message); return false; }
  43.  
  44. // ... and read it in!
  45. curCinematicKeys = new List<CinematicTimelineNode>();
  46.  
  47. bool keepReading = true;
  48. try
  49. {
  50. // (so that the loader can handle cases where we're loading an old file)
  51. int fileDataVersion = bReader.ReadInt32();
  52.  
  53. while (keepReading)
  54. {
  55. CinematicTimelineNode newNode = new CinematicTimelineNode();
  56. newNode.LoadFromBinary(bReader, fileDataVersion);
  57. curCinematicKeys.Add(newNode);
  58.  
  59. // Make sure we haven't run off the end of the file
  60. try { if (bReader.PeekChar() < 0) keepReading = false; }
  61. #pragma warning disable 0168
  62. catch (IOException eofe) { keepReading = false; }
  63. #pragma warning restore 0168
  64. }
  65. }
  66. catch (IOException e) { Debug.LogError("Failed writing cinematic file '" + filePath + "', exception: " + e.Message); return false; }
  67.  
  68. // Then we're done!
  69. bReader.Close();
  70. return true;
  71. }
  72. #endregion
Advertisement
Add Comment
Please, Sign In to add comment