示例#1
0
        static void AddVertex(float lx, float rx, float dy, float ty, ref HVertex vertex, ref CharacterInfoEx info)
        {
            vertex.position.x = lx;
            vertex.position.y = dy;
            vertex.uv         = info.info.uvBottomLeft;
            vertices.Add(vertex);

            vertex.position.x = lx;
            vertex.position.y = ty;
            vertex.uv         = info.info.uvTopLeft;
            vertices.Add(vertex);

            vertex.position.x = rx;
            vertex.position.y = ty;
            vertex.uv         = info.info.uvTopRight;
            vertices.Add(vertex);

            vertex.position.x = rx;
            vertex.position.y = dy;
            vertex.uv         = info.info.uvBottomRight;
            vertices.Add(vertex);
        }
示例#2
0
        /// <summary>
        /// 刷新顶点
        /// </summary>
        public void Refresh()
        {
            if (FontSize <= 0)
            {
                return;
            }
            if (text == null)
            {
                return;
            }
            float line   = FontSize * 1.25f;
            var   size   = SizeDelta;
            float endx   = size.x * 0.5f;
            float startx = -endx;
            float starty = size.y * 0.5f;
            float endy   = -starty;

            char[] tmp = text.ToArray();
            vert = new List <HVertex>();
            tri  = new List <int>();
            float dx = GetLineStart(tmp, 0, size.x);
            float dy = starty;

            for (int i = 0; i < tmp.Length; i++)
            {
                var c = tmp[i];
                if (buffer.ContainsKey(c))
                {
                    UVRect uv = buffer[c];
                    float  w  = uv.Scale.x * FontSize;
                    float  h  = uv.Scale.y * FontSize;
                    label :;
                    float x0 = dx;
                    float y0 = dy - h;
                    float x1 = dx + w;
                    float y1 = dy;
                    if (y0 < endy)
                    {
                        break;
                    }
                    if (x1 > endx)
                    {
                        dy -= line;
                        dx  = GetLineStart(tmp, i, size.x);
                        goto label;
                    }
                    int start = vert.Count;
                    var v     = new HVertex();
                    v.position.x = x0;
                    v.position.y = y0;
                    v.uv         = uv.uv0;
                    vert.Add(v);
                    v.position.x = x0;
                    v.position.y = y1;
                    v.uv         = uv.uv1;
                    vert.Add(v);
                    v.position.x = x1;
                    v.position.y = y0;
                    v.uv         = uv.uv2;
                    vert.Add(v);
                    v.position.x = x1;
                    v.position.y = y1;
                    v.uv         = uv.uv3;
                    vert.Add(v);
                    tri.Add(start);
                    tri.Add(start + 1);
                    tri.Add(start + 2);
                    tri.Add(start + 2);
                    tri.Add(start + 1);
                    tri.Add(start + 3);
                    dx += w;
                }
            }
        }
示例#3
0
        static void CreateEmojiMesh(HText text)
        {
            if (text.verts == null)
            {
                return;
            }
            bufferA.Clear();
            bufferB.Clear();
            var emojis = text.emojiString.emojis;
            var str    = text.emojiString.FilterString;
            var verts  = text.verts;
            int c      = verts.Length;

            if (c == 0)
            {
                text.vertices = null;
                text.tris     = null;
                return;
            }
            HVertex[] hv = new HVertex[c];

            int e = c / 4;

            for (int i = 0; i < c; i++)
            {
                hv[i].position = verts[i].position;
                hv[i].color    = verts[i].color;
                hv[i].uv       = verts[i].uv0;
                hv[i].uv4.x    = 1;
                hv[i].uv4.y    = 1;
            }
            if (emojis.Count > 0)
            {
                var   info = emojis[0];
                Color col  = Color.white;
                int   p    = 0;
                int   si   = 0;
                int   len  = str.Length;
                for (int i = 0; i < len; i++)
                {
                    bool yes = true;

                    for (int j = 0; j < key_noMesh.Length; j++)
                    {
                        if (key_noMesh[j] == str[i])
                        {
                            yes = false;
                            break;
                        }
                    }
                    if (yes)
                    {
                        if (i == info.pos)
                        {
                            int o = p * 4;
                            hv[o].uv      = info.uv[0];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            o++;
                            hv[o].uv      = info.uv[1];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            o++;
                            hv[o].uv      = info.uv[2];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            o++;
                            hv[o].uv      = info.uv[3];
                            hv[o].color   = col;
                            hv[o].picture = 1;
                            si++;
                            if (si < emojis.Count)
                            {
                                info = emojis[si];
                            }
                            int s = p * 4;
                            bufferB.Add(s);
                            bufferB.Add(s + 1);
                            bufferB.Add(s + 2);
                            bufferB.Add(s + 2);
                            bufferB.Add(s + 3);
                            bufferB.Add(s);
                        }
                        else
                        {
                            int s = p * 4;
                            bufferA.Add(s);
                            bufferA.Add(s + 1);
                            bufferA.Add(s + 2);
                            bufferA.Add(s + 2);
                            bufferA.Add(s + 3);
                            bufferA.Add(s);
                        }
                        p++;
                        if (p >= e)
                        {
                            break;
                        }
                    }
                }
                if (bufferB.Count > 0)
                {
                    if (text.subTris == null)
                    {
                        text.subTris = new int[2][];
                    }
                    text.subTris[0] = bufferA.ToArray();
                    text.subTris[1] = bufferB.ToArray();
                    text.tris       = null;
                }
                else
                {
                    text.tris    = bufferA.ToArray();
                    text.subTris = null;
                }
            }
            else
            {
                text.tris    = CreateTri(c);
                text.subTris = null;
            }
            text.vertices = hv;
        }
示例#4
0
        static void LayoutLine(int index, float startX, float startY)
        {
            var line = lineInfos[index];

            lineInfos[index].topY = startY;
            float   down   = lineInfos[index].downY = startY - line.High;
            float   sy     = down + line.minY + 0.24f * line.High;
            float   sx     = startX;
            HVertex vertex = new HVertex();

            for (int i = line.CharStart; i <= line.CharEnd; i++)
            {
                var   ci = characters[i];
                float sw = ci.info.glyphWidth;
                float rx = sw * 0.5f;
                float cx = ci.info.minX + rx;
                rx *= 0.95f;//给光标留间隙
                float lx = -rx;
                lx += sx + cx;
                rx += sx + cx;
                if (ci.type > -2)//有网格
                {
                    int c = vertices.Count;
                    vertex.uv4.x = 1;
                    vertex.uv4.y = 1;
                    if (ci.type == -1)//表情符
                    {
                        vertex.picture   = 1;
                        vertex.fillColor = 0.2f;
                        AddTris(Triangle2, c);
                    }
                    else if (ci.type == 1)//自定义字符
                    {
                        vertex.picture   = 2;
                        vertex.fillColor = 0.2f;
                        AddTris(Triangle3, c);
                    }
                    else
                    {
                        vertex.picture   = 0;
                        vertex.fillColor = 0.1f;
                        AddTris(Triangle1, c);
                    }

                    vertex.color = ci.color;

                    float dy = ci.info.minY - line.minY;
                    float ty = ci.info.maxY - line.minY;
                    ty *= 0.95f;
                    dy *= 0.95f;
                    ty += sy;
                    dy += sy;
                    characters[i].VertexIndex = vertices.Count / 4;
                    AddVertex(lx, rx, dy, ty, ref vertex, ref ci);
                    sx += ci.info.advance;
                }
                else
                {
                    sx += ci.info.advance;
                    characters[i].VertexIndex = -1;
                }
                characters[i].Left   = lx;
                characters[i].Right  = rx;
                characters[i].Center = (rx - lx) * 0.5f + lx;
            }
            lineInfos[index].Left  = startX;
            lineInfos[index].Right = sx;
        }