Beispiel #1
0
    void Start()
    {
        Debug.Log("QuestManager.Start");

        _showLoading.Raise();

        _questUi.FadeQuestScreenIn();
        firebaseData.database.Child(QuestFolderName).Child(firebaseData.currentUserUserId).GetValueAsync().ContinueWith(
            readTask =>
        {
            if (readTask.Result == null)
            {
                var json = JsonConvert.SerializeObject(QuestProgress);
                firebaseData.database.Child(QuestFolderName).Child(firebaseData.currentUserUserId)
                .SetRawJsonValueAsync(json).ContinueWith(writeTask =>
                {
                    if (writeTask.IsFaulted)
                    {
                        Debug.LogError(
                            "QuestManager: Failed to write default quest data to firebase realtime database!");
                        Debug.LogError("Error message: " + writeTask.Exception.Message);
                    }
                    else if (writeTask.IsCompleted)
                    {
                        Debug.Log("QuestManager: Default quest data was successfully set up!");
                        _questUi.FadeScreenOut();
                    }

                    _dismissLoading.Raise();
                    Debug.Log("Default info screen");
                    _questUi.ShowInfoPanel("Welcome to the DevFest Quest Adventure!",
                                           "It's a Quest, where you will have to complete different tasks related to the conference and Google technologies knowledge.\n\nNote: accomplish all tasks as fast as possible to win a greater award!",
                                           0);
                });
            }
            else
            {
                if (readTask.IsFaulted)
                {
                    Debug.LogError("QuestManager: Failed to retrieve quest data from firebase realtime database!");
                    Debug.LogError("Error message: " + readTask.Exception.Message);

                    _questUi.FadeScreenOut();
                }
                else if (readTask.IsCompleted)
                {
                    // retrieve user quest progress
                    var snapshot  = readTask.Result;
                    QuestProgress = JsonConvert.DeserializeObject <QuestProgress>(snapshot.GetRawJsonValue());

                    Debug.Log("QuestManager: Quest data was successfully set up!");
                    _questUi.FadeScreenOut();

                    Debug.Log("Updating Info screen");
                    if (QuestProgress.allRiddlesCompleted)
                    {
                        _questUi.ShowUserScorePanel();
                    }
                    else
                    {
                        Debug.Log("Default info screen");
                        _questUi.ShowInfoPanel("Welcome to the DevFest\nQuest Adventure!",
                                               "It's a Quest, where you will have to complete different tasks related to the conference and Google technologies knowledge.\n\nNote: accomplish all tasks as fast as possible to win a greater award!",
                                               0);
                    }
                }
                _dismissLoading.Raise();
            }

            //Check if Quest is activated
            CheckIfQuestIsActivated();
            ReadRiddleDataFromQuestProgress();
            UpdateUserScoreInLeaderBoard(false);
        });
    }