public static void SerializeLevelPack(LevelPack levelPack, string filePath) { #if !UNITY_WEBGL var levelPackSer = LevelPackSer.Create(levelPack); var serializer = new SerializerBuilder() .WithNamingConvention(new CamelCaseNamingConvention()) .Build(); if (_writerThread?.IsAlive ?? false) { return; } _writerThread = new Thread(() => { File.Delete(TempFilePath); using (var tempFileWriter = new StreamWriter(TempFilePath)) { // ATOMIC OPERATION // Write the level to a temporary file serializer.Serialize(tempFileWriter, levelPackSer); tempFileWriter.Flush(); // Replace the original file with the temporary file File.Copy(TempFilePath, filePath, true); } }); _writerThread.Start(); #endif }
public static LevelPackSer Create(LevelPack levelPack) { return(new LevelPackSer { Info = levelPack.PackInfo, Levels = levelPack.Levels.Select(LevelSer.Create).ToList(), CurrentLevel = levelPack.CurrentLevelNum }); }
public static LevelPackSer Create(LevelPack levelPack) { return(new LevelPackSer { Info = levelPack.PackInfo, Levels = levelPack.Levels.Select(LevelSer.Create).ToList(), CurrentLevel = levelPack.CurrentLevelNum, CurrentLanguage = levelPack.CurrentLanguage, Localization = levelPack.Localization }); }