Beispiel #1
0
    private void SendMessage()
    {
        string txtMsg = _chatInput.text;

        _chatInput.text = string.Empty;

        ServerModel.Message message = new ServerModel.Message()
        {
            name = GeneralDataManager.it.currentUser.name, message = txtMsg
        };
        NetworkManager.it.Emit(ServerMethod.SEND_MESSAGE, message.ToJSON());
    }
Beispiel #2
0
    private void Start()
    {
        RefreshUserList();

        NetworkManager.it.AddEventCallback(ServerMethod.RECEIVE_MESSAGE,
                                           (data) =>
        {
            if (_messageList.Count > 10)
            {
                _messageList.RemoveAt(0);
            }

            ServerModel.Message message = JsonUtility.FromJson <ServerModel.Message>(data);
            _messageList.Add(message);
            RefreshChatRoom();
        });

        NetworkManager.it.AddEventCallback(ServerMethod.OTHER_USER_CONNECT,
                                           (data) =>
        {
            var userDic = GeneralDataManager.it.userDictionary;
            var user    = JsonUtility.FromJson <ServerModel.User>(data);
            if (!userDic.ContainsKey(user.name))
            {
                userDic.Add(user.name, user);
            }
            RefreshUserList();
        });

        NetworkManager.it.AddEventCallback(ServerMethod.OTHER_USER_DISCONNECT,
                                           (data) =>
        {
            var userDic = GeneralDataManager.it.userDictionary;
            var user    = JsonUtility.FromJson <ServerModel.User>(data);
            if (userDic.ContainsKey(user.name))
            {
                userDic.Remove(user.name);
            }
            RefreshUserList();
        });
    }