コード例 #1
0
    // Use this for initialization
    void Start()
    {
        webApi = new WebApi();

        IWebApiResponse loginApiResponse = webApi.Login(PlayerPrefs.GetString("email"), PlayerPrefs.GetString("password"));

        if (loginApiResponse is ErrorResponse)
        {
            PushMessage((loginApiResponse as ErrorResponse).displayError, 5);
        }
        else
        {
            loginResponse = loginApiResponse as LoginResponse;
        }

        if (loginResponse != null)
        {
            IWebApiResponse tapsResponse = webApi.GetResponseObject <TapsResponse>("tapthat/taps", "POST", null, new Dictionary <string, string>()
            {
                { "authToken", loginResponse.authToken }
            });

            if (tapsResponse is ErrorResponse)
            {
                PushMessage((tapsResponse as ErrorResponse).displayError, 5);
            }
            else
            {
                TapsResponse leaderboardResponse = tapsResponse as TapsResponse;
                int          totalTaps           = leaderboardResponse.totalTaps;

                string msg = string.Format("Welcome back {0}, {1} bubble taps from before added", loginResponse.name, totalTaps);

                PushMessage(msg, 5);
                tapCount = totalTaps;
            }
            StartCoroutine("UpdateTaps");
        }
    }
コード例 #2
0
    private IEnumerable UpdateTaps()
    {
        if (loginResponse != null)
        {
            Debug.Log("sending delta " + tapDelta);

            Dictionary <string, string> args = new Dictionary <string, string>()
            {
                { "authToken", loginResponse.authToken },
                { "delta", tapDelta.ToString() }
            };
            tapDelta = 0;

            IWebApiResponse tapsResponse = webApi.GetResponseObject <TapsResponse>("tapthat/taps", "POST", null, args);


            if (tapsResponse is ErrorResponse)
            {
                PushMessage((tapsResponse as ErrorResponse).displayError, 5);
            }
            else
            {
                TapsResponse leaderboardResponse = tapsResponse as TapsResponse;

                LeaderboardResponse nextRank     = null;
                LeaderboardResponse previousRank = null;
                if (leaderboardResponse.rank != 0)
                {
                    foreach (LeaderboardResponse nearRank in leaderboardResponse.leaderboard)
                    {
                        if (nextRank != null && previousRank != null)
                        {
                            break;
                        }

                        if (nearRank.rank == leaderboardResponse.rank - 1)
                        {
                            nextRank = nearRank;
                            continue;
                        }
                        else if (nearRank.rank == leaderboardResponse.rank + 1)
                        {
                            previousRank = nearRank;
                            continue;
                        }
                    }
                }

                if (nextRank == null)
                {
                    nextRankLabel.enabled = false;
                }
                else
                {
                    nextRankLabel.enabled = true;
                    nextRankLabel.text    = nextRank.name + ": " + nextRank.totalTaps;
                }

                if (previousRank == null)
                {
                    previousRankLabel.enabled = false;
                }
                else
                {
                    previousRankLabel.enabled = true;
                    previousRankLabel.text    = previousRank.name + ": " + previousRank.totalTaps;
                }
            }
        }

        yield return(new WaitForSeconds(leaderboardDelay));

        StartCoroutine("UpdateTaps");
    }