// 创建图片 private void CreateImage(Vector2 pos, string imageId) { Transform item = UIRichTextMgrNew.GetCacheImage(); m_userCacheImage.Add(item); UIRichTextMgrNew.ImageInfo iInfo = UIRichTextMgrNew.s_imageList[imageId]; if (iInfo.type == UIRichTextMgrNew.ImageType.playerInfo) { } else if (iInfo.type == UIRichTextMgrNew.ImageType.face) { string[] animaInfo = UIRichTextMgrNew.s_imageList[imageId].param.Split('_'); //UIImageAnima anima = UIImageAnima.Get(item.gameObject); //anima.enabled = true; //anima.Play((uint)UIAtlasID.icon_expression, int.Parse(animaInfo[0]), int.Parse(animaInfo[1])); //anima.m_fps = anima.m_endIndex - anima.m_startIndex + 1; } else if (iInfo.type == UIRichTextMgrNew.ImageType.item) { //UILoadImage comIcon = UILoadImage.Get(item.gameObject); //comIcon.Load(UIRichTextMgrNew.TwoStrToInt(imageId)); //// 因为用到缓存image,这里禁用动画 //UIImageAnima anima = UIImageAnima.Get(item.gameObject); //if(anima != null) // anima.enabled = false; } item.gameObject.SetActive(true); item.SetParent(m_parent); item.localPosition = pos; item.localScale = Vector3.one; // 图片比较大,所以在这里更新当前行的高度 item.GetComponent <RectTransform>().sizeDelta = new Vector2(iInfo.x, iInfo.y); }
public void ClearUI() { if (m_parent != null) { if (m_userCacheText.Count != 0) { for (int i = 0; i < m_userCacheText.Count; i++) { UIRichTextMgrNew.SetCacheText(m_userCacheText[i].transform); } m_userCacheText.Clear(); } for (int i = 0; i < m_userCacheImage.Count; i++) { UIRichTextMgrNew.SetCacheImage(m_userCacheImage[i].transform); } m_userCacheImage.Clear(); //else //{ // for (int i = 0; i < m_parent.childCount; i++) // { // UIRichTextMgrNew.SetCacheText(m_parent.GetChild(i)); // } //} } }
private void OnHoverLink(GameObject go, bool isHover) { if (UIEventListener.Get(go).parameter == null) { return; } string[] parenArray = UIEventListener.Get(go).parameter.ToString().Split('='); int type = int.Parse(parenArray[0]); string value = parenArray[1]; UIRichTextMgrNew.OnHoverLink(isHover, type, value); }
private void OnClickLink(GameObject go) { if (UIEventListener.Get(go).parameter == null) { return; } string[] parenArray = UIEventListener.Get(go).parameter.ToString().Split('='); if (parenArray.Length == 2) { int type = int.Parse(parenArray[0]); UIRichTextMgrNew.OnClickLink(type, parenArray[1]); } }
private void CreateLink(Vector2 pos, string info, string text) { Transform item = UIRichTextMgrNew.GetCacheText(); m_userCacheText.Add(item); item.SetParent(m_parent); item.localPosition = pos; item.localScale = Vector3.one; Text label = item.GetComponent <Text>(); label.font = m_text.font; label.fontSize = m_text.fontSize; // 根据不同的类型,创建不同组件 string[] infoArray = info.Split('='); string type = infoArray[0]; string data = infoArray[1]; if (type.Equals("color")) { if (label.raycastTarget) // 普通文本不需要点击 { label.raycastTarget = false; } label.text = "<color='#" + data + "'>" + text + "</color>"; } else if (type.Equals("link")) { if (!label.raycastTarget && m_isCanClick) { label.raycastTarget = true; } string[] linkArray = data.Split(':'); int tpye = int.Parse(linkArray[0]); string color = linkArray[2]; label.text = "<color='#" + color + "'>" + text + "</color>"; UIEventListener lis = UIEventListener.Get(item.gameObject); lis.onClick = OnClickLink; lis.parameter = tpye + "=" + linkArray[1]; lis.onHover = OnHoverLink; } label.rectTransform.sizeDelta = new Vector2(label.preferredWidth, label.preferredHeight); }
private void CrateText(Vector2 pos, string txt) { RectTransform item = UIRichTextMgrNew.GetCacheText().GetComponent <RectTransform>(); m_userCacheText.Add(item); item.SetParent(m_parent); item.localPosition = pos; item.localScale = Vector3.one; item.sizeDelta = Vector2.zero; Text label = item.GetComponent <Text>(); label.font = m_text.font; label.fontSize = m_text.fontSize; label.text = "<color='#" + m_defaultColor + "'>" + txt + "</color>"; if (label.raycastTarget) // 普通文本不需要点击 { label.raycastTarget = false; } }