public IEnumerator UpdateLoop(float updateDelay)
    {
        yield return(new WaitForSeconds(updateDelay));

        if (cManager)
        {
            switch (gameState)
            {
            case GameState.LOBBY:
                RequestKeepAlive keepAlive = new RequestKeepAlive();
                keepAlive.send();
                cManager.send(keepAlive);
                break;

            case GameState.LOADING_GAME:
                while (SceneManager.GetActiveScene().name != "Sandbox")
                {
                    yield return(null);
                }

                gameState = GameState.INGAME;
                RequestPushUpdate.init();
                ResponseHeartbeat.init();

                break;

            case GameState.INGAME:
                //Create the two request objects that will be sent to the server
                RequestHeartbeat  heartbeat  = (RequestHeartbeat)NetworkRequestTable.get(Constants.CMSG_HEARTBEAT);
                RequestPushUpdate pushUpdate = (RequestPushUpdate)NetworkRequestTable.get(Constants.CMSG_PUSHUPDATE);

                //Create the messages to be sent
                heartbeat.send();
                pushUpdate.send();

                //Send the messages
                cManager.send(heartbeat);
                cManager.send(pushUpdate);
                break;

            default:
                break;
            }
        }
        StartCoroutine(UpdateLoop(updateDelay));
    }
Example #2
0
    public IEnumerator UpdateLoop(float updateDelay)
    {
        yield return(new WaitForSeconds(updateDelay));

        if (cManager)
        {
            switch (gameState)
            {
            case GameState.LOBBY:
            // will have specific request to keep it live at this point
            // but doesn't yet...
            // todo: add getLobbies code when lobbies are implemented
            // break;
            case GameState.LOGIN:
            case GameState.MAIN_MENU:
                if (lastState == GameState.GAME)
                {
                    sceneController.FadeAndLoadScene("Main_Menu");                                  // reload menu after a game;
                }
                RequestKeepAlive keepAlive = new RequestKeepAlive();
                keepAlive.send();
                cManager.send(keepAlive);
                break;

            case GameState.GAME:
                if (lastState == GameState.MAIN_MENU)
                {
                    sceneController.FadeAndLoadScene("Game_Scene");

                    while (SceneManager.GetActiveScene().name != "Game_Scene")
                    {
                        yield return(null);
                    }

                    Constants.loadSceneAConstants();

                    setCharacterValues();

                    Debug.Log("Joined Game");
                }

                //Create the two request objects that will be sent to the server
                RequestHeartbeat  heartbeat  = (RequestHeartbeat)NetworkRequestTable.get(Constants.CMSG_HEARTBEAT);
                RequestPushUpdate pushUpdate = (RequestPushUpdate)NetworkRequestTable.get(Constants.CMSG_PUSHUPDATE);

                //Create the messages to be sent
                heartbeat.send();
                pushUpdate.send();

                //Send the messages
                cManager.send(heartbeat);
                cManager.send(pushUpdate);

                break;

            default:
                break;
            }

            lastState = gameState;
        }
        StartCoroutine(UpdateLoop(updateDelay));
    }