Beispiel #1
0
 public void Save(ISaveable saveable, bool flush = true)
 {
     if (IsRegistered(saveable))
     {
         if (saveable.IsLoaded)
         {
             try {
                 string saveString = JsonConvert.SerializeObject(saveable.GetSave());
                 storage?.SetString(saveable.SaveKey, saveString, flush);
                 //UDebug.Log($"SAVED: {saveable.SaveKey} => {saveString}".Colored(ConsoleTextColor.magenta));
             } catch (System.Exception exception) {
                 Services.GetService <IConsoleService>().AddOutput($"exception when save {saveable.SaveType.Name}", ConsoleTextColor.red, true);
                 Services.GetService <IConsoleService>().AddOutput(exception.Message, ConsoleTextColor.red, true);
                 Services.GetService <IConsoleService>().AddOutput(exception.StackTrace, ConsoleTextColor.red, true);
             }
         }
     }
     else
     {
         throw new UnityException($"Save: saveable of type => {saveable.GetType().Name} is not registered on ISaveService");
     }
 }
Beispiel #2
0
 private void WriteSaveable(ISaveable saveable)
 {
     using (BinaryWriter writer = new BinaryWriter(System.IO.File.Open(GetSaveableFilePath(saveable), System.IO.FileMode.Create))) {
         writer.Write(saveable.GetSave());
     }
 }