bool ShowTalkStr(int nindex) { bool success = false; if (m_dialogInfo != null) { if (m_dialogInfo.buttons != null) { if (m_dialogInfo.buttons.Count < 2) { StopAllCoroutines(); //倒计时 tempTime = 0; CLOSETIME = CONST_TASK_CD; m_label_LabelNext.gameObject.SetActive(true); m_label_LabelNext.text = ((int)CLOSETIME).ToString() + "秒后自动跳过"; StartCoroutine(WaitToClose()); } else { m_label_LabelNext.gameObject.SetActive(false); } } } ResetDes(); if (m_dialogInfo != null) { if (m_dialogInfo.lstTalks != null) { if (nindex < m_dialogInfo.lstTalks.Count) { LangTalkData.Talk talkInfo = m_dialogInfo.lstTalks[nindex]; if (talkInfo.bUser) { string name = ""; if (Client.ClientGlobal.Instance().MainPlayer != null) { name = Client.ClientGlobal.Instance().MainPlayer.GetName(); } m_label_nameLabel.text = name; ShowRoleTexture(true); } else { table.NpcDataBase npcdata = GameTableManager.Instance.GetTableItem <table.NpcDataBase>(m_dialogInfo.nNpcId); if (npcdata != null) { ShowRoleTexture(false, npcdata); m_label_nameLabel.text = npcdata.strName; } } bool useRichText = false;//富文本有泄漏bug 暂时不用 if (useRichText) { string desc = string.Format("<size value=\"24\"><color value=\"#1c2850\">{0} </color></size>", talkInfo.strText); if (uiXmlRichText != null) { this.uiXmlRichText.fontSize = 24; this.uiXmlRichText.AddXml(RichXmlHelper.RichXmlAdapt(desc)); } } else { string desc = string.Format("[1c2850]{0}[-]", talkInfo.strText); m_label_normalText.text = desc; } success = true; } } if (m_dialogInfo.talkVoice != null && nindex < m_dialogInfo.talkVoice.Length) { Engine.IAudio audio = Engine.RareEngine.Instance().GetAudio(); if (audio != null && m_nPlayingAudioId != 0) { audio.StopEffect(m_nPlayingAudioId); } table.ResourceDataBase resDB = GameTableManager.Instance.GetTableItem <table.ResourceDataBase>(m_dialogInfo.talkVoice[nindex]); if (resDB == null) { Engine.Utility.Log.Error("找不到选择角色的Mp3资源"); } if (audio != null && resDB != null) { //m_nPlayingAudioId = audio.PlayUIEffect(resDB.strPath); Client.IPlayer mainPlayer = Client.ClientGlobal.Instance().MainPlayer; if (mainPlayer != null) { Transform tf = mainPlayer.GetTransForm(); if (tf != null) { m_nPlayingAudioId = audio.PlayEffect(tf.gameObject, resDB.strPath, false, true); } } } } } //是否显示下一个 //bool nextVisible = (null != m_dialogInfo // && null != m_dialogInfo.lstTalks // && (m_dialogInfo.lstTalks.Count > nindex + 1)); //if (null != m_label_LabelNext && m_label_LabelNext.gameObject.activeSelf != nextVisible) //{ // m_label_LabelNext.gameObject.SetActive(nextVisible); //} return(success); }
public static LangTalkData GetDataByCmd(GameCmd.stTalkDataScriptUserCmd_S cmd) { table.LangTextDataBase langtextDb = GameTableManager.Instance.GetTableItem <table.LangTextDataBase>(cmd.txt_id); LangTalkData data = new LangTalkData(); data.strStep = cmd.step; if (langtextDb != null) { data.nTextID = langtextDb.dwID; uint npcId; if (GetNpcIdForDaliyRingTask(out npcId)) { data.nNpcId = npcId; } else { data.nNpcId = langtextDb.npcID; } data.npcType = (NpcType)langtextDb.npcType; data.nTaskId = langtextDb.taskID; if (!string.IsNullOrEmpty(langtextDb.talkVoice)) { string[] voices = langtextDb.talkVoice.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); data.talkVoice = new uint[voices.Length]; for (int i = 0; i < voices.Length; i++) { data.talkVoice[i] = uint.Parse(voices[i]); } } for (int i = 0; i < cmd.buttons.Count; ++i) { table.LangTextDataBase btnDb = GameTableManager.Instance.GetTableItem <table.LangTextDataBase>(cmd.buttons[i]); if (btnDb != null) { LangTalkData.Button btn = new LangTalkData.Button(); btn.taskId = btnDb.taskID; btn.nindex = (uint)i + 1; btn.strBtnName = btnDb.strText; data.buttons.Add(btn); } } IEnumerable <XNode> nodes = XDocument.Parse("<root>" + langtextDb.strText + "</root>").Root.Nodes(); if (nodes != null) { foreach (var n in nodes) { var e = n as XElement; if (e != null) { switch (e.Name.ToString()) { case "talk": LangTalkData.Talk talk = new LangTalkData.Talk(); if (e.Attribute("type") != null) { var type = int.Parse(e.AttributeValue("type")); talk.bUser = type == 2; } if (e.Attribute("text") != null) { System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); string text = e.AttributeValue("text"); string strColor = ""; bool starttoken = false; for (int i = 0; i < text.Length; i++) { if (starttoken) { if (text[i] == '0' || text[i] == '1' || text[i] == '2' || text[i] == '3' || text[i] == '4' || text[i] == '5' || text[i] == '6' || text[i] == '7' || text[i] == '8' || text[i] == '9' || text[i] == 'a' || text[i] == 'b' || text[i] == 'c' || text[i] == 'd' || text[i] == 'e' || text[i] == 'f' || text[i] == 'A' || text[i] == 'B' || text[i] == 'C' || text[i] == 'D' || text[i] == 'E' || text[i] == 'F' || text[i] == '-') { strColor += text[i]; } else if (text[i] == ']') { starttoken = false; strColor += ']'; if (strColor.Length == 8) { strColor = strColor.Replace("[", "<color value=\"#"); strColor = strColor.Replace("]", "\">"); stringBuilder.Append(strColor); } else if (strColor.Length == 3) { strColor = strColor.Replace("[-]", "</color>"); stringBuilder.Append(strColor); } else { stringBuilder.Append(strColor); } strColor = ""; } else { starttoken = false; strColor += text[i]; stringBuilder.Append(strColor); } } else if (text[i] == '[') { strColor = "["; starttoken = true; } else { starttoken = false; stringBuilder.Append(text[i]); } } talk.strText = stringBuilder.ToString(); } data.lstTalks.Add(talk); break; } continue; } } } } else { Engine.Utility.Log.Error("Not Found LangTextDataBase id {0}", cmd.txt_id); } return(data); }