/// <summary> /// 点击离开房间后处理服务器返回的消息 /// </summary> /// <param name="msg">服务器返回的离开房间消息</param> private void LeaveRoomHandle(object msg) { var leaveRoomMsg = msg as mmopb.leaveRoom_ack; if (leaveRoomMsg.isSuc) { //打开房间列表 roomsView.rooms.SetActive(true); //关闭进入的房间 roomView.room_boot.SetActive(false); //删除原来有的列表 GameObject[] rooms = GameObject.FindGameObjectsWithTag("ROOM"); foreach (GameObject room in rooms) { Destroy(room); } //删除聊天消息 GameObject[] messages = GameObject.FindGameObjectsWithTag("ROOMMSG"); foreach (GameObject message in messages) { Destroy(message); } //请求房间列表数据 var rooms_req = new mmopb.roomList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(rooms_req)); } else { Debug.Log(leaveRoomMsg.error); } }
/// <summary> /// 在房间里面点击开始游戏,向服务器发出开始游戏请求 /// </summary> /// <param name="param"></param> private void OnClickBtnStartGame(object param) { button.clip = common; button.Play(); var startGameMsg = new mmopb.startBattle_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(startGameMsg)); }
/// <summary> /// 在房间里面点击退出房间退出房间 /// </summary> /// <param name="param"></param> private void OnClickBtnQuitRoom(object param) { button.clip = common; button.Play(); var leaveRoomMsg = new mmopb.leaveRoom_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(leaveRoomMsg)); }
/// <summary> /// 在房间里面点击邀请按钮 /// </summary> /// <param name="param"></param> private void OnClickBtnInviteFriend(object param) { button.clip = common; button.Play(); roomView.friendList.SetActive(true); var friendsReq = new mmopb.friendsList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(friendsReq)); }
public void OnConnected(SocketError err) { if (err == SocketError.Success) { Debug.Log("连接"); var msg = new mmopb.login_ack(); msg.error = "Hello!"; tcpConnection.Send(ProtoHelper.EncodeWithName(msg)); } }
/// <summary> /// 点击好友界面的添加好友按钮 /// </summary> /// <param name="param"></param> private void ClickAddFriend(object param) { button.clip = common; button.Play(); var addFriendMsg = new mmopb.addFriend_req(); string friendName = friendView.friendNameAdd.text; addFriendMsg.nickName = friendName; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(addFriendMsg)); }
/// <summary> /// 点击邀请通知的拒绝按钮 /// </summary> /// <param name="param"></param> private void ClickNoNewInvite(object param) { button.clip = common; button.Play(); var inviteMsg = new mmopb.noticeInviteFriend_ack(); inviteMsg.isSuc = false; inviteMsg.roleId = roleId_invite; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(inviteMsg)); roomsView.newInvite.SetActive(false); }
/// <summary> /// 点击邀请好友列表界面的邀请按钮(对勾) /// </summary> /// <param name="param"></param> private void ClickInviteTargetFriend(object param) { button.clip = sendMsg; button.Play(); var inviteFriendMsg = new mmopb.inviteFriend_req(); GameObject friend = (GameObject)param; FriendInviteDetail friendInviteDetail = friend.GetComponent <FriendInviteDetail>(); inviteFriendMsg.roleId = friendInviteDetail.friendId; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(inviteFriendMsg)); }
/// <summary> /// 在好友列表界面点击删除按钮 /// </summary> /// <param name="param"></param> private void ClickDeleteFriend(object param) { button.clip = common; button.Play(); var deleteMsg = new mmopb.deleteFriend_req(); GameObject friend = (GameObject)param; FriendDetail friendDetail = friend.GetComponentInChildren <FriendDetail>(); deleteMsg.roleId = friendDetail.friendId; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(deleteMsg)); }
/// <summary> /// 点击添加好友通知的拒绝 /// </summary> /// <param name="param"></param> private void ClickNoNewFriend(object param) { button.clip = common; button.Play(); var noticePlayerAddFriend_ack = new mmopb.noticePlayerAddFriend_ack(); noticePlayerAddFriend_ack.isAgree = false; noticePlayerAddFriend_ack.roleId = roleId; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(noticePlayerAddFriend_ack)); lobbyView.newFriend.SetActive(false); }
/// <summary> /// 点击游戏大厅的朋友按钮 /// </summary> /// <param name="param"></param> private void ClickFriends(object param) { button.clip = common; button.Play(); var friendReq = new mmopb.friendsList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(friendReq)); friendView.friends.SetActive(true); lobbyView.partHome.SetActive(false); lobbyView.newMessage.SetActive(false); }
/// <summary> /// 在房间里面点击发送按钮发送消息 /// </summary> /// <param name="param"></param> private void OnClickBtnSendMessage(object param) { button.clip = sendMsg; button.Play(); var sendMessage_req = new mmopb.sendMessage_req(); if (roomView.message.text != "") { sendMessage_req.content = roomView.message.text; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(sendMessage_req)); roomView.message.text = ""; } }
/// <summary> /// 在好友列表点击删除按钮之后处理服务器返回的删除确认消息 /// </summary> /// <param name="msg"></param> private void DeleteFriendHandle(object msg) { var deleteMsg = msg as mmopb.deleteFriend_ack; if (deleteMsg.isSuc) { var friendReq = new mmopb.friendsList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(friendReq)); } else { TipUtils.Instance.ShowToastUI(deleteMsg.error, root, 1.0f); } }
/// <summary> /// 在房间列表界面点击刷新列表按钮刷新房间列表数据 /// </summary> /// <param name="param"></param> private void OnClickBtnRefresh(object param) { button.clip = common; button.Play(); //删除原来有的列表 GameObject[] rooms = GameObject.FindGameObjectsWithTag("ROOM"); foreach (GameObject room in rooms) { Destroy(room); } var rooms_req = new mmopb.roomList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(rooms_req)); }
/// <summary> /// 接受并处理服务器返回的关于添加好友的ack消息 /// </summary> /// <param name="msg">返回消息</param> private void AddFriendHandle(object msg) { var addFriendAck = msg as mmopb.addFriend_ack; if (addFriendAck.isSuc) { TipUtils.Instance.ShowToastUI("添加成功", root, 1.0f); var friendReq = new mmopb.friendsList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(friendReq)); } else { TipUtils.Instance.ShowToastUI(addFriendAck.error, root, 1.0f); } }
/// <summary> /// 点击添加好友通知的同意添加 /// </summary> /// <param name="param"></param> private void ClickYesNewFriend(object param) { button.clip = common; button.Play(); var noticePlayerAddFriend_ack = new mmopb.noticePlayerAddFriend_ack(); noticePlayerAddFriend_ack.isAgree = true; noticePlayerAddFriend_ack.roleId = roleId; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(noticePlayerAddFriend_ack)); lobbyView.newFriend.SetActive(false); if (friendView.friends.activeInHierarchy == true) { var friendReq = new mmopb.friendsList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(friendReq)); } }
/// <summary> /// 服务器响应注册消息 /// </summary> /// <param name="role"></param> private void RegisterReturn(Role role, ReturnValue <UserEntity> ret) { mmopb.register_ack register_Ack = new mmopb.register_ack(); if (!ret.HasError) { register_Ack.succ = true; Console.WriteLine("返回注册成功消息"); } else { register_Ack.succ = false; register_Ack.error = ret.Message; Console.WriteLine("返回注册失败消息"); } role.Client_SActor.Send(ProtoHelper.EncodeWithName(register_Ack)); }
/// <summary> /// 在房间列表界面点击房间的加入按钮加入到一个房间 /// </summary> /// <param name="param"></param> private void OnClickBtnJoin(object param) { button.clip = common; button.Play(); GameObject room = (GameObject)param; RoomDetails roomDetails = room.GetComponent <RoomDetails>(); if (roomDetails.status.text.Equals("战斗中")) { return; } else { var joinRoomMsg = new mmopb.enterRoom_req(); joinRoomMsg.roomId = roomDetails._roomId; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(joinRoomMsg)); } }
/// <summary> /// 在注册界面点击注册按钮,进行注册 /// </summary> /// <param name="param"></param> public void OnClickBtnRegister(object param) { button.Play(); //获取输入,发送给服务器,接受结果,成功则跳转到登陆界面,否则显示错误消息 string account = registerView.Account_reg.text; string nickName = registerView.Nickname_reg.text; string password = registerView.Password_reg.text; string pwdConfirm = registerView.PasswordConfirm_reg.text; var registerMsg = new mmopb.register_req(); //注册信息验证 var verification = InfoVerification(account, nickName, password, pwdConfirm); switch (verification) { case isAccountNull: TipUtils.Instance.ShowToastUI("用户名不能为空", root.transform, 2.0f); break; case isAccountWrong: TipUtils.Instance.ShowToastUI("用户名不正确", root.transform, 2.0f); break; case isNicknameNull: TipUtils.Instance.ShowToastUI("昵称不能为空", root.transform, 2.0f); break; case isPasswordNull: TipUtils.Instance.ShowToastUI("密码不能为空", root.transform, 2.0f); break; case isPwdConfirmWrong: TipUtils.Instance.ShowToastUI("两次密码不匹配", root.transform, 2.0f); break; case isInfoRight: registerMsg.account = account; registerMsg.password = password; registerMsg.nickname = nickName; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(registerMsg)); break; } }
/// <summary> /// 在登录界面点击登录按钮,进行登录 /// </summary> /// <param name="param"></param> private void OnClickBtnLogin(object param) { button.Play(); var account = loginView.Account_log.text; var password = loginView.Password_log.text; //账户格式验证 var isAccountRight = AccountFormatVerification(account); if (isAccountRight) { var loginMsg = new mmopb.login_req(); loginMsg.account = account; loginMsg.password = password; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(loginMsg)); } else { TipUtils.Instance.ShowToastUI("用户名不正确", root.transform, 2.0f); } }
/// <summary> /// 在聊天框点击发送按钮 /// </summary> /// <param name="param"></param> private void ClickSendToTargetFriend(object param) { button.clip = sendMsg; button.Play(); var sendMessageToOnlineFriend_req = new mmopb.sendMessageToOnlineFriend_req(); sendMessageToOnlineFriend_req.content = friendView.chatMsg.text; sendMessageToOnlineFriend_req.roleId = roleId_chat; ClientNet.Instance.Send(ProtoHelper.EncodeWithName(sendMessageToOnlineFriend_req)); //加载预制体 GameObject _message = Resources.Load("MessageMe") as GameObject; // 对象初始化 GameObject message = Instantiate(_message, friendView.chatParentTransForm); Text myContent = message.GetComponentInChildren <Text>(); myContent.text = friendView.chatMsg.text; //清空聊天框 friendView.chatMsg.text = ""; }
public void SendMessage(object o) { tcpConnection.Send(ProtoHelper.EncodeWithName(o)); }
/// <summary> /// 点击退出游戏按钮,向服务器发送离开房间消息 /// </summary> /// <param name="param"></param> private void ClickBtnExit(object param) { var quitMsg = new mmopb.leaveRoom_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(quitMsg)); }
/// <summary> /// 点击设置下的退出账号退出当前账户 /// </summary> /// <param name="param"></param> private void ClickLogoutAccount(object param) { var logoutMsg = new mmopb.exitGame_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(logoutMsg)); }
// Use this for initialization public void Start() { //邀请显示 if (InviteInfo.Instance.IsAgreeInvite) { roomsView.rooms.SetActive(false); roomView.room_boot.SetActive(true); //清空信息 PlayersInfo playersInfo = roomView.room.GetComponent <PlayersInfo>(); playersInfo.name_Yang.text = ""; playersInfo.camp_Yang.text = ""; playersInfo.name_Yin.text = ""; playersInfo.camp_Yin.text = ""; Dictionary <Int32, mmopb.p_roleInfoInRoom> playerList = InviteInfo.Instance.PlayerList; foreach (KeyValuePair <Int32, mmopb.p_roleInfoInRoom> player in playerList) { if (player.Value.camp == 1) { playersInfo.name_Yang.text = player.Value.nickName; playersInfo.camp_Yang.text = "阳"; } else { playersInfo.name_Yin.text = player.Value.nickName; playersInfo.camp_Yin.text = "阴"; } } LocalUser.Instance.Camp = playerList[LocalUser.Instance.PlayerId].camp; InviteInfo.Instance.IsAgreeInvite = false; } //进入时请求房间列表数据 var rooms_req = new mmopb.roomList_req(); ClientNet.Instance.Send(ProtoHelper.EncodeWithName(rooms_req)); //音量设置 GameObject canvas = GameObject.Find("Canvas"); AudioSource audioSource = canvas.GetComponent <AudioSource>(); audioSource.volume = LocalUser.Instance.Voice; audioSource.mute = LocalUser.Instance.IsMute; //事件 UIDispacher.Instance.AddEventListener("Return", OnClickBtnReturn); UIDispacher.Instance.AddEventListener("Refresh", OnClickBtnRefresh); UIDispacher.Instance.AddEventListener("CreateRoom", OnClickBtnCreateRoom); UIDispacher.Instance.AddEventListener("Join", OnClickBtnJoin); UIDispacher.Instance.AddEventListener("StartGame", OnClickBtnStartGame); UIDispacher.Instance.AddEventListener("QuitRoom", OnClickBtnQuitRoom); UIDispacher.Instance.AddEventListener("InviteFriend", OnClickBtnInviteFriend); UIDispacher.Instance.AddEventListener("SendMessage", OnClickBtnSendMessage); UIDispacher.Instance.AddEventListener("CloseInviteFriends", OnClickBtnCloseInviteFriends); UIDispacher.Instance.AddEventListener("ClickInviteTargetFriend", ClickInviteTargetFriend); UIDispacher.Instance.AddEventListener("ClickYesNewInvite", ClickYesNewInvite); UIDispacher.Instance.AddEventListener("ClickNoNewInvite", ClickNoNewInvite); NetDispacher.Instance.AddEventListener("roomList_ack", LoadRoomsHandle); NetDispacher.Instance.AddEventListener("createRoom_ack", CreateRoomHandle); NetDispacher.Instance.AddEventListener("enterRoom_ack", EnterRoomHandle); NetDispacher.Instance.AddEventListener("roleInfoInRoom_bcst", RoleInfoInRoomHandle); NetDispacher.Instance.AddEventListener("startBattle_bcst", StartBattle_bcstHandle); NetDispacher.Instance.AddEventListener("leaveRoom_ack", LeaveRoomHandle); NetDispacher.Instance.AddEventListener("sendMessage_bcst", RevChatMsgHandle); NetDispacher.Instance.AddEventListener("friendsList_ack", FriendsListHandle); NetDispacher.Instance.AddEventListener("noticeInviteFriend_ecn", RevInviteMsgHandle); NetDispacher.Instance.AddEventListener("inviteResult_ack", RevInviteResultHandle); }