public async Task LoadPieceCollectionAsync()
        {
            try
            {
                await FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerCollectionLocation())
                .GetValueAsync().ContinueWith(task =>
                {
                    if (task.IsFaulted)
                    {
                    }
                    else if (task.IsCompleted)
                    {
                        try
                        {
                            DataSnapshot snapshot = task.Result;

                            string info = snapshot?.GetRawJsonValue()?.ToString();

                            var array = new PiecesCollected.PieceCollectionInfo[0];
                            if (info != null)
                            {
                                array = JsonHelper.FromJson <PiecesCollected.PieceCollectionInfo>(info);
                            }

                            var result = new PiecesCollected();
                            if (array != null)
                            {
                                result.Pieces.AddRange(array);
                            }

                            PieceCollectionManager.Instance.PiecesCollected = result;
                        }
                        catch (Exception ex)
                        {
                            Debug.LogError(ex);
                        }
                    }
                });
            }
            catch { }
        }
Exemple #2
0
        public void WritePiecesCollected(PiecesCollected pieces)
        {
            var toJson = JsonHelper.ToJson(pieces.Pieces.ToArray());

            var result = System.Threading.Tasks.Task.Run(() => FireBaseDatabase.Database.Child(FireBaseSavePaths.PlayerCollectionLocation()).SetRawJsonValueAsync(toJson));

            if (result.IsCanceled || result.IsFaulted)
            {
                Debug.LogWarning(result.Exception);
            }
        }