public override void Render(VertexHelper vh, Rect area, Vector2 offset, float pixelsPerUnit) { Color currentColor = node.d_color; if (currentColor.a <= 0.01f) { return; } var uv = UnityEngine.Sprites.DataUtility.GetOuterUV(sprite); Vector2 leftPos = GetStartLeftBottom(1f) + offset; Tools.LB2LT(ref leftPos, area.height); float width = rect.width; float height = rect.height; int count = vh.currentVertCount; vh.AddVert(new Vector3(leftPos.x, leftPos.y), currentColor, new Vector2(uv.x, uv.y)); vh.AddVert(new Vector3(leftPos.x, leftPos.y + height), currentColor, new Vector2(uv.x, uv.w)); vh.AddVert(new Vector3(leftPos.x + width, leftPos.y + height), currentColor, new Vector2(uv.z, uv.w)); vh.AddVert(new Vector3(leftPos.x + width, leftPos.y), currentColor, new Vector2(uv.z, uv.y)); vh.AddTriangle(count, count + 1, count + 2); vh.AddTriangle(count + 2, count + 3, count); }
public override void Render(VertexHelper vh, Rect area, Vector2 offset, float pixelsPerUnit) { if (sprite == null) { return; } Color currentColor = node.d_color; if (currentColor.a <= 0.01f) { return; } Vector2 leftPos = GetStartLeftBottom(1f) + offset; Tools.LB2LT(ref leftPos, area.height); ISpriteDraw cd = node.owner.GetDraw(DrawType.ISprite, node.keyPrefix + sprite.GetHashCode(), (Draw d, object p) => { ISpriteDraw cad = d as ISpriteDraw; cad.isOpenAlpha = node.d_bBlink; cad.isOpenOffset = false; }) as ISpriteDraw; cd.Add(sprite, leftPos, rect.width, rect.height, currentColor); }
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; } }