Example #1
0
            public override void Render(VertexHelper vh, Rect area, Vector2 offset, float pixelsPerUnit)
            {
                var   node         = Node;
                Color currentColor = node.currentColor;

                if (currentColor.a <= 0.01f)
                {
                    return;
                }

                int   start         = vh.currentIndexCount;
                float unitsPerPixel = 1f / pixelsPerUnit;

                Vector2 leftBottomPos = GetStartLeftBottom(unitsPerPixel) + offset;

                Tools.LB2LT(ref leftBottomPos, area.height);

                // 渲染文本
                float minY = float.MaxValue;
                float maxY = float.MinValue;
                {
                    //leftPos = Vector2.zero;
                    Font      font     = node.d_font;
                    FontStyle fs       = node.d_fontStyle;
                    int       fontSize = (int)((node.d_fontSize * pixelsPerUnit));
                    font.RequestCharactersInTexture(text, fontSize, fs);
                    Vector2 startPos = Vector2.zero;
                    for (int i = 0; i < text.Length; ++i)
                    {
                        if (font.GetCharacterInfo(text[i], out s_Info, fontSize, fs))
                        {
                            int startVertCount = vh.currentVertCount;

                            Rect cr = Rect.MinMaxRect(
                                leftBottomPos.x + ((startPos.x + s_Info.minX) * unitsPerPixel),
                                leftBottomPos.y + ((startPos.y + s_Info.minY) * unitsPerPixel),
                                leftBottomPos.x + ((startPos.x + s_Info.maxX) * unitsPerPixel),
                                leftBottomPos.y + ((startPos.y + s_Info.maxY) * unitsPerPixel));

                            vh.AddVert(new Vector3(cr.xMin, cr.yMax), currentColor, s_Info.uvTopLeft);
                            vh.AddVert(new Vector3(cr.xMax, cr.yMax), currentColor, s_Info.uvTopRight);
                            vh.AddVert(new Vector3(cr.xMax, cr.yMin), currentColor, s_Info.uvBottomRight);
                            vh.AddVert(new Vector3(cr.xMin, cr.yMin), currentColor, s_Info.uvBottomLeft);

                            vh.AddTriangle(startVertCount + 0, startVertCount + 1, startVertCount + 2);
                            vh.AddTriangle(startVertCount + 2, startVertCount + 3, startVertCount + 0);

                            startPos.x += (s_Info.advance);

                            minY = Mathf.Min(cr.yMin, minY);
                            maxY = Mathf.Max(cr.yMax, maxY);
                        }
                    }
                }

                bool isset = false;

                if (node.d_bDynUnderline || node.d_bUnderline)
                {
                    isset = true;
                    node.GetLineCharacterInfo(out s_Info);

                    Vector2 startpos = new Vector2(leftBottomPos.x, minY);

                    if (node.d_bDynUnderline)
                    {
                        Texture     mainTexture = node.d_font.material.mainTexture;
                        OutlineDraw draw        = node.owner.GetDraw(DrawType.Outline, node.keyPrefix + mainTexture.GetInstanceID(), (Draw d, object p) =>
                        {
                            OutlineDraw od = d as OutlineDraw;
                            od.isOpenAlpha = node.d_bBlink;
                            od.texture     = mainTexture;
                        }) as OutlineDraw;

                        draw.AddLine(node, startpos, rect.width, line_height * unitsPerPixel, currentColor, s_Info.uv.center, node.d_dynSpeed);
                    }
                    else
                    {
                        Tools.AddLine(vh, startpos, s_Info.uv.center, rect.width, line_height * unitsPerPixel, currentColor);
                    }
                }

                if (node.d_bDynStrickout || node.d_bStrickout)
                {
                    if (!isset)
                    {
                        isset = true;
                        node.GetLineCharacterInfo(out s_Info);
                    }

                    Vector2 startpos = new Vector2(leftBottomPos.x, (maxY + minY) * 0.5f + line_height * 0.5f * unitsPerPixel);

                    if (node.d_bDynStrickout)
                    {
                        Texture     mainTexture = node.d_font.material.mainTexture;
                        OutlineDraw draw        = node.owner.GetDraw(DrawType.Outline, node.keyPrefix + mainTexture.GetInstanceID(), (Draw d, object p) =>
                        {
                            OutlineDraw od = d as OutlineDraw;
                            od.isOpenAlpha = node.d_bBlink;
                            od.texture     = mainTexture;
                        }) as OutlineDraw;
                        draw.AddLine(node, startpos, rect.width, line_height * unitsPerPixel, currentColor, s_Info.uv.center, node.d_dynSpeed);
                    }
                    else
                    {
                        Tools.AddLine(vh, startpos, s_Info.uv.center, rect.width, line_height * unitsPerPixel, currentColor);
                    }
                }

                switch (node.effectType)
                {
                case EffectType.Outline:
                    Effect.Outline(vh, start, node.effectColor, node.effectDistance);
                    break;

                case EffectType.Shadow:
                    Effect.Shadow(vh, start, node.effectColor, node.effectDistance);
                    break;
                }
            }