public void OnProtoDeserialize(ProtobufSerializer serializer) { PrefabIdentifier prefabIdentifier = GetComponent <PrefabIdentifier>(); Debug.Log($"Deserializing {prefabIdentifier.Id}"); string oldDataPath = QPatch.GetOldSaveDirectory(); oldDataPath = string.Concat(oldDataPath, prefabIdentifier.Id, ".json"); //Port old data if (File.Exists(oldDataPath)) { Debug.Log($"Loading {prefabIdentifier.Id} from old data"); BaseClockSaveData saveData = JsonConvert.DeserializeObject <BaseClockSaveData>(File.ReadAllText(oldDataPath)); m_UseSystemTime = saveData.usesSystemTime; UseSystemTimeSet(m_UseSystemTime); File.Delete(oldDataPath); Debug.Log($"Ported {prefabIdentifier.Id}"); } else { string containerPath = Path.Combine("BaseClocks", $"{prefabIdentifier.Id}.json"); BaseClocksCoroutineRunner.Instance.StartCoroutine(DeserializeCoroutine(containerPath)); } }
private IEnumerator DeserializeCoroutine(string path) { Debug.Log($"trying to load {path}"); UserStorage userStorage = PlatformUtils.main.GetUserStorage(); UserStorageUtils.LoadOperation loadOperation = userStorage.LoadFilesAsync(SaveLoadManager.main.GetCurrentSlot(), new List <string>() { path }); yield return(loadOperation); if (loadOperation.GetSuccessful()) { string json = Encoding.ASCII.GetString(loadOperation.files[path]); BaseClockSaveData saveData = JsonConvert.DeserializeObject <BaseClockSaveData>(json); m_UseSystemTime = saveData.usesSystemTime; UseSystemTimeSet(m_UseSystemTime); Debug.Log($"{path} loaded"); } }
public void OnProtoSerialize(ProtobufSerializer serializer) { PrefabIdentifier prefabIdentifier = GetComponent <PrefabIdentifier>(); string slot = SaveLoadManager.main.GetCurrentSlot(); string fileName = $"{prefabIdentifier.Id}.json"; slot = Path.Combine(slot, "BaseClocks"); var userStorage = PlatformUtils.main.GetUserStorage(); userStorage.CreateContainerAsync(slot); BaseClockSaveData saveData = new BaseClockSaveData() { usesSystemTime = UsingSystemTime() }; string json = JsonConvert.SerializeObject(saveData); Dictionary <string, byte[]> saveFiles = new Dictionary <string, byte[]> { [fileName] = Encoding.ASCII.GetBytes(json) }; userStorage.SaveFilesAsync(slot, saveFiles); }