예제 #1
0
    public void RequestFullGameState()
    {
        if (!IsFullGameStateRequestPending)
        {
            AsyncJSONRequest            fullGameStateRequest = AsyncJSONRequest.Create(m_gameWorldController.gameObject);
            Dictionary <string, object> request = new Dictionary <string, object>();

            request["character_id"] = SessionData.GetInstance().CharacterID;

            IsFullGameStateRequestPending = true;

            fullGameStateRequest.POST(
                ServerConstants.fullGameStateRequestURL,
                request,
                (AsyncJSONRequest asyncRequest) =>
            {
                if (asyncRequest.GetRequestState() == AsyncJSONRequest.eRequestState.succeded)
                {
                    JsonData response     = asyncRequest.GetResult();
                    string responseResult = (string)response["result"];

                    if (responseResult == "Success")
                    {
                        GameData currentGameData = SessionData.GetInstance().CurrentGameData;

                        // Parse the full world state into the session data
                        currentGameData.ParseFullGameStateResponse(response);

                        Debug.Log("Game State Loaded");
                        m_gameWorldController.OnGameLoaded();
                    }
                    else
                    {
                        Debug.LogError("Game State Request Failed: " + responseResult);
                        m_gameWorldController.OnRequestFailed(responseResult);
                    }
                }
                else
                {
                    Debug.LogError("Game State Request Failed: " + asyncRequest.GetFailureReason());
                    m_gameWorldController.OnRequestFailed("Connection Failed!");
                }

                IsFullGameStateRequestPending = false;
            });
        }
    }