コード例 #1
0
    public void OnClientMessage(UnityEngine.Networking.NetworkMessage netMsg)
    {
        NetworkInstanceVars json = JsonUtility.FromJson <NetworkInstanceVars>(netMsg.reader.ReadString());

        switch (json.messageType)
        {
        case "winner":
            Debug.Log("Server Message type: winner: " + serverPlayerList[netMsg.conn.address]);
            int objective = Random.Range(0, objectiveCount - 1);
            sendWinnerMessageToClient(netMsg.conn.address, objective);

            //Next round, update scores
            serverScoreList[netMsg.conn.address]++;
            Debug.Log("Scoreboard");
            foreach (KeyValuePair <string, int> score in serverScoreList)
            {
                Debug.Log(score.Key + ": " + score.Value + "point(s)");
            }

            round++;
            if (round > roundLimit)
            {
                //Game end message to clients
                Debug.Log("game end");
                sendEndMessageToClient();
            }
            Debug.Log(scoreboardToString(serverScoreList));
            Debug.Log("Round end: " + round + "/" + roundLimit);
            break;

        case "name":
            Debug.Log("Server Message type: name: " + json.name);
            serverPlayerList[netMsg.conn.address] = json.name;
            if (!clientManager.getClientPlayerList().Contains(json.name))
            {
                clientManager.addToClientPlayerList(json.name);
            }
            syncPlayerLists();
            break;

        default:
            Debug.Log("unknown message from client type: " + json.messageType);
            break;
        }
    }
コード例 #2
0
    public void OnServerMessage(UnityEngine.Networking.NetworkMessage netMsg)
    {
        NetworkInstanceVars json = JsonUtility.FromJson <NetworkInstanceVars>(netMsg.reader.ReadString());

        switch (json.messageType)
        {
        case "start":
            Debug.Log("Client Message type: start");
            SceneManager.LoadScene("mainScene");
            objective = json.objective;
            round.startRound(objective);
            break;

        case "player list":
            Debug.Log("Client Message type: player list");
            clientPlayerList = new List <string>(json.playerListName);
            uiManager.updatePlayerListUI(clientPlayerList);
            break;

        case "winner":
            Debug.Log("Client Message type: winner: " + json.name);

            //winner panel show subroutine
            StartCoroutine(uiManager.showWinnerPanel(json.name));
            StartCoroutine(round.disableSelection());
            objective = json.objective;
            round.startRound(objective);
            Debug.Log("objective: " + objective);
            break;

        case "end":
            Debug.Log("game end");
            SceneManager.LoadScene("VictoryScene");
            uiManager.setVictoryMessage(json.name);
            break;

        default:
            Debug.Log("unknown message from server type: " + json.messageType);
            break;
        }
    }