Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected string SaveCinematicToFile(string cinematicName, List<CinematicTimelineNode> cinematicKeys)
- {
- if ((cinematicKeys == null) || (cinematicKeys.Count == 0)) return null;
- string filePath = FilePathForCinematic(cinematicName);
- // Open the file for writing...
- BinaryWriter bWriter;
- try { bWriter = new BinaryWriter(new FileStream(filePath, FileMode.Create)); }
- catch (IOException e) { Debug.LogError("Cannot create cinematic file '" + filePath + "', exception: " + e.Message); return null; }
- // ... and write it out!
- try
- {
- // (so that the loader can handle cases where we're loading an old file)
- bWriter.Write((int)CinematicTimelineNode.DataVersion);
- for (int index = 0; index < cinematicKeys.Count; index++)
- {
- cinematicKeys[index].SaveToBinary(bWriter);
- }
- }
- catch (IOException e) { Debug.LogError("Failed writing cinematic file '" + filePath + "', exception: " + e.Message); return null; }
- // Then we're done!
- bWriter.Close();
- return filePath;
- }
- protected bool LoadCinematicFromFile(string cinematicName)
- {
- // (even if we fail to load, any old cinematic is toast)
- ClearCinematic();
- string cinematicDirectory = Application.streamingAssetsPath + Path.DirectorySeparatorChar + CinematicFilesRelativePath;
- string filePath = cinematicDirectory + Path.DirectorySeparatorChar + cinematicName + CinematicFileExtension;
- // Open the file for reading...
- BinaryReader bReader;
- try { bReader = new BinaryReader(new FileStream(filePath, FileMode.Open)); }
- catch (IOException e) { Debug.LogError("Cannot load cinematic file '" + filePath + "', exception: " + e.Message); return false; }
- // ... and read it in!
- curCinematicKeys = new List<CinematicTimelineNode>();
- bool keepReading = true;
- try
- {
- // (so that the loader can handle cases where we're loading an old file)
- int fileDataVersion = bReader.ReadInt32();
- while (keepReading)
- {
- CinematicTimelineNode newNode = new CinematicTimelineNode();
- newNode.LoadFromBinary(bReader, fileDataVersion);
- curCinematicKeys.Add(newNode);
- // Make sure we haven't run off the end of the file
- try { if (bReader.PeekChar() < 0) keepReading = false; }
- #pragma warning disable 0168
- catch (IOException eofe) { keepReading = false; }
- #pragma warning restore 0168
- }
- }
- catch (IOException e) { Debug.LogError("Failed writing cinematic file '" + filePath + "', exception: " + e.Message); return false; }
- // Then we're done!
- bReader.Close();
- return true;
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment