Ejemplo n.º 1
0
    public void GetUserHighScoreProfilePicture(UserHighScore userHighScore, int?width = null, int?height = null, string type = null)
    {
        string path = Path.Combine(Application.persistentDataPath, userHighScore.UserId + "_ProfilePicture.png");

        if (File.Exists(path) && DateTime.Now - File.GetLastWriteTime(path) < TimeSpan.FromDays(this.DaysToKeepProfilePicture))
        {
            userHighScore.ProfilePicture = TextureIo.ReadTextureFromFile(
                path, width ?? userHighScore.ProfilePicture.width, height ?? userHighScore.ProfilePicture.height);
        }
        else
        {
            string url = this.GetPictureURL(userHighScore.UserId, width, height, type);
            FB.API(
                url,
                HttpMethod.GET,
                result =>
            {
                if (result.Error != null)
                {
                    FbDebug.Error(result.Error);

                    return;
                }

                userHighScore.ProfilePicture = result.Texture;
                TextureIo.SaveTextureToFile(path, userHighScore.ProfilePicture);
            });
        }
    }
Ejemplo n.º 2
0
    private List <UserHighScore> DeserializeHighScores(string response)
    {
        Dictionary <string, object> responseObject = Json.Deserialize(response) as Dictionary <string, object>;
        List <UserHighScore>        highScores     = new List <UserHighScore>();

        if (responseObject != null)
        {
            object val;

            if (responseObject.TryGetValue("data", out val))
            {
                List <object> userList = (List <object>)val;

                foreach (object userListObject in userList)
                {
                    UserHighScore userHighScore            = new UserHighScore();
                    Dictionary <string, object> dataObject = userListObject as Dictionary <string, object>;

                    if (dataObject != null)
                    {
                        if (dataObject.TryGetValue("user", out val))
                        {
                            Dictionary <string, object> userObject = val as Dictionary <string, object>;

                            if (userObject != null)
                            {
                                if (userObject.TryGetValue("id", out val))
                                {
                                    userHighScore.UserId = (string)val;
                                }

                                if (userObject.TryGetValue("name", out val))
                                {
                                    userHighScore.Name = (string)val;
                                }
                            }
                        }

                        if (dataObject.TryGetValue("score", out val))
                        {
                            long highScore = (long)val;
                            userHighScore.HighScore = (uint)highScore;
                        }
                    }

                    highScores.Add(userHighScore);
                }
            }
        }

        return(highScores);
    }
Ejemplo n.º 3
0
    public void GetHighScores()
    {
        string scoresQuery = string.Format("/{0}/scores", FB.AppId);

        if (this.IsLoggedIn)
        {
            FB.API(
                scoresQuery,
                HttpMethod.GET,
                result =>
            {
                if (result.Error != null)
                {
                    FbDebug.Error(result.Error);

                    return;
                }

                FbDebug.Log("Result: " + result.Text);
                Debug.Log("Facebook get scores result: " + result.Text);

                this.HighScores = this.DeserializeHighScores(result.Text);

                foreach (UserHighScore userHighScore in this.HighScores)
                {
                    Debug.Log("Facebook high scores result: " + userHighScore.ToString());
                    this.GetUserHighScoreProfilePicture(userHighScore, 128, 128);

                    if (userHighScore.UserId == FB.UserId)
                    {
                        this.MyHighScore = userHighScore;
                    }
                }
            });
        }
    }