示例#1
0
    private void OnChannelMessageReceived(string channelName, string[] senders, object[] messages)
    {
        if (channelName != _roomId)
        {
            return;
        }

        foreach (string sender in senders)
        {
            if (sender == ServiceManager.PlayerManager.LocalPlayerProfile.Uid)
            {
                continue;
            }

            ChatManager.PlayerInfoMessage playerInfo = ChatManager.GetLatestMessage <ChatManager.PlayerInfoMessage>(sender, senders, messages);
            if (playerInfo != null && !_playerWidgets.ContainsKey(sender))
            {
                // Create player item with info
                PlayerDisplayWidget newWidget = Instantiate(_displayWidget, _playerScroll.content.transform);
                newWidget.Initialize(playerInfo.PlayerName);
                _playerWidgets.Add(sender, newWidget);
                _playerCount++;
                _playerCountText.SetText($"{_playerCount}/{PhotonNetwork.CurrentRoom.MaxPlayers}");
            }
        }
    }
示例#2
0
    private void Update()
    {
        if (string.IsNullOrEmpty(_roomId) && PhotonNetwork.InRoom)
        {
            _roomId = PhotonNetwork.CurrentRoom.Name;
            _roomName.SetText(PhotonNetwork.CurrentRoom.CustomProperties[RoomManager.RoomNameKey] as string);
            _chatManger.Subscribe(_roomId);
            _chatManger.SendChannelMessage(_roomId, new ChatManager.PlayerInfoMessage()
            {
                PlayerName = ServiceManager.PlayerManager.LocalPlayerProfile.PlayerName
            });

            PlayerDisplayWidget newWidget = Instantiate(_displayWidget, _playerScroll.content.transform);
            newWidget.Initialize(ServiceManager.PlayerManager.LocalPlayerProfile.PlayerName);
            _playerWidgets.Add(ServiceManager.PlayerManager.LocalPlayerProfile.Uid, newWidget);
            _playerCount++;
            _playerCountText.SetText($"{_playerCount}/{PhotonNetwork.CurrentRoom.MaxPlayers}");
        }
    }