コード例 #1
0
        private void addClickListeners()
        {
            btnLogin.onClick.AddListener(() => {
                string username = ifUsername.text;
                string password = ifPassword.text;
                BacktoryUser.LoginInBackground(username, password, loginResponse =>
                {
                    if (loginResponse.Successful)
                    {
                        writeLine("logged in!");
                    }
                    else
                    {
                        writeLine("Unable to login=> " + loginResponse.Code + ":" + loginResponse.Message);
                    }
                });
            });

            btnConnect.onClick.AddListener(() => {
                Debug.Log("AccessToken: " + BacktoryUser.GetAccessToken());
                if (BacktoryUser.GetAccessToken() == null)
                {
                    writeLine("login first");
                    return;
                }
                connect();
            });

            btnDisconnect.onClick.AddListener(() => {
                BacktoryResponse <BacktoryVoid> response = backtoryApi.Disconnect();
                if (response.Successful)
                {
                    writeLine("---disconnect successful");
                }
                else
                {
                    writeLine("---disconnect failed with code: " + response.Code + " and message " + response.Message);
                }
            });

            btnMatchmaking.onClick.AddListener(() => {
                BacktoryResponse <MatchmakingResponse> response = backtoryApi.RequestMatchmaking(matchmakingName, 55, "sample meta data");
                if (response.Successful)
                {
                    lastMatchmakingRequestId = response.Body.RequestId;
                    writeLine("---matchmaking successful. id: " + lastMatchmakingRequestId);
                }
                else
                {
                    writeLine("---matchmaking failed with code: " + response.Code + " and message " + response.Message);
                }
            });

            btnCancelMM.onClick.AddListener(() => {
                BacktoryResponse <BacktoryVoid> response = backtoryApi.CancelMatchmaking(matchmakingName, lastMatchmakingRequestId);
                if (response.Successful)
                {
                    writeLine("---matchmaking cancelled successful.");
                }
                else
                {
                    writeLine("---matchmaking cancellation failed with code: " + response.Code + " and message " + response.Message);
                }
            });

            btnChallenge.onClick.AddListener(() => {
                List <String> users = new List <String> ();
                users.Add("5720b016e4b0bf11f90cdee6");  // ali
                users.Add("5720b01be4b0bf11f90cdee7");  // mamad
                users.Add("5720b01ee4b0bf11f90cdee8");  // farib
                BacktoryResponse <ChallengeResponse> response = backtoryApi.RequestChallenge(users, 15, 2);
                if (response.Successful)
                {
                    writeLine("---challenge request successful. challenge id: " + response.Body.ChallengeId);
                }
                else
                {
                    writeLine("---challenge request failed with code: " + response.Code + " and message " + response.Message);
                }
            });

            btnChallengeList.onClick.AddListener(() => {
                BacktoryResponse <ActiveChallengesListResponse> response = backtoryApi.RequestListOfActiveChallenges();
                if (response.Successful)
                {
                    writeLine("---active challenges list json: " + Backtory.ToJson((response.Body), true));
                }
                else
                {
                    writeLine("---active challenges list failed with code: " + response.Code + " and message " + response.Message);
                }
            });

            btnAccept.onClick.AddListener(() => {
                BacktoryResponse <BacktoryVoid> response = backtoryApi.AcceptChallenge(lastChallengeInvitationId);
                if (response.Successful)
                {
                    writeLine("---challenge accepted successful.");
                }
                else
                {
                    writeLine("---accepting challenge failed with code: " + response.Code + " and message " + response.Message);
                }
            });

            btnDecline.onClick.AddListener(() => {
                BacktoryResponse <BacktoryVoid> response = backtoryApi.DeclineChallenge(lastChallengeInvitationId);
                if (response.Successful)
                {
                    writeLine("---challenge declined successful.");
                }
                else
                {
                    writeLine("---declining challenge failed with code: " + response.Code + " and message " + response.Message);
                }
            });

            btnChat.onClick.AddListener(() => SceneManager.LoadScene("ChatScene"));
        }