SpriteGraphic FindGraphic(InlineText text, SpriteAsset matchAsset, out List <SpriteGraphic> list) { EmojiTools.BeginSample("Emoji_UnitFindGraphic"); if (textGraphics == null) { textGraphics = new Dictionary <InlineText, List <SpriteGraphic> >(); } if (!textGraphics.TryGetValue(text, out list)) { list = ListPool <SpriteGraphic> .Get(); textGraphics[text] = list; } SpriteGraphic target = null; for (int i = 0; i < list.Count; ++i) { SpriteGraphic graphic = list[i]; if (graphic && UnityEngine.Object.ReferenceEquals(graphic.mainTexture, matchAsset.texSource)) { target = graphic; break; } } EmojiTools.EndSample(); return(target); }
void RemoveInText(InlineText text) { if (alltexts != null) { alltexts.Remove(text); } }
SpriteGraphic FindGraphic(InlineText text, int atlasID, out SpriteAsset matchAsset) { matchAsset = null; for (int i = 0; i < allatlas.Count; ++i) { SpriteAsset asset = allatlas[i]; if (asset != null && asset.ID == atlasID) { matchAsset = asset; break; } } if (matchAsset && matchAsset.texSource != null) { List <SpriteGraphic> list = null; SpriteGraphic target = FindGraphic(text, matchAsset, out list); if (!target) { target = CreateSpriteRender(text.transform); list.Add(target); } return(target); } return(null); }
public void DoParse(InlineText text, StringBuilder fillbuilder, string content) { if (_parsers.Count > 0) { MatchCollection matches = _tagRegex.Matches(content); if (matches.Count > 0) { bool needfix = false; int index = 0; for (int m = 0; m < matches.Count; ++m) { Match matchstr = matches[m]; fillbuilder.Append(content.Substring(index, matchstr.Index - index)); index = matchstr.Index + matchstr.Length; for (int i = 0; i < _parsers.Count; ++i) { var parser = _parsers[i]; if (parser.ParsetContent(text, fillbuilder, matchstr, m)) { parser.Hot++; if (parser.Hot > hot) { needfix = true; } } } if (m == matches.Count - 1) { fillbuilder.Append(content.Substring(matchstr.Index + matchstr.Length)); } } //reset and fix if (needfix && this._parsers.Count > 1) { this._parsers.Sort(SortList); } // for (int i = 0; i < _parsers.Count; ++i) { var parser = _parsers[i]; parser.Hot = 0; } } else { fillbuilder.Append(content); } } else { fillbuilder.Append(content); } }
internal void CancelRebuild(InlineText text) { if (_feature != null && _feature.Context.RebuildTexts.Remove(text) && _feature.Context.RebuildTexts.Count == 0) { CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this); } }
void FillPart(InlineText text, string context, int start, int end, ref ParseTextResult result) { string substr = context.Substring(start, end - start + 1); //生成字符 拿到字符大小 Vector2 extents = text.rectTransform.rect.size; var settings = text.GetGenerationSettings(extents); text.cachedTextGenerator.PopulateWithErrors(substr, settings, text.gameObject); //最后4个点是空行 var charlist = text.cachedTextGenerator.characters; //插入点之后文字所占用的宽度 for (int i = 0; i < text.cachedTextGenerator.characterCountVisible; i++) { var chardata = charlist[i]; result.GetPartSize().Add(chardata.charWidth); } if (text.Manager != null && text.Manager.OpenDebug) { #if UNITY_EDITOR Debug.LogFormat("{0} point ={1}", substr, start); #endif } }
bool ParseElement(InlineText text, string info, ref TextCotext context, out int atlasId, out string tagKey) { atlasId = -1; tagKey = null; int index = info.IndexOf('#'); //parse element if (index != -1) { string subId = info.Substring(1, index - 1); if (subId.Length > 0 && !int.TryParse(subId, out atlasId)) { #if UNITY_EDITOR Debug.LogErrorFormat("{0} convert failed ", subId); #endif context.FailedText.Add(text); return(false); } else if (subId.Length == 0) { atlasId = 0; } tagKey = info.Substring(index, info.Length - index - 2 + 1); } else { tagKey = info.Substring(1, info.Length - 2); } return(true); }
void FillSpriteTag(InlineText text, StringBuilder stringBuilder, Match match, int matchindex, int atlasId, string atlasTag) { if (text.Manager != null && text.Manager.CanRendering(atlasId) && text.Manager.CanRendering(atlasTag)) { SpriteAsset sprAsset; SpriteInfoGroup tagSprites = text.Manager.FindSpriteGroup(atlasTag, out sprAsset); if (tagSprites != null && tagSprites.spritegroups.Count > 0) { if (!text.Manager.isRendering(sprAsset)) { text.Manager.PushRenderAtlas(sprAsset); } if (_SpaceGen == null) { _SpaceGen = new TextGenerator(); } if (cacheframecnt != Time.frameCount || cachetext != text) { cacheframecnt = Time.frameCount; cachetext = text; Vector2 extents = text.rectTransform.rect.size; TextGenerationSettings settings = text.GetGenerationSettings(extents); _SpaceGen.Populate(palceholder, settings); } IList <UIVertex> spaceverts = _SpaceGen.verts; float spacewid = spaceverts[1].position.x - spaceverts[0].position.x; float spaceheight = spaceverts[0].position.y - spaceverts[3].position.y; float autosize = Mathf.Min(tagSprites.size, Mathf.Max(spacewid, spaceheight)); float spacesize = Mathf.Min(spacewid, spaceheight); int fillspacecnt = Mathf.RoundToInt(autosize / spacesize); for (int i = 0; i < fillspacecnt; i++) { stringBuilder.Append(palceholder); } if (fillspacecnt > 0) { SpriteTagInfo tempSpriteTag = new SpriteTagInfo(); tempSpriteTag.ID = atlasId; tempSpriteTag.Tag = atlasTag; tempSpriteTag.Size = new Vector2(autosize, autosize); tempSpriteTag.pos = new Vector3[4]; tempSpriteTag.uv = tagSprites.spritegroups[0].uv; tempSpriteTag.FillIdxAndPlaceHolder(stringBuilder.Length * 4 - 1, matchindex, fillspacecnt); text.AddFillData(tempSpriteTag); } } } }
Graphic Parse(InlineText text, IFillData taginfo, List <string> joblist) { if (taginfo != null) { return(ParsePosAndUV(text, taginfo.ID, taginfo.pos, taginfo.uv, joblist)); } return(null); }
SpriteGraphic Parse(InlineText text, IFillData taginfo) { if (taginfo != null) { return(ParsePosAndUV(text, taginfo.ID, taginfo.pos, taginfo.uv)); } return(null); }
internal void Rebuild(InlineText text) { if (_feature != null && _feature.Context.RebuildTexts.Contains(text) == false) { _feature.Context.RebuildTexts.Add(text); CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this); } }
public bool Dirty(InlineText text) { if (text != null) { Transform trans = text.transform; return(trans.position != worldpos || trans.rotation != worldquat || trans.localScale != scale); } return(false); }
/// <summary> /// 移除文本 /// </summary> /// <param name="_id"></param> /// <param name="_key"></param> public void UnRegister(InlineText _key) { EmojiTools.BeginSample("Emoji_UnRegister"); if (_render != null) { _render.DisRendering(_key); } EmojiTools.EndSample(); }
public void RenderEmoji(InlineText text, Texture texture, ref UIMeshGroup mesh) { _texture = texture; _cachetext = text; _meshgroup = mesh; _rendering = true; SetVerticesDirty(); }
void RefreshSubUIMesh(InlineText text, SpriteGraphic target, SpriteAsset matchAsset, Vector3[] Pos, Vector2[] UV) { // set mesh tempMesh.SetAtlas(matchAsset); tempMesh.SetUVLen(UV.Length); tempMesh.SetVertLen(Pos.Length); for (int i = 0; i < Pos.Length; ++i) { //text object pos Vector3 value = Pos[i]; Vector3 worldpos = text.transform.TransformPoint(value); Vector3 localpos = target.transform.InverseTransformPoint(worldpos); tempMesh.SetVert(i, localpos); } for (int i = 0; i < UV.Length; ++i) { Vector2 value = UV[i]; tempMesh.SetUV(i, value); } //rendermesh UnitMeshInfo currentMesh = null; if (!this.renderData.TryGetValue(target, out currentMesh)) { currentMesh = new UnitMeshInfo(); renderData[target] = currentMesh; } if (!currentMesh.Equals(tempMesh)) { if (target.isDirty) { currentMesh.AddCopy(tempMesh); tempMesh.Clear(); } else { currentMesh.Copy(tempMesh); } } if (currentMesh.VertCnt() > 3 && currentMesh.UVCnt() > 3) { target.Draw(this); target.SetDirtyMask(); target.SetVerticesDirty(); } else { target.Draw(null); target.SetDirtyMask(); target.SetVerticesDirty(); } }
public void DisRendering(InlineText text) { RemoveInText(text); if (rebuildqueue != null && !rebuildqueue.Contains(text)) { rebuildqueue.Add(text); } }
public void Set(InlineText text) { if (text != null) { Transform trans = text.transform; this.worldpos = trans.position; this.worldquat = trans.rotation; this.scale = trans.localScale; } }
void AddInText(InlineText text) { if (alltexts == null) { alltexts = ListPool <InlineText> .Get(); } if (!alltexts.Contains(text)) { alltexts.Add(text); } }
void MarkDirtyStaticEmoji() { if (alltexts != null && alltexts.Count > 0) { if (listeners == null) { listeners = new Dictionary <InlineText, ListenerData>(); } for (int i = 0; i < alltexts.Count; ++i) { InlineText text = alltexts[i]; List <IFillData> emojidata = text.PopEmojiData(); if (text != null && emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0) { bool isdirty = false; ListenerData data = null; if (listeners.TryGetValue(text, out data)) { isdirty = data.Dirty(text); if (isdirty) { data.Set(text); } } else { data = new ListenerData(); data.Set(text); listeners.Add(text, data); } int staticcnt = 0; for (int j = 0; j < emojidata.Count; ++j) { IFillData taginfo = emojidata[j]; SpriteAsset asset = null; SpriteInfoGroup groupinfo = manager.FindSpriteGroup(taginfo.Tag, out asset); if (groupinfo != null && groupinfo.spritegroups.Count == 1) { staticcnt++; } } if (staticcnt > 0 && isdirty) { this.TryRendering(text); } } } } }
void RefreshSubUIMesh(InlineText text, CanvasGraphicGroup group, SpriteAsset matchAsset, Vector3[] Pos, Vector2[] UV, List <string> joblist) { // set mesh tempMesh.SetAtlas(matchAsset); tempMesh.SetUVLen(UV.Length); tempMesh.SetVertLen(Pos.Length); SpriteGraphic graphic = group.graphic; //think about culling and screen coordinate....... for (int i = 0; i < Pos.Length; ++i) { //text object pos Vector3 value = Pos[i]; Vector3 worldpos = text.transform.TransformPoint(value); Vector3 localpos = group.graphic.transform.InverseTransformPoint(worldpos); tempMesh.SetVert(i, localpos); } for (int i = 0; i < UV.Length; ++i) { Vector2 value = UV[i]; tempMesh.SetUV(i, value); } //rendermesh UnitMeshInfo currentMesh = group.mesh; if (!currentMesh.Equals(tempMesh)) { if (joblist != null && joblist.Count > 0) { currentMesh.AddCopy(tempMesh); tempMesh.Clear(); } else { currentMesh.Copy(tempMesh); } } if (currentMesh.VertCnt() > 3 && currentMesh.UVCnt() > 3) { graphic.Draw(this); } else { graphic.Draw(null); } group.isDirty = true; }
internal void Remove(InlineText text) { if (_feature != null) { CancelRebuild(text); int idx = _feature.Context.AllTexts.IndexOf(text); if (idx != -1) { _feature.Context.AllTexts.RemoveAt(idx); _feature.Context.Results.RemoveAt(idx); } } }
public IEmojiRender Register(InlineText _key) { EmojiTools.BeginSample("Emoji_Register"); if (_render != null) { if (_render.TryRendering(_key)) { EmojiTools.EndSample(); return(_render); } } EmojiTools.EndSample(); return(null); }
Graphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV, List <string> joblist) { EmojiTools.BeginSample("Emoji_GroupParsePosAndUV"); SpriteAsset matchAsset = null; for (int i = 0; i < allatlas.Count; ++i) { SpriteAsset asset = allatlas[i]; if (asset != null && asset.ID == ID) { matchAsset = asset; break; } } if (matchAsset && matchAsset.texSource != null) { CanvasGraphicGroup group = FindGraphicGroup(text.canvas, matchAsset.ID); if (group == null) { group = new CanvasGraphicGroup(); group.AtlasID = matchAsset.ID; group.canvas = text.canvas; group.mesh = UnitMeshInfoPool.Get(); group.isDirty = false; group.graphic = CreateSpriteRender(); if (GraphicTasks == null) { GraphicTasks = new List <CanvasGraphicGroup>(); } GraphicTasks.Add(group); } RefreshSubUIMesh(text, group, matchAsset, Pos, UV, joblist); EmojiTools.EndSample(); return(group.graphic); } else { Debug.LogErrorFormat("missing {0} atlas", ID); } EmojiTools.EndSample(); return(null); }
public bool TryRendering(InlineText text) { AddInText(text); if (rebuildqueue == null) { rebuildqueue = ListPool <InlineText> .Get(); } if (!rebuildqueue.Contains(text)) { rebuildqueue.Add(text); return(true); } return(false); }
public int DoStep(ref TextCotext context, EmojiEvent uievent) { if (uievent == EmojiEvent.PreRender) { for (int i = 0; i < context.AllTexts.Count; i++) { InlineText text = context.AllTexts[i]; if (text == null) { continue; } if (!context.RebuildTexts.Contains(text)) { continue; } _cache.Clear(); TextElementResult result = context.Results[i]; //if (result.ParseGroup.emojitypeMap == null) // result.ParseGroup.emojitypeMap = new Dictionary<int, int>(); //else //result.ParseGroup.emojitypeMap.Clear(); int val = 0; for (int k = 0; k < result.ParseGroup.fillplacemap.Count; k++) { val += result.ParseGroup.fillplacemap[k]; _cache[k] = val; } //emoji FixPoints(result.ParseGroup.EmojiResult.GetEmojiPoints(), 1, ref result); //href FixPoints(result.ParseGroup.HrefResult.GetHrefPoints(), 2, ref result); context.Results[i] = result; } } return(0); }
internal bool GetParseGroup(InlineText text, out ParseGroup mesh) { if (_feature != null) { var resultlist = _feature.Context.Results; for (int i = 0; i < resultlist.Count; i++) { var info = resultlist[i]; if (info.RenderId == text.GetHashCode()) { mesh = info.ParseGroup; return(true); } } } mesh = default(ParseGroup); return(false); }
public int DoStep(ref TextCotext context, EmojiEvent uievent) { if (uievent == EmojiEvent.PreRender) { int errcode = 0; for (int i = 0; i < context.AllTexts.Count; i++) { InlineText text = context.AllTexts[i]; if (text == null) { continue; } if (!context.RebuildTexts.Contains(text)) { continue; } TextElementResult result = context.Results[i]; result.MeshGroup.TextMeshResult.Init(); result.GizmosResult.Clear(); //text string currenttext = null; if (result.ParseGroup.TextResult.FormatElements != null && result.ParseGroup.TextResult.FormatElements.Count > 0) { currenttext = result.ParseGroup.TextResult.FormatString; } else { currenttext = text.text; } errcode = FillText(text, currenttext, ref context, ref result); context.Results[i] = result; } return(errcode); } return(0); }
public bool ParsetContent(InlineText text, StringBuilder textfiller, Match data, int matchindex) { string value = data.Value; if (!string.IsNullOrEmpty(value)) { int index = value.IndexOf('#'); int atlasId = 0; string tagKey = null; if (index != -1) { string subId = value.Substring(1, index - 1); if (subId.Length > 0 && int.TryParse(subId, out atlasId)) { //Debug.LogErrorFormat("{0} convert success ", subId); } else if (subId.Length > 0) { atlasId = -1; } else if (subId.Length == 0) { atlasId = 0; } tagKey = value.Substring(index + 1, value.Length - index - 2); FillSpriteTag(text, textfiller, data, matchindex, atlasId, tagKey); } else { tagKey = value.Substring(1, value.Length - 2); FillSpriteTag(text, textfiller, data, matchindex, atlasId, tagKey); } return(true); } return(false); }
SpriteGraphic ParsePosAndUV(InlineText text, int ID, Vector3[] Pos, Vector2[] UV) { EmojiTools.BeginSample("Emoji_UnitParsePosAndUV"); SpriteAsset matchAsset = null; for (int i = 0; i < allatlas.Count; ++i) { SpriteAsset asset = allatlas[i]; if (asset != null && asset.ID == ID) { matchAsset = asset; break; } } if (matchAsset && matchAsset.texSource != null) { List <SpriteGraphic> list = null; SpriteGraphic target = FindGraphic(text, matchAsset, out list); if (!target) { target = CreateSpriteRender(text.transform); list.Add(target); } RefreshSubUIMesh(text, target, matchAsset, Pos, UV); EmojiTools.EndSample(); return(target); } else { Debug.LogErrorFormat("missing {0} atlas", ID); } EmojiTools.EndSample(); return(null); }
void Fill(InlineText target, SpriteInfoGroup group, int elementidx, ref float linesize, ref TextElementResult textresult, out int fillsize) { fillsize = 0; float spacesize = Mathf.Max(_placesize.x, _placesize.y); float minsize = Mathf.Min(group.size, Mathf.Min(_placesize.x, _placesize.y)); if (minsize > 0.1f) { float autosize = Mathf.Min(group.size, spacesize); int fillspacecnt = Mathf.CeilToInt(autosize / minsize);; if (target.horizontalOverflow != HorizontalWrapMode.Overflow && fillspacecnt > 0) { float wid = target.rectTransform.rect.width; float fillwidth = fillspacecnt * (minsize + _space); //填充字符之间穿插了换行的情况 进行检测 if (wid - linesize < fillwidth) { fillspacecnt = 1; linesize = 0; textresult.ParseGroup.EmojiResult.GetFixedIndex().Add(elementidx); } else { linesize += fillwidth; } } fillsize = fillspacecnt; textresult.ParseGroup.EmojiResult.GetEmojiSize().Add(autosize); textresult.ParseGroup.EmojiResult.GetGroups().Add(group); } }