/// <summary> /// 他人进入房间广播 /// </summary> /// <param name="socketMsg"></param> private void EnterBroadcastResult(SocketMsg socketMsg) { if ((MatchCode)socketMsg.State == MatchCode.Success) { var newUser = socketMsg.value as UserCharacterDto; //更新房间数据 MatchRoomDto room = Data.GameData.MatchRoomDto; room.UIdClientDict.Add(newUser.Id, newUser); room.UIdList.Add(newUser.Id); ResetPosition(); //给UI绑定数据 if (room.LeftId != -1) { UserCharacterDto leftUserDto = room.UIdClientDict[room.LeftId]; Dispatch(AreaCode.UI, UIEvent.Set_Left_Player_Data, leftUserDto); } if (room.RightId != -1) { UserCharacterDto rightUserDto = room.UIdClientDict[room.RightId]; Dispatch(AreaCode.UI, UIEvent.Set_Right_Player_Data, rightUserDto); } //发消息 显示玩家的状态面板所有游戏物体 Dispatch(AreaCode.UI, UIEvent.Player_Enter, newUser.Id); //给用户一个提示 promptMsg.Text = "有新玩家 ( " + newUser.Name + " )进入"; Dispatch(AreaCode.UI, UIEvent.Prompt_Msg, promptMsg); } }
/// <summary> /// 刷新视图 /// </summary> void RefreshView(UserCharacterDto info) { txt_Name.text = info.Name; txt_Lv.text = "Lv." + info.Lv; //等级和经验的公式:maxExp=lv*100 txt_Exp.text = info.Exp + " / " + info.Lv * 100; txt_Beem.text = "x " + info.Been; slider.value = info.Exp / info.Lv * 100; }
public override void Execute(int eventCode, object message) { switch (eventCode) { case UIEvent.Refresh_Info_Panel: UserCharacterDto userCharacter = message as UserCharacterDto; RefreshView(userCharacter); break; } }
/// <summary> /// 进入房间广播 /// </summary> /// <param name="socketMsg"></param> private void EnterBroadcastResult(SocketMsg socketMsg) { if ((MatchCode)socketMsg.State == MatchCode.Success) { //更新房间数据 UserCharacterDto user = socketMsg.value as UserCharacterDto; Data.GameData.MatchRoomDto.UIdClientDict.Add(user.Id, user); //房间信息提示 promptMsg.Text = "有新的玩家(" + user.Name + ")进入房间"; Dispatch(AreaCode.UI, UIEvent.Prompt_Msg, promptMsg); //更新ui // TODO } }
private MatchRoomDto MakeRoomDto(MatchRoom room) { MatchRoomDto dto = new MatchRoomDto(); //给 UIdClientDict 赋值 foreach (var uId in room.UIdClientDict.Keys) { var info = userCache.GetUserInfo(uId); UserCharacterDto userCharacter = EntityHelper.Mapping <UserCharacterDto, UserCharacterInfo>(info); dto.UIdClientDict.Add(uId, userCharacter); dto.UIdList.Add(uId); } dto.ReadyUIdList = room.ReadyUIdList; return(dto); }
/// <summary> /// 自己进入房间广播 /// </summary> /// <param name="socketMsg"></param> private void MyEnterBroadcastResult(SocketMsg socketMsg) { if ((MatchCode)socketMsg.State == MatchCode.Success) { Data.GameData.MatchRoomDto = socketMsg.value as MatchRoomDto; ResetPosition(); MatchRoomDto room = Data.GameData.MatchRoomDto; if (room.LeftId != -1) { UserCharacterDto leftUserDto = room.UIdClientDict[room.LeftId]; Dispatch(AreaCode.UI, UIEvent.Set_Left_Player_Data, leftUserDto); } if (room.RightId != -1) { UserCharacterDto rightUserDto = room.UIdClientDict[room.RightId]; Dispatch(AreaCode.UI, UIEvent.Set_Right_Player_Data, rightUserDto); } //显示进入房间的玩家对象 Dispatch(AreaCode.UI, UIEvent.Show_EnterRoom_Button, null); } }
public override void Start() { base.Start(); socketMsg = new SocketMsg(); Bind( UIEvent.Show_Grab_Button, UIEvent.Show_Deal_Button, //UIEvent.Set_MyPlayer_Data, UIEvent.Hide_Ready_Button ); btnDeal = transform.Find("btn_Deal").GetComponent <Button>(); btnNotDeal = transform.Find("btn_NotDeal").GetComponent <Button>(); btnGrab = transform.Find("btn_Grab").GetComponent <Button>(); btnNotGrab = transform.Find("btn_NotGrab").GetComponent <Button>(); btnReady = transform.Find("btn_Ready").GetComponent <Button>(); //添加监听 btnDeal.onClick.AddListener(OnDealClick); btnNotDeal.onClick.AddListener(OnNotDealClick); btnGrab.onClick.AddListener(delegate() { OnGrabClick(true); }); btnNotGrab.onClick.AddListener(delegate() { OnGrabClick(false); }); btnReady.onClick.AddListener(OnReadyClick); // btnGrab.gameObject.SetActive(false); btnNotGrab.gameObject.SetActive(false); btnDeal.gameObject.SetActive(false); btnNotDeal.gameObject.SetActive(false); // UserCharacterDto myUserDto = Data.GameData.MatchRoomDto.UIdClientDict[Data.GameData.UserCharacterDto.Id]; this.userCharacterDto = myUserDto; }
/// <summary> /// 进入匹配 /// </summary> /// <param name="client"></param> private void Enter(ClientPeer client) { SingleExecute.Instance.Execute(() => { int userId = userCache.GetClientUserId(client); //判断是否已在匹配房间 if (matchCache.IsMatching(userId)) { socketMsg.OpCode = MsgType.Match; socketMsg.SubCode = MatchCode.EnterMatch_Result; socketMsg.State = MatchCode.Repeat_Match; client.Send(socketMsg); return; } //进入房间 MatchRoom room = matchCache.Enter(userId, client); //广播信息 socketMsg.OpCode = MsgType.Match; socketMsg.SubCode = MatchCode.EnterMatch_Broadcast_Result; socketMsg.State = MatchCode.Success; room.Brocast(socketMsg); //返回给客户端数据 MatchRoomDto roomDto = new MatchRoomDto { ReadyUIdList = room.ReadyUIdList }; foreach (var uId in room.UIdClientDict.Keys) { var info = userCache.GetUserInfo(uId); UserCharacterDto userCharacter = EntityHelper.Mapping <UserCharacterDto, UserCharacterInfo>(info); roomDto.UIdClientDict.Add(uId, userCharacter); } socketMsg.value = roomDto; client.Send(socketMsg); }); }
/// <summary> /// 获取角色信息 /// </summary> /// <param name="client"></param> private void GetCharacterInfo(ClientPeer client) { SingleExecute.Instance.Execute(() => { //判断是否在线 if (!accountCache.IsOnline(client)) { msg.OpCode = MsgType.User; msg.SubCode = UserCode.GetInfoResult; msg.State = UserCode.AccountNotOnline; client.Send(msg); return; } int id = accountCache.GetId(client); if (!userCache.IsExist(id)) { msg.OpCode = MsgType.User; msg.SubCode = UserCode.GetInfoResult; msg.State = UserCode.UserExist; client.Send(msg); return; } //角色上线 Online(client); // UserCharacterInfo user = userCache.GetUserInfo(id); UserCharacterDto userCharacter = EntityHelper.Mapping <UserCharacterDto, UserCharacterInfo>(user); msg.OpCode = MsgType.User; msg.SubCode = UserCode.GetInfoResult; msg.State = UserCode.Success; msg.value = userCharacter; client.Send(msg); }); }
public override void Execute(int eventCode, object message) { switch (eventCode) { case UIEvent.Player_Hide_State: Invoke("HideUI", 0.5f); break; case UIEvent.Player_Ready: //显示准备文本框 if (userCharacterDto == null) { break; } int userId = (int)message; if (userCharacterDto.Id == userId) { ReadyState(true); } break; case UIEvent.Player_Leave: if (userCharacterDto == null) { break; } //玩家离开隐藏面板 int leaveUserId = (int)message; if (userCharacterDto.Id == leaveUserId) { ReadyState(false); SetPanelActive(false); userCharacterDto = null; } break; case UIEvent.Player_Enter: //玩家进入房间 if (userCharacterDto == null) { break; } int enterUserId = (int)message; if (userCharacterDto.Id == enterUserId) { SetPanelActive(true); } break; case UIEvent.Player_Chat: { if (userCharacterDto == null) { break; } ChatDto chatDto = message as ChatDto; if (userCharacterDto.Id == chatDto.UserId) { var text = ConstantHelper.GetChatText(chatDto.Type); ShowChat(text); } break; } case UIEvent.Player_Change_Identity: { if (userCharacterDto == null) { break; } GrabDto dto = message as GrabDto; if (userCharacterDto.Id == dto.UserId) { SetIdentity(1); } break; } } }