/// <summary> /// 游戏聊天 /// </summary> /// <param name="chat"></param> public void ServerGameChat(SendReceiveGameChat chat) { switch ((eGameChatContentType)chat.chatType) { case eGameChatContentType.Face: //表情 break; case eGameChatContentType.Chat: //普通输入的文字 break; case eGameChatContentType.TexTVoice: //快捷文字聊天 PlayTxtVoiceChat(chat); break; case eGameChatContentType.HDFace: //互动表情 PlayHuDongFace(chat); break; case eGameChatContentType.Voice: //语音 PlayVoiceChat(chat); break; } }
/// <summary> /// 语音聊天抬起 /// </summary> public void OnVoiceRelase() { mVoceRecordShow.gameObject.SetActive(false); #if YYVOICE uint mCurRecordTime = 0; YunVaImSDK.instance.RecordStopRequest((data1) => { mCurRecordTime = data1.time; SQDebug.Log("停止录音返回:" + data1.strfilepath); }, (data2) => { SQDebug.Log("上传返回:" + data2.fileurl); XXGoldFlowerGameController mCtr = Global.Inst.GetController <XXGoldFlowerGameController>(); SendReceiveGameChat req = new SendReceiveGameChat(); req.fromSeatId = XXGoldFlowerGameModel.Inst.mMySeatId; req.chatType = (int)eGameChatContentType.Voice; req.content = data2.fileurl; req.voiceChatTime = (int)mCurRecordTime; mCtr.SendGameChat(req); }, (data3) => { SQDebug.Log("识别返回:" + data3.text); }); #endif }
/// <summary> /// 获取玩家信息 /// </summary> /// <param name="uid"></param> public void SendGetPlayerInfo(string uid, int seatId) { SendGetGoldFlowerUserInfoReq req = new SendGetGoldFlowerUserInfoReq(); req.uid = uid; NetProcess.SendRequest <SendGetGoldFlowerUserInfoReq>(req, GoldFlowerProtoIdMap.CMD_SendGetPlayerInfo, (Msg) => { SendGetGoldFlowerUserInfoAck ack = Msg.Read <SendGetGoldFlowerUserInfoAck>(); if (ack.code == 1) { GameUserInfoWidget widget = BaseView.GetWidget <GameUserInfoWidget>(AssetsPathDic.GameUserInfoWidget, mView.transform); widget.SetData(!(seatId == XXGoldFlowerGameModel.Inst.mMySeatId), ack.data.info.headUrl, ack.data.info.nickName, ack.data.info.userId, ack.data.info.address + "", seatId, (index) => { SendReceiveGameChat chat = new SendReceiveGameChat(); chat.fromSeatId = XXGoldFlowerGameModel.Inst.mMySeatId; chat.toSeatId = seatId; chat.faceIndex = index; chat.chatType = (int)eGameChatContentType.HDFace; SendGameChat(chat); }); } else { GameUtils.ShowErrorTips(ack.code); } }); }
public UILabel mLabel; //文本框 /// <summary> /// 设置数据并显示 /// </summary> /// <param name="data">聊天数据</param> /// <param name="pos">坐标,世界坐标</param> /// <param name="call">回调</param> public void SetData(SendReceiveGameChat data, Vector3 pos, eChatTextDirectionType dType) { //设置位置 transform.position = pos; gameObject.SetActive(true); eGameChatContentType _type = (eGameChatContentType)data.chatType; if (_type == eGameChatContentType.Chat)//普通文字 { mLabel.text = data.content; } else if (_type == eGameChatContentType.TexTVoice)//文字语音 { List <ConfigDada> conList = ConfigManager.GetConfigs <TSTGameTxtChatConfig>(); ConfigDada conData = conList.Find(o => o.conIndex == data.faceIndex.ToString()); if (conData == null) { return; } TSTGameTxtChatConfig con = conData as TSTGameTxtChatConfig; mLabel.text = con.name; string voice = data.sex == 1 ? con.soundNameman : con.soundNamewoman; SoundProcess.PlaySound("ChatSound/" + voice); } mBg.width = 20 + mLabel.width;//设置背景长度 DelayRun(2, () => { gameObject.SetActive(false); }); }
/// <summary> /// 播放语音动画 /// </summary> protected void PlayYYVoiceAnimaion(SendReceiveGameChat chat) { mYYVoiceAnim.gameObject.SetActive(true); mYYVoiceAnim.SetBegin("yx_yy0", 1, 3, 50000, 0.25f); float vTime = chat.voiceChatTime / 1000; StartCoroutine(DelaySetVoiceToBegin(vTime)); }
/// <summary> /// 游戏聊天 /// </summary> /// <param name="chat"></param> public void NetOnGameTalk(SendReceiveGameChat chat) { TenPlayerUI player = null; if (TryGetPlayer(chat.fromSeatId, out player)) { player.ServerGameChat(chat); } }
/// <summary> /// 推送聊天 /// </summary> /// <param name="msg"></param> private void NetOnGameTalk(MessageData msg) { SendReceiveGameChat data = msg.Read <SendReceiveGameChat>(); if (mGameUI != null) { mGameUI.ServerGetChat(data); } }
/// <summary> /// 互动表情点击回调 /// </summary> /// <param name="id"></param> private void OnHudongClickCallback(int id) { MJGameController mCtr = Global.Inst.GetController <MJGameController>(); SendReceiveGameChat req = new SendReceiveGameChat(); req.chatType = (int)eGameChatContentType.HDFace; req.faceIndex = id; req.fromSeatId = MJGameModel.Inst.mMySeatId; req.toSeatId = mRoomPlayerInfo.seatId; mCtr.SendGameChat(req); }
/// <summary> /// 聊天 /// </summary> /// <param name="info"></param> public void SendChat(SendReceiveGameChat info) { NetProcess.SendRequest <SendReceiveGameChat>(info, ProtoIdMap.CMD_FinishTask, (msg) => { CommonRecieveProto data = msg.Read <CommonRecieveProto>(); //if (data.code == 1) { Debug.Log("聊天"); } }); }
/// <summary> /// 聊天表情点击 /// </summary> public void OnTxtChatClick() { GameChatView view = Global.Inst.GetController <GameChatController>().OpenWindow() as GameChatView; view.SetData((index) => { NNGameController mCtr = Global.Inst.GetController <NNGameController>(); SendReceiveGameChat req = new SendReceiveGameChat(); req.chatType = (int)eGameChatContentType.TexTVoice; req.faceIndex = index; req.fromSeatId = NiuniuModel.Inst.mMySeatId;; mCtr.SendGameChat(req); }); }
/// <summary> /// 发送聊天 /// </summary> /// <param name="req"></param> public void SendGameChat(SendReceiveGameChat req) { NetProcess.SendRequest <SendReceiveGameChat>(req, MJProtoMap.CMD_SendChat, (Msg) => { CommonRecieveProto ack = Msg.Read <CommonRecieveProto>(); if (ack.code == 1) { } else { GameUtils.ShowErrorTips(ack.code); } }); }
/// <summary> /// 当表情点击 /// </summary> /// <param name="go"></param> public void OnFaceClick(GameObject go) { int index = int.Parse(go.name); //MJChatProtoData data = new MJChatProtoData(); SendReceiveGameChat data = new SendReceiveGameChat(); data.chatType = 4; data.faceIndex = index; data.fromSeatId = MJGameModel.Inst.mMySeatId; Global.Inst.GetController <MJGameController>().SendChat(data); //gameObject.SetActive(false); }
/// <summary> /// 添加一个表情 /// </summary> /// <param name="pos">位置,世界坐标</param> /// <param name="_type">类型</param> /// <param name="data">数据</param> private void AddOneFace(Vector3 pos, eChatTextDirectionType _type, SendReceiveGameChat data) { int index = _type.GetHashCode(); if (index >= 0 && index < mFaces.Length) { //List<ConfigDada> configs = ConfigManager.GetConfigs<GameFaceConfig>(); //ConfigDada conData = configs.Find(o => o.conIndex == data.faceIndex); //if (conData != null) //{ // mFaces[index].transform.position = pos; // GameFaceConfig con = conData as GameFaceConfig; // mFaces[index].SetBegin(con.animSprite, con.startEnd[0], con.startEnd[con.startEnd.Length - 1], 2, 0.25f, false); //} } }
private Dictionary <int, GameObject> mVoiceDic = new Dictionary <int, GameObject>(); //语音聊天喇叭 #region 互动表情 /// <summary> /// 添加一个互动表情 /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="con"></param> public void AddOneInteractionFace(Vector3 from, Vector3 to, SendReceiveGameChat data) { List <ConfigDada> conList = ConfigManager.GetConfigs <TSTHuDongFaceConfig>(); TSTHuDongFaceConfig con = null; for (int i = 0; i < conList.Count; i++) { TSTHuDongFaceConfig temp = conList[i] as TSTHuDongFaceConfig; if (temp.id == data.faceIndex) { con = temp; break; } } if (con == null) { return; } GameObject go = NGUITools.AddChild(mItemRoot, mItem); go.gameObject.SetActive(true); TweenPosition tween = go.GetComponent <TweenPosition>(); UISprite sp = go.GetComponent <UISprite>(); SpriteAnimation anim = go.GetComponent <SpriteAnimation>(); //设置起始点和目标点 mFrom.position = from; mTo.position = to; from = mFrom.localPosition; to = mTo.localPosition; //飞行动画和表情动画 sp.spriteName = con.foreName + "0"; tween.duration = 0.4f; string sound = con.sound; tween.AddOnFinished(() => { anim.SetBegin(con.foreName, 1, con.length); anim.SetDalayDestory(4.0f); SoundProcess.PlaySound("HuDongFaceSound/" + sound); }); tween.from = from; tween.to = to; tween.PlayForward(); }
/// <summary> /// 文字聊天,文字语音,语音,表情 /// </summary> /// <param name="pos">位置,世界坐标</param> /// <param name="_type">类型</param> /// <param name="data">数据</param> public void AddOneChat(Vector3 pos, eChatTextDirectionType _type, SendReceiveGameChat data) { eGameChatContentType chatType = (eGameChatContentType)data.chatType; switch (chatType) { case eGameChatContentType.Chat: //文字 case eGameChatContentType.TexTVoice: //文字语音 AddOneText(pos, _type, data); break; case eGameChatContentType.Face: //表情 AddOneFace(pos, _type, data); break; case eGameChatContentType.Voice: //语音 AddOneVoice(pos, _type, data); break; } }
/// <summary> /// 添加一个文字聊天或文字语音 /// </summary> /// <param name="pos">位置,世界坐标</param> /// <param name="_type">类型</param> /// <param name="data">数据</param> private void AddOneText(Vector3 pos, eChatTextDirectionType _type, SendReceiveGameChat data) { int index = (int)_type; GameTextChatShowItem item; if (mTextChat.ContainsKey(data.fromSeatId)) { item = mTextChat[data.fromSeatId]; } else { if (index < 0 || index >= mTextItems.Length) { return; } GameObject obj = NGUITools.AddChild(mTextRoot, mTextItems[index].gameObject); item = obj.GetComponent <GameTextChatShowItem>(); mTextChat[data.fromSeatId] = item; } item.SetData(data, pos, _type); }
/// <summary> /// 添加一个语音 /// </summary> /// <param name="pos">位置,世界坐标</param> /// <param name="_type">类型</param> /// <param name="data">数据</param> private void AddOneVoice(Vector3 pos, eChatTextDirectionType _type, SendReceiveGameChat data) { bool ised = PlayerPrefs.GetInt("DDL_" + PlayerModel.Inst.UserInfo.userId) == 1 ? true : false;//等于1是勾选了,其他是未勾选 if (!ised) { string ext = DateTime.Now.ToFileTime().ToString(); #if YYVOICE YunVaImSDK.instance.RecordStartPlayRequest("", data.content, ext, (data2) => { if (data2.result == 0) { SQDebug.Log("播放成功"); } else { SQDebug.Log("播放失败"); } }); #endif } int index = data.fromSeatId; GameObject obj; if (mVoiceDic.ContainsKey(index)) { obj = mVoiceDic[index]; } else { obj = NGUITools.AddChild(mVoiceRoot, mVoiceItem); mVoiceDic[index] = obj; } obj.SetActive(true); obj.transform.position = pos; float t = data.voiceChatTime / 1000f; DelayRun(t, () => { obj.SetActive(false); }); }
/// <summary> /// 显示文字聊天 /// </summary> /// <param name="chat"></param> private void PlayTxtVoiceChat(SendReceiveGameChat chat) { mTxtChatSp.gameObject.SetActive(true); List <ConfigDada> mRulelist = mRulelist = ConfigManager.GetConfigs <TSTGameTxtChatConfig>(); for (int i = 0; i < mRulelist.Count; i++) { TSTGameTxtChatConfig config = mRulelist[i] as TSTGameTxtChatConfig; if (config.id == chat.faceIndex) { mTxtChatSp.GetComponentInChildren <UILabel>().text = config.name; mTxtChatSp.GetComponent <UISprite>().width = mTxtChatSp.GetComponentInChildren <UILabel>().width + 70; int sex = 1; GoldFlowerPlayer player = null; if (XXGoldFlowerGameModel.Inst.mPlayerInfoDic.TryGetValue(chat.fromSeatId, out player)) { sex = player.sex; } if (sex == 1) { SoundProcess.PlaySound("ChatSound/" + config.soundNameman); } else { SoundProcess.PlaySound("ChatSound/" + config.soundNamewoman); } StopCoroutine("DelayHideTxtChat"); StartCoroutine("DelayHideTxtChat"); } } }
/// <summary> /// 播放语音 /// </summary> /// <param name="chat"></param> protected void PlayVoiceChat(SendReceiveGameChat chat) { bool ised = PlayerPrefs.GetInt("DDL_" + PlayerModel.Inst.UserInfo.userId) == 1 ? true : false;//等于1是勾选了,其他是未勾选 if (!ised) { string ext = DateTime.Now.ToFileTime().ToString(); #if YYVOICE YunVaImSDK.instance.RecordStartPlayRequest("", chat.content, ext, (data2) => { if (data2.result == 0) { SQDebug.Log("播放成功"); } else { SQDebug.Log("播放失败"); } }); #endif } PlayYYVoiceAnimaion(chat); }
/// <summary> /// 显示互动表情 /// </summary> /// <param name="chat"></param> protected void PlayHuDongFace(SendReceiveGameChat chat) { if (mGameInteractionView == null) { mGameInteractionView = Global.Inst.GetController <GameInteractionController>().OpenWindow() as GameInteractionView; } List <ConfigDada> config = ConfigManager.GetConfigs <TSTHuDongFaceConfig>(); TSTHuDongFaceConfig con = null; for (int i = 0; i < config.Count; i++) { TSTHuDongFaceConfig hdf = config[i] as TSTHuDongFaceConfig; if (hdf.id == chat.faceIndex) { con = hdf; break; } } //起始位置 Vector3 from = Vector3.zero; //目标位置 Vector3 to = Vector3.zero; NiuniuGameView view = Global.Inst.GetController <NNGameController>().mView; NiuniuPlayerUI fromPlayer = null; NiuniuPlayerUI toPlayer = null; if (view.TryGetPlayer(chat.fromSeatId, out fromPlayer) && view.TryGetPlayer(chat.toSeatId, out toPlayer)) { from = fromPlayer.GetBaseInfoPos(); to = toPlayer.GetBaseInfoPos(); mGameInteractionView.AddOneInteractionFace(from, to, chat); } }
/// <summary> /// 同步游戏聊天 /// </summary> /// <param name="msg"></param> private void NetOnGameTalk(MessageData msg) { SendReceiveGameChat ack = msg.Read <SendReceiveGameChat>(); mView.NetOnGameTalk(ack); }