Exemple #1
0
        /// <summary>
        /// Called once per frame.
        /// LeaderboardController's initialization and events are queued in its Database callback
        /// methods and then triggered in Update, because Firebase Database uses asynchronous
        /// threads in "ContinueWith" when results are retrieved, but many Unity functions such
        /// as modifying UI elements can only be called from the main thread.
        /// </summary>
        private void Update()
        {
            if (!initialized)
            {
                if (readyToInitialize)
                {
                    FirebaseApp app = FirebaseApp.DefaultInstance;
                    if (EditorAuth)
                    {
                        app.SetEditorP12FileName(EditorP12FileName);
                        app.SetEditorServiceAccountEmail(EditorServiceAccountEmail);
                        app.SetEditorP12Password(EditorP12Password);
                    }

                    if (app.Options.DatabaseUrl != null)
                    {
                        app.SetEditorDatabaseUrl(app.Options.DatabaseUrl);
                    }

                    dbref       = FirebaseDatabase.DefaultInstance.RootReference;
                    initialized = true;
                    RefreshScores();
                    readyToInitialize = false;
                    if (FirebaseInitialized != null)
                    {
                        FirebaseInitialized(this, null);
                    }
                }
                return;
            }
            if (refreshScores)
            {
                RefreshScores();
                return;
            }
            if (sendScoreAddedEvent)
            {
                sendScoreAddedEvent = false;
                if (ScoreAdded != null)
                {
                    ScoreAdded(this, userScoreArgs);
                }
                return;
            }
            if (sendUserScoreEvent)
            {
                sendUserScoreEvent = false;
                if (UserScoreUpdated != null)
                {
                    UserScoreUpdated(this, userScoreArgs);
                }
                return;
            }
            if (sendUpdateTopScoresEvent)
            {
                sendUpdateTopScoresEvent = false;
                if (TopScoresUpdated != null)
                {
                    TopScoresUpdated(this, new TopScoreArgs {
                        TopScores = TopScores,
                        StartDate = StartDate,
                        EndDate   = EndDate
                    });
                }
                return;
            }
        }