//登录成功后与gw建立长链接 public void LoginSuccessCallback(string data) { LoginResponse r = JsonMapper.ToObject <LoginResponse>(data); if (!r.status) { AppDebug.Log("登陆失败:" + r.err); return; } AppDebug.Log("登陆成功!"); //创建用户实体 m_Player.UserId = r.userId; m_Player.Token = r.token;//System.Text.Encoding.Default.GetString(); m_Player.TokenExpireTime = r.expireTime; //获取 gateway 地址(此处应该返回一个服务器列表,供玩家选择登录) string[] c = { ":" }; string[] s = r.gw.Split(c, StringSplitOptions.None); string host = s[0]; int port = int.Parse(s[1]); SocketClient.Instance.Connecte(host, port); }
/// <summary> /// 进入房间 /// </summary> /// <param name="proto"></param> public void EnterRoom(JY_ROOM_ENTER proto) { Debug.Log(proto.pos + "进入房间"); SeatEntity seat = GetSeatBySeatId(proto.pos); if (seat == null) { return; } seat.PlayerId = proto.playerId; seat.Nickname = proto.nickname; seat.Avatar = proto.avatar; seat.Gender = proto.gender; seat.Pos = proto.pos; seat.Gold = proto.gold; seat.IsBanker = false; seat.seatStatus = SEAT_STATUS.IDLE; seat.isReady = false; seat.Pour = 0; seat.isJoinGame = false; PeopleCounting(); SendSeatInfoChangeNotify(seat); AppDebug.Log(seat.Nickname + "进入房间,SeatIndex:" + seat.Index); }
/// <summary> /// 座位弃牌 /// </summary> public void OnSeatDiscardPoker() { //找到手牌 List <MaJiangCtrl_JuYou> handPokerList = MahJongManager_JuYou.Instance.GetHand(m_nSeatIndex); if (handPokerList == null) { return; } int handPokerListCount = handPokerList.Count; List <MaJiangCtrl_JuYou> TablePokerList = MahJongManager_JuYou.Instance.GetDicTable(m_nSeatIndex); //if (TablePokerList != null && TablePokerList.Count >= 16) Debug.Log("弃掉桌面牌" + m_nSeatIndex+ "TablePokerList.Count"+ TablePokerList.Count); if (TablePokerList != null && TablePokerList.Count >= 16) { MahJongManager_JuYou.Instance.ClearDicTable(m_nSeatIndex); } for (int i = 0; i < handPokerListCount; i++) { AppDebug.Log(string.Format("座位Index{0}弃牌{1}", m_nSeatIndex, handPokerList[0].Poker.ToChinese())); MaJiangCtrl_JuYou majiang = MahJongManager_JuYou.Instance.ClearHandPoker(m_nSeatIndex, handPokerList[0].Poker); if (majiang != null) { majiang.gameObject.SetParent(m_DeskTopContainer.transform); majiang.gameObject.layer = m_DeskTopContainer.gameObject.layer; majiang.transform.localPosition = m_DeskTopContainer.GetLocalPos(majiang.transform); } } //if (TablePokerList != null && TablePokerList.Count > 18) MahJongManager_JuYou.Instance.ClearDicTable(m_nSeatIndex); }
/// <summary> /// 设置Poker状态 播放动画 /// </summary> /// <param name="seat"></param> public void SetPokerStatus(Seat seat) { //获得MaJiangCtrl_PaiJiu list List <MaJiangCtrl_PaiJiu> handPokerList = MahJongManager_PaiJiu.Instance.GetHand(m_nSeatPos); //设置状态 if (handPokerList == null) { return; } for (int i = 0; i < handPokerList.Count; i++) { if (handPokerList[i].Poker.type == 0 || handPokerList[i].Poker.size == 0) { continue; } //加载预制 设置数据 //判断名字是否是相应数据 string prabfName = handPokerList[i].gameObject.name.Split('(')[0]; if (prabfName != handPokerList[i].Poker.ToString()) { MahJongManager_PaiJiu.Instance.SetHand(m_nSeatPos, seat.PokerList[i]); } AppDebug.Log(string.Format("座位{0} Index{1} 变更牌状态", seat.Pos, handPokerList[i].Poker.index)); handPokerList[i].SetPokerStatus(true); } }
/// <summary> /// 进入房间 /// </summary> /// <param name="pbSeat"></param> public void EnterRoom(PDK_ENTER_ROOM proto) { if (CurrentRoom == null) { return; } //if (CurrentRoom.SeatList.Count == 2 && proto.pos == 2) //{ // proto.pos = 3; //} Debug.Log("座位" + proto.pos + "进入房间"); SeatEntity seat = GetSeatBySeatPos(proto.pos); if (seat == null) { return; } seat.PlayerId = proto.playerId; seat.isLandlord = seat.PlayerId == CurrentRoom.ownerId; seat.Gold = 0; //seat.Gold = proto.gold; seat.Avatar = proto.avatar; seat.Gender = proto.gender; seat.Nickname = proto.nickname; //seat.IP = proto.ipaddr; seat.Pos = proto.pos; seat.Latitude = proto.latitude; seat.Longitude = proto.longitude; seat.IsFocus = true; SendSeatInfoChangeNotify(seat); AppDebug.Log(seat.Nickname + "进入房间"); }
/// <summary> /// 下注 /// </summary> /// <param name="proto"></param> public void NoticeJetton(PAIGOW_ROOM_INFORM_JETTON proto) { CurrentRoom.roomStatus = ROOM_STATUS.POUR; CurrentRoom.loopEnd = false; List <int> pourPosList = proto.getPosList(); for (int i = 0; i < pourPosList.Count; i++) { PaiJiu.Seat seat = GetSeatBySeatId(pourPosList[i]); if (seat == null) { continue; } seat.Pour = 0; AppDebug.Log(seat.Nickname + "开始下注"); //提示该谁下注 //设置倒计时 SetCountDown(proto.unixtime); //SendSeatInfoChangeNotify(seat); //SendRoomInfoChangeNotify(); } // 1 判断自己是否下注 // 2 控制提示 SendRoomInfoChangeNotify(); }
/// <summary> /// 告诉玩家去哪里 /// </summary> /// <param name="targetPos"></param> public void MoveTo(Vector3 targetPos) { //如果目标点不是原点 进行移动 if (targetPos == Vector3.zero) { return; } TargetPos = targetPos; //CurrRoleFSMMgr.ChangeState(RoleState.Run); //计算路径 m_seeker.StartPath(transform.position, targetPos, (Path p) => { if (!p.error) { AStarPath = (ABPath)p; if (Vector3.Distance(AStarPath.endPoint, new Vector3(AStarPath.originalEndPoint.x, AStarPath.endPoint.y, AStarPath.originalEndPoint.z)) > 1f) { AppDebug.Log("不能到达目标点"); AStarPath = null; } AStartCurrWayPoint = 1; CurrRoleFSMMgr.ChangeState(RoleState.Run); } else { //寻路失败 AppDebug.LogError(p.errorLog); AStarPath = null; } }); }
/// <summary> /// 服务器广播换庄 /// </summary> private void OnServerChangeBanker(byte[] obj) { AppDebug.Log("服务器广播换庄"); PAIGOW_ROOM_CHANGEBANKER proto = PAIGOW_ROOM_CHANGEBANKER.decode(obj); RoomPaiJiuProxy.Instance.OnServerChangeBanker(proto); }
public void SendMessage(IMessage obj) { if (!MessageDefine.ContainProtoType(obj.GetType())) { AppDebug.Log("协议不存在:" + obj.GetType().ToString()); return; } Message msg = new Message(); //set header msg.Header = new Header(); //set body { byte[] messageBody = obj.ToByteArray(); byte[] body = new byte[2 + messageBody.Length]; using (AppMemoryStream ms = new AppMemoryStream()) { int id = MessageDefine.GetProtoIdByProtoType(obj.GetType()); ms.WriteUShort((ushort)(id)); ms.Write(messageBody, 0, messageBody.Length); body = ms.ToArray(); } msg.Body = ByteString.CopyFrom(body); } //发送消息 int protoId = MessageDefine.GetProtoIdByProtoType(msg.GetType()); SocketClient.Instance.SendMessage(protoId, msg.ToByteArray()); }
/// <summary> /// 获取公告回调 /// </summary> /// <param name="args"></param> private void OnRequestNoticeCallBack(NetWorkHttp.CallBackArgs args) { //RequestNotice的回调又调用了OpenView m_isBusy = false; if (args.HasError) { ShowMessage("提示", "网络连接失败"); } else { if (args.Value.code < 0) { ShowMessage("错误", args.Value.msg); return; } List <NoticeEntity> lst = LitJson.JsonMapper.ToObject <List <NoticeEntity> >(args.Value.data.ToJson()); // UIViewManager.Instance.OpenWindow(UIWindowType.Notice); AppDebug.Log("服务器给的公告数据:" + args.Value.data.ToJson()); if (m_UIMailView != null) { //ShowMessage("提示", "这里需要打开"); m_UIMailView.SetBtnLeft(lst);//在公告面板初始化时,生成按钮 } } }
/// <summary> /// 连接到socket服务器 /// </summary> /// <param name="ip">ip</param> /// <param name="port">端口号</param> public void Connect(string ip, int port) { //如果socket已经存在 并且处于连接中状态 则直接返回 if (m_Client != null && m_Client.Connected) { return; } m_Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { m_Client.Connect(new IPEndPoint(IPAddress.Parse(ip), port)); m_CheckSendQuene = OnCheckSendQueueCallBack; ReceiveMsg(); if (OnConnectOK != null) { OnConnectOK(); } AppDebug.Log("连接成功"); } catch (Exception ex) { AppDebug.Log("连接失败=" + ex.Message); } }
/// <summary> /// 进入房间 /// </summary> /// <param name="pbSeat"></param> public void EnterRoom(PAIGOW_ROOM_ENTER proto) { Debug.Log(proto.pos + "进入房间"); PaiJiu.Seat seat = GetSeatBySeatId(proto.pos); if (seat == null) { return; } seat.PlayerId = proto.playerId; seat.Nickname = proto.nickname; seat.Avatar = proto.avatar; seat.Gender = proto.gender; seat.Pos = proto.pos; //seat.Gold = proto.gold; //<-----------------------------------《玩家基本金币》 PeopleCounting(); SendSeatInfoChangeNotify(seat); #if IS_ZHANGJIAKOU if (BankerSeat != null) { SendSeatInfoChangeNotify(BankerSeat); } #endif AppDebug.Log(seat.Nickname + "进入房间,SeatIndex:" + seat.Index); }
/// <summary> /// 开局 /// </summary> /// <param name="room"></param> /// <param name="isPlayAnimation"></param> public void Begin(RoomEntity room, bool isPlayAnimation) { //CompassCtrl.Instance.SetNormal(); //<--------------指南针控制 //UIItemTingTip.Instance.Close(); //m_UISceneMaJiang3DView.Begin(); //m_UIScenePaiJiu3DView. //设置开局的 //====================初始化墙==================== InitWall(isPlayAnimation); //===================摸牌======================= if (!isPlayAnimation) { for (int i = 0; i < room.SeatList.Count; i++) { SeatEntity seat = room.SeatList[i]; //桌面上的牌 for (int j = 0; j < seat.TablePokerList.Count; j++) { MaJiangCtrl_JuYou majiang = MahJongManager_JuYou.Instance.DrawMaJiang(seat.Index, seat.TablePokerList[j]); //清空摸到手里的已出过的牌 if (seat.TablePokerList.Count > 0) { m_Seats[seat.Index].OnSeatDiscardPoker(); } //if (seat.TablePokerList.Count > 0) MahJongManager_JuYou.Instance.ClearDicTable(seat.Index); } List <MaJiangCtrl_JuYou> majiangs = new List <MaJiangCtrl_JuYou>(); //手里的牌 for (int j = 0; j < seat.PokerList.Count; ++j) { if (seat == RoomJuYouProxy.Instance.PlayerSeat) { AppDebug.Log(string.Format("---PlayerSeat---------重连房间座位手牌{0}", seat.PokerList[j].ToChinese())); } MaJiangCtrl_JuYou majiang = null; majiang = MahJongManager_JuYou.Instance.DrawMaJiang(seat.Index, seat.PokerList[j]); majiangs.Add(majiang); } m_Seats[seat.Index].DrawPoker(majiangs, true); } } else { //// 清空手牌 // for (int i = 0; i < room.SeatList.Count; i++) // { // SeatCtrl_JuYou seatCtrl = m_Seats[room.SeatList[i].Index]; // if (seatCtrl != null) seatCtrl.OnSeatDiscardPoker(); // } //其他动画 m_UISceneJuYou3DView.Begin(RoomJuYouProxy.Instance.CurrentRoom); //StartCoroutine(BeginAnimation(/*isReplay*/)); } }
//设置手牌 (空手牌 赋值) public void SetHand(int seatPos, Poker poker) { //判断是否需要加载 List <MaJiangCtrl_PaiJiu> handPokerList = GetHand(seatPos); if (handPokerList == null) { return; } for (int i = 0; i < handPokerList.Count; i++) { if (handPokerList[i].Poker.index == poker.index) { AppDebug.Log(string.Format("加载有数据的牌")); MaJiangCtrl_PaiJiu ctrl = SpawnMaJiang(seatPos, poker, "Hand"); ctrl.transform.SetParent(handPokerList[i].transform.parent); ctrl.transform.localScale = handPokerList[i].transform.localScale; ctrl.transform.localPosition = handPokerList[i].transform.localPosition; ctrl.transform.localEulerAngles = handPokerList[i].transform.localEulerAngles; PushMaJiangToPool(handPokerList[i].gameObject); handPokerList[i] = ctrl; } } }
void Start() { CurrChannelInitConfig = new ChannelInitConfig(); //初始化渠道配置 InitChannelConfig(ref WebAccountUrl, ref ChannelId, ref InnerVersion); AppDebug.Log("WebAccountUrl=" + WebAccountUrl); AppDebug.Log("ChannelId=" + ChannelId); AppDebug.Log("InnerVersion=" + InnerVersion); Dictionary <string, object> dic = new Dictionary <string, object>(); dic["ChannelId"] = ChannelId; dic["InnerVersion"] = InnerVersion; //初始化的时候 请求服务器时间 NetWorkHttp.Instance.SendData(WebAccountUrl + "api/init", OnInitCallBack, isPost: true, dic: dic); #if UNITY_STANDALONE_WIN string localFilePath = Application.persistentDataPath + "/"; //AppDebug.Log(localFilePath); if (!Directory.Exists(localFilePath)) { Directory.CreateDirectory(localFilePath); } #endif }
/// <summary> /// 当客户端连接服务器成功之后的回调处理 /// </summary> private void OnConnectOKCallback() { //开始更新最后连接的区服信息 把这些信息写入后台进行记录 UpdateLastLogOnServer(GlobalInit.Instance.m_currentAccountEntity, GlobalInit.Instance.m_currentSelectGameServer); AppDebug.Log("和服务器连接成功"); SceneMgr.Instance.LoadToSelectRole(); }
private void OnOpen(WebSocket ws) { AppDebug.Log("ws:OnOpen "); m_CheckSendQueneAction = CheckSendQueue; m_connected = true; }
/// <summary> /// 异步连接 /// </summary> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="onConnectedCallBack"></param> public void BeginConnect() { if (m_SocketClient.Socket != null && m_SocketClient.Socket.Connected) { Debug.Log("重复连接?????????"); m_SocketClient.Close(false); return; } string ip = m_SocketClient.CurrentHost; AddressFamily addressFamily = AddressFamily.InterNetwork; IPAddress[] ips = null; try { ips = Dns.GetHostAddresses(m_SocketClient.CurrentHost); } catch { m_isConnectComplete = true; m_isConnectSuccess = false; return; } if (ips != null && ips.Length > 0) { string rawIp = ips[0].ToString(); GetIP(rawIp, out ip, out addressFamily); m_SocketClient.Socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); for (int i = 0; i < ips.Length; ++i) { Debug.Log("DNS解析的地址有:" + ips[i].ToString() + "网络类型:" + ips[i].AddressFamily.ToString()); //if (ips[i].AddressFamily == AddressFamily.InterNetwork) //{ // string rawIp = ips[i].ToString(); // GetIP(rawIp, out ip, out addressFamily); // m_SocketClient.Socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); // break; //} } } else { m_SocketClient.Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } try { AppDebug.Log(string.Format("连接{0}:{1}", ip, m_SocketClient.CurrentPort.ToString())); m_SocketClient.Socket.BeginConnect(ip, m_SocketClient.CurrentPort, ConnectCallBack, m_SocketClient.Socket); } catch { m_isConnectComplete = true; m_isConnectSuccess = false; } }
private void OnBinary(WebSocket ws, byte[] data) { AppDebug.Log("ws:OnBinary "); lock (m_ReceiveQueue) { m_ReceiveQueue.Enqueue(data); } }
/// <summary> /// /// </summary> private void OnServerNextGame(byte[] obj) { AppDebug.Log("服务器广播准备下一局"); RoomPaiJiuProxy.Instance.OnServerNextGame(); if (PaiJiuSceneCtrl.Instance != null) { PaiJiuSceneCtrl.Instance.NextGame(); } }
private void OnError(WebSocket ws, Exception e) { if (e == null) { return; } AppDebug.Log("ws:OnBinary " + e.ToString()); }
private void OnClickGameLevelCallback(int gameLevelId, Transform container) { AppDebug.Log(gameLevelId); m_levelDetailView = WindowUIMgr.Instance.OpenWindow(WindowUIType.GameLevelDetail).GetComponent <UIGameLevelDetailView>(); //GameObject @object = ResourcesMgr.Instance.Load(ResourcesMgr.ResourceType.UIWindow, "Pan_GameLevelDetail"); m_levelDetailView.transform.SetParent(container); m_levelDetailView.gameObject.SetGameObjNormalTransfor(0.8f); SetGameLevelDetailData(gameLevelId, 0, m_levelDetailView); }
/// <summary> /// 服务器广播比赛开始 /// </summary> /// <param name="obj"></param> private void OnServerBroadcastBegin(byte[] obj) { AppDebug.Log("服务器广播比赛开始"); OP_MATCH_BEGIN proto = OP_MATCH_BEGIN.decode(obj); MatchProxy.Instance.BeginMatch(); GameCtrl.Instance.BeginMatch(m_CurrentSelectMatchEntity.gameId); MatchProxy.Instance.UpdateRiseCount(proto.promoted); m_isWait = false; }
/// <summary> /// 服务器广播换庄 /// </summary> private void OnServerChooseBanker(byte[] obj) { AppDebug.Log("服务器广播换庄"); JY_ROOM_INFORMBANKER proto = JY_ROOM_INFORMBANKER.decode(obj); RoomJuYouProxy.Instance.OnServerChooseBanker(proto); //if (PaiJiuSceneCtrl.Instance != null) //{ // PaiJiuSceneCtrl.Instance.ChooseBanker(); //} }
private IEnumerator LoadingScene() { string strSceneName = string.Empty; switch (SceneMgr.Instance.CurrentSceneType) { case SceneType.LogOn: strSceneName = "Scene_LogOn"; break; case SceneType.SelectRole: strSceneName = "Scene_SelectRole"; break; case SceneType.WorldMap: //现在需要根据当前服务器返回的最后登录的世界地图id拿到地图相关实体数据 WorldMapEntity worldMapEntity = WorldMapDBModel.GetInstance.GetEntityById(SceneMgr.Instance.CurrWorldMapId); if (worldMapEntity != null) { //现在我们从地图实体类中找到我们地图编号对应的场景名字 strSceneName = worldMapEntity.SceneName; } else { AppDebug.Log(GetType() + "/LoadingScene()/当前世界地图id没有得到对应的实体数据,请检查。id = " + SceneMgr.Instance.CurrWorldMapId); strSceneName = string.Empty; } break; } //说明有错误需要调整 if (strSceneName == string.Empty) { //直接退出携程 yield break; } if (SceneMgr.Instance.CurrentSceneType == SceneType.SelectRole || SceneMgr.Instance.CurrentSceneType == SceneType.WorldMap) { AssetBundleMgr.Instance.LoadAssetAsync(string.Format("Scene/{0}.unity3d", strSceneName), strSceneName, OnLoadABCompleted: (UnityEngine.GameObject obj) => { m_Async = SceneManager.LoadSceneAsync(strSceneName, LoadSceneMode.Additive); m_Async.allowSceneActivation = false; }); } else { m_Async = SceneManager.LoadSceneAsync(strSceneName, LoadSceneMode.Additive); m_Async.allowSceneActivation = false; yield return(m_Async); } }
/// <summary> /// 服务器广播选庄 /// </summary> private void OnServerChooseBanker(byte[] obj) { AppDebug.Log("服务器广播选庄"); PAIGOW_ROOM_CHOOSEBANKER proto = PAIGOW_ROOM_CHOOSEBANKER.decode(obj); RoomPaiJiuProxy.Instance.OnServerChooseBanker(proto); if (PaiJiuSceneCtrl.Instance != null) { PaiJiuSceneCtrl.Instance.ChooseBanker(); } }
/// <summary> /// 设置UI手牌 状态 /// </summary> public void SetHandPokerStatus(Seat seat) { AppDebug.Log(string.Format("翻开UI手牌")); for (int i = 0; i < m_HandList.Count; i++) { if (m_HandList[i].Majiang != null) { m_HandList[i].Majiang.SetPokerStatus(true); } } }
/// <summary> /// 服务器广播总结算信息 /// </summary> /// <param name="obj"></param> private void OnServerResultInfo(byte[] obj) { AppDebug.Log("服务器广播总结算信息"); PAIGOW_ROOM_TOTALSETTLE proto = PAIGOW_ROOM_TOTALSETTLE.decode(obj); if (proto.hasPaigowRoom()) { m_Result = proto.paigow_room; RoomPaiJiuProxy.Instance.RoomResult(m_Result); } }
/// <summary> /// 牌局结果界面分享按钮点击 /// </summary> /// <param name="obj"></param> private void OnBtnResultViewShareClick(object[] obj) { if (m_UIResultView != null) { m_UIResultView.StartCoroutine(ShareCtrl.Instance.ScreenCapture(OnScreenCaptureComplete)); } else if (m_UISettleView != null) { AppDebug.Log("开始分享了啊"); m_UISettleView.StartCoroutine(ShareCtrl.Instance.ScreenCapture(OnScreenCaptureComplete)); } }
/// <summary> /// 截屏完成回调 /// </summary> /// <param name="tex"></param> private void OnScreenCaptureComplete(Texture2D tex) { string path = LocalFileManager.Instance.LocalFilePath + "share/"; if (!IOUtil.DirectoryExists(path)) { IOUtil.CreateDirectory(path); } IOUtil.Write(path + "record.jpg", tex.EncodeToJPG()); AppDebug.Log("分享完了啊"); ShareCtrl.Instance.ShareTexture(WXShareType.WXSceneSession, path + "record.jpg"); }