void ClickSendMessageBtn() { if (inputText.text.Trim() == null || inputText.text.Trim() == "") { return; } GameObject tempChatItem = Instantiate(goprefab) as GameObject; tempChatItem.transform.parent = goContent.transform; tempChatItem.transform.localScale = Vector3.one; InlieSpriteText tempChatText = tempChatItem.transform.FindChild("Text").GetComponent <InlieSpriteText>(); #region 解析输入表情正则 string _TempInputText = ""; int _TempMatchIndex = 0; foreach (Match match in m_inputTagRegex.Matches(inputText.text.Trim())) { _TempInputText += inputText.text.Trim().Substring(_TempMatchIndex, match.Index - _TempMatchIndex); _TempInputText += "<quad name=" + match.Groups[1].Value + " size=56 width=1" + " />"; _TempMatchIndex = match.Index + match.Length; } _TempInputText += inputText.text.Trim().Substring(_TempMatchIndex, inputText.text.Trim().Length - _TempMatchIndex); #endregion tempChatText.text = _TempInputText; if (tempChatText.preferredWidth + 20.0f < 105.0f) { tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(105.0f, tempChatText.preferredHeight + 50.0f); } else if (tempChatText.preferredWidth + 20.0f > tempChatText.rectTransform.sizeDelta.x) { tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.rectTransform.sizeDelta.x + 20.0f, tempChatText.preferredHeight + 50.0f); } else { tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.preferredWidth + 20.0f, tempChatText.preferredHeight + 50.0f); } tempChatItem.SetActive(true); tempChatText.SetVerticesDirty(); tempChatItem.GetComponent <RectTransform>().anchoredPosition = new Vector3(-10.0f, -chatHeight); chatHeight += tempChatText.preferredHeight + 50.0f + PlayerHight + 10.0f; if (chatHeight > goContent.GetComponent <RectTransform>().sizeDelta.y) { goContent.GetComponent <RectTransform>().sizeDelta = new Vector2(goContent.GetComponent <RectTransform>().sizeDelta.x, chatHeight); } //while (scrollbarVertical.value > 0.01f) //{ // scrollbarVertical.value = 0.0f; //} isAddMessage = true; inputText.text = ""; }
void AutoTalk() { string[] emojiTextName = new string[] { "sick", "watermelon", "run", "die", "angry", "bleeding", "nurturing", "idle" }; string strTalk = "按下F1,我会自动说话:<quad name=" + emojiTextName[Random.Range(0, emojiTextName.Length)] + " size=56 width=1 />,show一个emoji"; GameObject tempChatItem = Instantiate(goprefab_left) as GameObject; tempChatItem.transform.parent = goContent.transform; tempChatItem.transform.localScale = Vector3.one; InlieSpriteText tempChatText = tempChatItem.transform.FindChild("Text").GetComponent <InlieSpriteText>(); tempChatText.text = strTalk; if (tempChatText.preferredWidth + 20.0f < 105.0f) { tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(105.0f, tempChatText.preferredHeight + 50.0f); } else if (tempChatText.preferredWidth + 20.0f > tempChatText.rectTransform.sizeDelta.x) { tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.rectTransform.sizeDelta.x + 20.0f, tempChatText.preferredHeight + 50.0f); } else { tempChatItem.GetComponent <RectTransform>().sizeDelta = new Vector2(tempChatText.preferredWidth + 20.0f, tempChatText.preferredHeight + 50.0f); } tempChatItem.SetActive(true); tempChatText.SetVerticesDirty(); tempChatItem.GetComponent <RectTransform>().anchoredPosition = new Vector3(10.0f, -chatHeight); chatHeight += tempChatText.preferredHeight + 50.0f + PlayerHight + 10.0f; if (chatHeight > goContent.GetComponent <RectTransform>().sizeDelta.y) { goContent.GetComponent <RectTransform>().sizeDelta = new Vector2(goContent.GetComponent <RectTransform>().sizeDelta.x, chatHeight); } //while (scrollbarVertical.value > 0.01f) //{ // scrollbarVertical.value = 0.0f; //} isAddMessage = true; }
void Awake() { _text = GetComponent <InlieSpriteText>(); }