Beispiel #1
0
        public const char emSpace = '@';//'\u2001';☀@
        /// <summary>
        /// 检查字符串中的表情符,并替换位@符号
        /// </summary>
        /// <param name="str">源字符串</param>
        /// <param name="list">所包含表情符列表</param>
        /// <returns>替换后的额字符串</returns>
        public static string CheckEmoji(string str, List <EmojiInfo> list)
        {
            if (str == "" | str == null)
            {
                return(str);
            }
            StringBuilder sb = new StringBuilder();

            char[] cc  = str.ToCharArray();
            int    i   = 0;
            int    len = cc.Length;
            int    pos = 0;

            while (i < len)
            {
                char   c = cc[i];
                UInt16 v = (UInt16)c;
                if (v < 0x8cff)
                {
                    if (v >= 0x2600 & v <= 0x27bf)
                    {
                        var pst = new EmojiInfo();
                        pst.chr = new string(c, 1);
                        pst.uv  = new Vector2[4];
                        FindEmoji(cc, i, pst.uv);
                        pst.pos = pos;
                        list.Add(pst);
                        sb.Append(emSpace);
                    }
                    else
                    {
                        sb.Append(c);
                    }
                    i++;
                }
                else
                {
                    var pst = new EmojiInfo();
                    pst.pos = pos;
                    pst.uv  = new Vector2[4];
                    int a = FindEmoji(cc, i, pst.uv);
                    if (a > 0)
                    {
                        pst.chr = new string(cc, i, a);
                        i      += a;
                        list.Add(pst);
                        sb.Append(emSpace);
                    }
                    else
                    {
                        i++;
                        sb.Append(c);
                    }
                }
                pos++;
            }
            return(sb.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// 创建带有表情符的网格
        /// </summary>
        /// <param name="text"></param>
        protected static void CreateEmojiMesh(HText text)
        {
            if (text.TmpVerts.DataCount == 0)
            {
                text.vertInfo.DataCount  = 0;
                text.trisInfo.DataCount  = 0;
                text.trisInfo2.DataCount = 0;
                return;
            }
            bufferA.Clear();
            bufferB.Clear();
            var emojis = text.emojiString.emojis;
            var str    = text.emojiString.FilterString;
            var verts  = text.TmpVerts;
            int c      = verts.DataCount;

            text.tris = null;
            if (text.vertInfo.Size == 0)
            {
                text.vertInfo = VertexBuffer.RegNew(c);
            }
            else
            if (text.vertInfo.Size <c | text.vertInfo.Size> c + 32)
            {
                text.vertInfo.Release();
                text.vertInfo = VertexBuffer.RegNew(c);
            }
            var       emoji = text.emojiString;
            EmojiInfo info  = null;

            if (emoji.emojis.Count > 0)
            {
                info = emoji.emojis[0];
            }
            int     index = 0;
            int     e     = c / 4;
            int     ac    = 0;
            Color32 col   = Color.white;

            unsafe
            {
                HVertex *   hv  = text.vertInfo.Addr;
                TextVertex *src = verts.Addr;
                for (int i = 0; i < e; i++)
                {
                    int s  = i * 4;
                    int ss = ac;
                    int ti = src[s].Index;
                    for (int j = 0; j < 4; j++)
                    {
                        hv[ss].position = src[s].position;
                        hv[ss].color    = src[s].color;
                        hv[ss].uv       = src[s].uv;
                        hv[ss].uv4.x    = 1;
                        hv[ss].uv4.y    = 1;
                        hv[ss].picture  = 0;
                        s++;
                        ss++;
                    }
                    if (info != null)
                    {
                        if (ti > info.pos)
                        {
                            info = null;
                            for (int j = index; j < emoji.emojis.Count; j++)
                            {
                                if (emoji.emojis[j].pos >= ti)
                                {
                                    index = j;
                                    info  = emoji.emojis[j];
                                    break;
                                }
                            }
                        }
                        ss = ac;
                        if (info != null)
                        {
                            if (ti == info.pos)
                            {
                                AddTris(bufferB, ac);
                                hv[ss].uv      = info.uv[0];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[1];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[2];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[3];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                            }
                            else
                            {
                                AddTris(bufferA, ac);
                            }
                        }
                        else
                        {
                            AddTris(bufferA, ac);
                        }
                    }
                    else
                    {
                        AddTris(bufferA, ac);
                    }
                    ac += 4;
                }
            }
            text.vertInfo.DataCount = ac;
            ApplyTris(text);
        }