public async Task ReadEquippedPowerupsAsync() { try { await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerEquippedPowerupLocation()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { } else if (task.IsCompleted) { try { DataSnapshot snapshot = task.Result; string info = snapshot?.GetRawJsonValue()?.ToString(); var result = new string[0]; if (info != null) { result = JsonHelper.FromJson <string>(info); } for (int i = 0; i < result.Length; i++) { UserPowerupManager.Instance.EquippedPowerups[i] = PowerupFactory.GetPowerup(result[i]); } } catch (Exception ex) { Debug.LogError(ex); } } }); } catch (Exception ex) { DebugLogger.Instance.WriteException(ex); } }
public void WriteEquippedPowerups(IPowerup[] powerups) { var data = powerups.Select(x => x.GetType().Name).ToArray(); var toJson = JsonHelper.ToJson(data); var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerEquippedPowerupLocation()).SetRawJsonValueAsync(toJson)); if (result.IsCanceled || result.IsFaulted) { Debug.LogWarning(result.Exception); } }