public void Render(VertexHelper vh, ref float curwidth) { int start = vh.currentIndexCount; Color c = color; if (c.a <= 0.01f) { return; } if (curwidth >= width) { // 完整显示 Tools.AddLine(vh, leftPos, uv, width, height, c); } else { Tools.AddLine(vh, leftPos, uv, curwidth, height, c); } switch (node.effectType) { case EffectType.Outline: c = node.effectColor; Effect.Outline(vh, start, c, node.effectDistance); break; case EffectType.Shadow: c = node.effectColor; Effect.Shadow(vh, start, c, node.effectDistance); break; } curwidth -= width; }
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; int wordspace = node.owner.wordSpacing; { //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; s_xMin = leftBottomPos.x + ((startPos.x + s_Info.minX) * unitsPerPixel); s_yMin = leftBottomPos.y + ((startPos.y + s_Info.minY) * unitsPerPixel); s_xMax = leftBottomPos.x + ((startPos.x + s_Info.maxX) * unitsPerPixel); s_yMax = leftBottomPos.y + ((startPos.y + s_Info.maxY) * unitsPerPixel); s_point.x = s_xMin; s_point.y = s_yMax; vh.AddVert(s_point, currentColor, s_Info.uvTopLeft); s_point.x = s_xMax; s_point.y = s_yMax; vh.AddVert(s_point, currentColor, s_Info.uvTopRight); s_point.x = s_xMax; s_point.y = s_yMin; vh.AddVert(s_point, currentColor, s_Info.uvBottomRight); s_point.x = s_xMin; s_point.y = s_yMin; vh.AddVert(s_point, 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 + wordspace; minY = Mathf.Min(s_yMin, minY); maxY = Mathf.Max(s_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, leftBottomPos.y - line_height); 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; } }