bool ParseEmote(string str, int index) { Match match = s_RegexEmote.Match(str); if (match != Match.Empty) { var id = match.Groups[1].Value; if (!GameTable.EmoteDict.ContainsKey(id)) { return(false); } Emote emote = GameTable.EmoteDict[id]; string path = emote.emotePath; int frameCount = emote.frameCount; float fps = emote.fps; int width = emote.width; int height = emote.height; LRichElementAnim element = new LRichElementAnim(path, frameCount, width, height, fps, ""); elementDic.Add(index, element); return(true); } return(false); }
//public LRichText(InputType inputType):this() //{ // this.inputType = inputType; //} //=================================================================== //解析内部结构并生成相关GameObject的方法 //=================================================================== //将_richElements中的单个元素拆解为每个字符一个元素,这个时候是一字排开的状态 //_elemRenderArr中存放的所有元素的list void reloadData() { this.removeAllElements(); RectTransform rtran = this.GetComponent <RectTransform>(); //align if (alignType == RichAlignType.DESIGN_CENTER) { rtran.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); } else if (alignType == RichAlignType.LEFT_TOP) { rtran.GetComponent <RectTransform>().pivot = new Vector2(0f, 1f); } foreach (LRichElement elem in _richElements) { if (elem.type == RichType.TEXT) { LRichElementText elemText = elem as LRichElementText; char[] _charArr = elemText.txt.ToCharArray(); TextGenerator gen = new TextGenerator(); foreach (char strChar in _charArr) { LRenderElement rendElem = new LRenderElement(); rendElem.type = RichType.TEXT; rendElem.strChar = strChar.ToString(); rendElem.isOutLine = elemText.isOutLine; rendElem.isUnderLine = elemText.isUnderLine; rendElem.font = this.font; rendElem.fontSize = elemText.fontSize; rendElem.data = elemText.data; rendElem.color = elemText.color; TextGenerationSettings setting = new TextGenerationSettings(); setting.font = this.font; setting.fontSize = elemText.fontSize; setting.lineSpacing = 1; setting.scaleFactor = 1; setting.verticalOverflow = VerticalWrapMode.Overflow; setting.horizontalOverflow = HorizontalWrapMode.Overflow; rendElem.width = (int)gen.GetPreferredWidth(rendElem.strChar, setting); rendElem.height = (int)gen.GetPreferredHeight(rendElem.strChar, setting); _elemRenderArr.Add(rendElem); } } else if (elem.type == RichType.IMAGE) { LRichElementImage elemImg = elem as LRichElementImage; LRenderElement rendElem = new LRenderElement(); rendElem.type = RichType.IMAGE; rendElem.path = elemImg.path; rendElem.data = elemImg.data; //从配置直接传进来,不用再读取图片大小了 //Sprite sp = Resources.LoadAssetAtPath(AppConst.RawResPath + rendElem.path, typeof(Sprite)) as Sprite; rendElem.width = elemImg.width; rendElem.height = elemImg.height; _elemRenderArr.Add(rendElem); } else if (elem.type == RichType.ANIM) { LRichElementAnim elemAnim = elem as LRichElementAnim; LRenderElement rendElem = new LRenderElement(); rendElem.type = RichType.ANIM; rendElem.path = elemAnim.path; rendElem.data = elemAnim.data; rendElem.frameCount = elemAnim.frameCount; rendElem.fs = elemAnim.fs; //Sprite sp = Resources.LoadAssetAtPath(AppConst.RawResPath + rendElem.path + "/1", typeof(Sprite)) as Sprite; rendElem.width = elemAnim.width; rendElem.height = elemAnim.height; _elemRenderArr.Add(rendElem); } else if (elem.type == RichType.NEWLINE) { LRenderElement rendElem = new LRenderElement(); rendElem.isNewLine = true; _elemRenderArr.Add(rendElem); } } _richElements.Clear(); formarRenderers(); }