Exemple #1
0
    // -- Response Parsing

    void ParseScoreoidJSON(string theJSONString, string url)
    {
        var N = JSON.Parse(theJSONString);

        string errorString = N["error"];

        if (null != errorString)
        {
            Debug.Log(string.Format("Scoreoid Error: {0}", N["error"]));
            Utilities().RequestFailed(N["error"]);
        }
        else
        {
            string command = url.Replace(API_URL_BASE, "");

            switch (command)
            {
            case "editPlayer":
                Utilities().UpdatedPlayerSuccessfully();
                break;

            case "createPlayer":
                Utilities().PlayerRegistered();
                break;

            case "getPlayer":
                // Parse the player into the ScoreoidPlayer.
                ScoreoidPlayer player =
                    new ScoreoidPlayer(N[0]["Player"]["username"],
                                       N[0]["Player"]["money"].AsFloat,
                                       N[0]["Player"]["kills"].AsInt,
                                       N[0]["Player"]["inventory"],
                                       N[0]["Player"]["current_level"].AsInt,
                                       N[0]["Player"]["xp"].AsFloat /*,
                                                                     * N[0]["Player"]["unique_id"]*/);

                // Set the player
                Utilities().PlayerLoggedIn(player);
                break;

            default:
                Debug.Log(string.Format("Unhandled command: {0}", command));
                break;
            }
        }
    }
    // -- Response Parsing
    void ParseScoreoidJSON(string theJSONString, string url)
    {
        var N = JSON.Parse(theJSONString);

        string errorString = N["error"];
        if(null != errorString)
        {
            Debug.Log(string.Format("Scoreoid Error: {0}", N["error"]));
            Utilities().RequestFailed(N["error"]);
        }
        else
        {
            string command = url.Replace(API_URL_BASE, "");

            switch(command)
            {
            case "editPlayer":
                Utilities().UpdatedPlayerSuccessfully();
                break;
            case "createPlayer":
                Utilities().PlayerRegistered();
                break;
            case "getPlayer":
                // Parse the player into the ScoreoidPlayer.
                ScoreoidPlayer player =
                    new ScoreoidPlayer( N[0]["Player"]["username"],
                                     	N[0]["Player"]["money"].AsFloat,
                                        N[0]["Player"]["kills"].AsInt,
                                        N[0]["Player"]["inventory"],
                                        N[0]["Player"]["current_level"].AsInt,
                                        N[0]["Player"]["xp"].AsFloat/*,
                                        N[0]["Player"]["unique_id"]*/);

                // Set the player
                Utilities().PlayerLoggedIn(player);
                break;
            default:
                Debug.Log(string.Format("Unhandled command: {0}", command));
                break;
            }
        }
    }