示例#1
0
    /// <summary>
    /// Processes the network client or connId message.
    /// </summary>
    /// <param name="netMsg">Net message.</param>
    public void ProcessNetworkClientMessage(Dictionary <string, object> netMsg)
    {
        // Get the type from the object
        NetworkMessages.MessageTypes type = (NetworkMessages.MessageTypes)System.Enum.Parse(typeof(NetworkMessages.MessageTypes), netMsg ["type"].ToString());

        Debug.Log(string.Format("Client Message: {0}", type));

        switch (type)
        {
        case NetworkMessages.MessageTypes.SERVER_DISCONNECT:
            Debug.LogError("The Server has disconnected");
            GameObject.FindObjectOfType <LobbyManager> ().ResetLobby();
            break;

        case NetworkMessages.MessageTypes.ADD_USERNAME:
            RunOnMainThread(() => {
                GameObject.FindObjectOfType <LobbyManager> ().AddUserToChat(netMsg["username"].ToString());
            });
            break;

        default:
            Debug.LogError(string.Format("Unknown MessageType: {0}", type));
            break;
        }
    }
示例#2
0
    /// <summary>
    /// Processes the network server message.
    /// </summary>
    /// <param name="netMsg">Net message.</param>
    public void ProcessNetworkServerMessage(Dictionary <string, object> netMsg)
    {
        // Get the type from the object
        NetworkMessages.MessageTypes type = (NetworkMessages.MessageTypes)System.Enum.Parse(typeof(NetworkMessages.MessageTypes), netMsg ["type"].ToString());

        Debug.Log(string.Format("Server Message: {0}", type));

        switch (type)
        {
        case NetworkMessages.MessageTypes.JOIN_GAME:
            Debug.Log(string.Format("connId: {0} has joined the game", netMsg["connId"].ToString()));
            break;

        default:
            Debug.LogError(string.Format("Unknown MessageType: {0}", type));
            break;
        }
    }