Ejemplo n.º 1
0
 /// <summary>
 /// Firebaseインスタンスを指定して初期化
 /// </summary>
 /// <param name="service"></param>
 public RankingBoard(FirebaseService service)
 {
     this.service = service;
 }
Ejemplo n.º 2
0
        private void Start()
        {
            service = new FirebaseService();
            ranking = new RankingBoard(service);

            //  サインインの実行
            signInButton.onClick.AddListener(() =>
            {
                if (service.IsSignedIn())
                {
                    return;
                }
                service.SignInAnonymouslyAsync().ContinueWith(task =>
                {
                    if (!task.IsFaulted)
                    {
                        //  成功時
                        Debug.Log("Authentication completed");
                        Debug.Log("uid : " + task.Result.UserId);
                    }
                    else
                    {
                        //  失敗時
                        Debug.LogException(task.Exception);
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            });

            //  スコアの登録
            registerButton.onClick.AddListener(() =>
            {
                ranking.AddEntry(
                    entry: new RankingEntry(nameField.text, int.Parse(scoreField.text)),
                    onComplete: () =>
                {
                    //  成功時
                    Debug.Log("registered");
                },
                    onError: (exception) =>
                {
                    //  失敗時
                    Debug.LogException(exception);
                });
            });

            //  ランキングの取得
            fetchButton.onClick.AddListener(() =>
            {
                ranking.UpdateEntries(
                    onComplete: () =>
                {
                    //  成功時
                    ranking.Entries.ForEach(e => Debug.Log(e.ToString()));
                    rankingPanel.SetRanking(ranking);
                },
                    onError: (exception) =>
                {
                    //  失敗時
                    Debug.LogException(exception);
                });
            });
        }