public void Insert(int index, EmojiString emoji) { if (index > m_str.Length) { index = m_str.Length; } var list = emoji.emojis; for (int i = 0; i < list.Count; i++) { list[i].pos += index; } string str = emoji.FilterString; builder.Insert(index, str); int l = str.Length; for (int i = 0; i < emojis.Count; i++)//将后面的表情符位置往后移 { if (emojis[i].pos >= index) { emojis[i].pos += l; } } emojis.AddRange(list); emojis.Sort((a, b) => { return(a.pos > b.pos ? 1 : -1); }); m_str = builder.ToString(); f_str = EmojiMap.EmojiToFullString(m_str, emojis); }
public static UIVertex[] CreateEmojiMesh(Text text, EmojiString emoji, ref TextGenerationSettings settings) { string str = emoji.FilterString; if (str != null & str != "") { text.cachedTextGenerator.Populate(str, settings); IList <UIVertex> verts = text.cachedTextGenerator.verts; if (verts.Count == 0) { return(null); } float unitsPerPixel = 1 / text.pixelsPerUnit; /// s Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel; /// s roundingOffset = text.PixelAdjustPoint(roundingOffset) - roundingOffset; var vs = CreateEmojiMesh(text.cachedTextGenerator.verts, emoji.emojis, text.fontSize, unitsPerPixel, roundingOffset); //*s return(vs); } return(null); }
public static List <UIVertex> CreateEmojiMesh(Text text, EmojiString emoji) { float s = Screen.dpi / NormalDpi; Vector2 extents = text.rectTransform.rect.size; var settings = text.GetGenerationSettings(extents * s); float t = settings.fontSize; t *= s; settings.fontSize = (int)t; t = settings.resizeTextMinSize; t *= s; settings.resizeTextMinSize = (int)t; t = settings.resizeTextMaxSize; t *= s; settings.resizeTextMaxSize = (int)t; string str = emoji.FilterString; if (str != null & str != "") { text.cachedTextGenerator.PopulateWithErrors(str, settings, text.gameObject); IList <UIVertex> verts = text.cachedTextGenerator.verts; if (verts.Count == 0) { return(null); } float unitsPerPixel = 1 / text.pixelsPerUnit / s; Vector2 roundingOffset = new Vector2(verts[0].position.x / s, verts[0].position.y / s) * unitsPerPixel; roundingOffset = text.PixelAdjustPoint(roundingOffset) - roundingOffset; var vs = CreateEmojiMesh(text.cachedTextGenerator.verts, emoji.emojis, text.fontSize * s, unitsPerPixel, roundingOffset); if (vs != null) { return(new List <UIVertex>(vs)); } } return(null); }