Beispiel #1
0
    /// <summary>
    /// 添加房间
    /// </summary>
    /// <param name="groupId"></param>
    /// <param name="entity"></param>
    public void AddRoom(int groupId, RoomEntityBase entity, List <int> lstPlayerId)
    {
        ChatGroupEntity group = GetGroup(groupId);

        if (group == null)
        {
            return;
        }
        if (entity == null)
        {
            return;
        }
        if (GetRoom(groupId, entity.gameId) != null)
        {
            AppDebug.LogWarning("房间存在了");
            return;
        }
        AppDebug.Log("有一个新的房间");
        if (lstPlayerId != null)
        {
            for (int i = 0; i < lstPlayerId.Count; ++i)
            {
                bool isExists = false;
                for (int j = 0; j < group.members.Count; ++j)
                {
                    if (lstPlayerId[i] == group.members[j].id)
                    {
                        entity.players.Add(group.members[j]);
                        isExists = true;
                        break;
                    }
                }
                if (!isExists)
                {
                    entity.players.Add(null);
                }
            }
        }
        group.rooms.Add(entity);
        group.roomCount = group.rooms.Count;

        TransferData data = new TransferData();

        data.SetValue("GroupEntity", group);
        data.SetValue("RoomEntity", entity);
        SendNotification(ON_ADD_ROOM, data);

        SendGroupInfoChangedNotification(group);
    }
Beispiel #2
0
    /// <summary>
    /// 添加房间
    /// </summary>
    /// <param name="obj"></param>
    private void OnAddRoom(TransferData data)
    {
        ChatGroupEntity group = data.GetValue <ChatGroupEntity>("GroupEntity");

        if (group.id != m_GroupId)
        {
            return;
        }

        RoomEntityBase roomEntity       = data.GetValue <RoomEntityBase>("RoomEntity");
        UIItemChatRoom item             = UIPoolManager.Instance.Spawn("UIItemChatRoom").GetComponent <UIItemChatRoom>();
        List <UIItemChatRoomPlayer> lst = new List <UIItemChatRoomPlayer>();

        for (int j = 0; j < roomEntity.players.Count; ++j)
        {
            PlayerEntity         playerEntity = roomEntity.players[j];
            UIItemChatRoomPlayer itemPlayer   = UIPoolManager.Instance.Spawn("UIItemChatRoomPlayer").GetComponent <UIItemChatRoomPlayer>();
            if (playerEntity == null)
            {
                itemPlayer.SetUI(group.id, roomEntity.roomId, 0, string.Empty, false);
            }
            else
            {
                itemPlayer.SetUI(group.id, roomEntity.roomId, playerEntity.id, playerEntity.avatar, group.isOwner);
            }
            lst.Add(itemPlayer);
            m_RoomPlayerList.Add(itemPlayer);
        }
        item.SetUI(group.id, roomEntity.roomId, roomEntity.roomStatus == RoomEntityBase.RoomStatus.Gaming, roomEntity.GameName);
        item.SetPlayer(lst);
        item.gameObject.SetParent(m_RoomContainer, true);
        m_RoomList.Add(item);
        if (roomEntity.roomStatus == RoomEntityBase.RoomStatus.Gaming)
        {
            m_TxtGamingRoomCount.SafeSetText((m_TxtGamingRoomCount.text.ToInt() + 1).ToString());
        }
        else if (roomEntity.roomStatus == RoomEntityBase.RoomStatus.Waiting)
        {
            m_TxtWaitingRoomCount.SafeSetText((m_TxtWaitingRoomCount.text.ToInt() + 1).ToString());
        }
    }
Beispiel #3
0
    /// <summary>
    /// 进入房间
    /// </summary>
    /// <param name="groupId"></param>
    /// <param name="roomId"></param>
    /// <param name="playerId"></param>
    public void EnterRoom(int groupId, int roomId, int playerId)
    {
        ChatGroupEntity group = GetGroup(groupId);

        if (group == null)
        {
            return;
        }
        RoomEntityBase room = GetRoom(groupId, roomId);

        if (room == null)
        {
            return;
        }
        PlayerEntity player = GetMember(groupId, playerId);

        if (player == null)
        {
            return;
        }
        Debug.Log("玩家" + player.nickname + "进入房间" + room.roomId);
        for (int i = 0; i < room.players.Count; ++i)
        {
            if (room.players[i] == null)
            {
                room.players[i] = player;
                break;
            }
        }

        TransferData data = new TransferData();

        data.SetValue("GroupEntity", group);
        data.SetValue("RoomId", roomId);
        data.SetValue("PlayerEntity", player);
        SendNotification(ON_ENTER_ROOM, data);
    }
Beispiel #4
0
    /// <summary>
    /// 房间信息变更
    /// </summary>
    /// <param name="obj"></param>
    private void OnRoomInfoChanged(TransferData data)
    {
        ChatGroupEntity group = data.GetValue <ChatGroupEntity>("GroupEntity");

        if (group == null)
        {
            return;
        }
        RoomEntityBase room = data.GetValue <RoomEntityBase>("RoomEntity");

        if (room == null)
        {
            return;
        }

        for (int i = 0; i < m_RoomList.Count; ++i)
        {
            if (m_RoomList[i].RoomId == room.roomId)
            {
                m_RoomList[i].SetUI(group.id, room.roomId, room.roomStatus == RoomEntityBase.RoomStatus.Gaming, room.GameName);
                break;
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// 离开房间
    /// </summary>
    /// <param name="groupId"></param>
    /// <param name="roomId"></param>
    /// <param name="playerId"></param>
    public void LeaveRoom(int groupId, int roomId, int playerId)
    {
        RoomEntityBase room = GetRoom(groupId, roomId);

        if (room == null)
        {
            return;
        }
        PlayerEntity player = GetMember(groupId, playerId);

        if (player == null)
        {
            return;
        }
        Debug.Log("玩家" + playerId.ToString() + "离开房间" + roomId.ToString());
        for (int i = 0; i < room.players.Count; ++i)
        {
            if (room.players[i] == null)
            {
                continue;
            }

            if (room.players[i].id == playerId)
            {
                room.players[i] = null;
                break;
            }
        }

        TransferData data = new TransferData();

        data.SetValue("GroupId", groupId);
        data.SetValue("RoomId", roomId);
        data.SetValue("PlayerId", playerId);
        SendNotification(ON_LEAVE_ROOM, data);
    }
Beispiel #6
0
    /// <summary>
    /// 更新房间信息
    /// </summary>
    public void UpdateRoom(int groupId, int roomId, int loop, RoomEntityBase.RoomStatus status)
    {
        ChatGroupEntity group = GetGroup(groupId);

        if (group == null)
        {
            return;
        }
        RoomEntityBase room = GetRoom(groupId, roomId);

        if (room == null)
        {
            return;
        }
        room.currentLoop = loop;
        room.roomStatus  = status;

        TransferData data = new TransferData();

        data.SetValue("GroupEntity", group);
        data.SetValue("RoomEntity", room);
        SendNotification(ON_ROOM_INFO_CHANGED, data);
        SendGroupInfoChangedNotification(group);
    }