当前位置 博文首页 > keren2的博客:字体加粗特效

    keren2的博客:字体加粗特效

    作者:[db:作者] 时间:2021-09-02 10:16

    这个是让字体变粗,这个功能是转载别人的,但是忘记链接了,是别人写的。

    /*--------------------------------------------------------------------

    • Author Name: DXL
    • Creation Time: 7/4/2019 4:57:36 PM
    • File Describe: 字体加粗效果
    • ------------------------------------------------------------------*/

    using UnityEngine;
    using System.Collections.Generic;
    using UnityEngine.UI;
    [RequireComponent(typeof(Text))]
    public class BoldTextEffect : BaseMeshEffect
    {
    [Range(0, 1)] public float Alpha;
    [Range(1, 5)] public int Strength;

    private Text m_Text = null;
    
    private Text TextComp
    {
        get
        {
            if (m_Text == null)
            {
                m_Text = GetComponent<Text>();
            }
    
            return m_Text;
        }
    }
    
    private Color effectColor
    {
        get
        {
            if (TextComp == null)
            {
                return Color.black;
            }
    
            return TextComp.color;
        }
    }
    
    
    protected void ApplyShadowZeroAlloc(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
    {
        int num = verts.Count + end - start;
        if (verts.Capacity < num)
            verts.Capacity = num;
        for (int index = start; index < end; ++index)
        {
            UIVertex vert = verts[index];
            verts.Add(vert);
            Vector3 position = vert.position;
            position.x += x;
            position.y += y;
            vert.position = position;
            Color32 color32 = color;
            color32.a = (byte)((int)color32.a * (int)verts[index].color.a / (int)byte.MaxValue);
            color32.a = (byte)(Alpha * color32.a);
            vert.color = color32;
            verts[index] = vert;
        }
    }
    
    public override void ModifyMesh(VertexHelper vh)
    {
        if (!IsActive())
        {
            return;
        }
    
        List<UIVertex> verts = new List<UIVertex>();
        vh.GetUIVertexStream(verts);
    
    
        for (int i = 0; i < Strength; ++i)
        {
            ApplyShadowZeroAlloc(verts, effectColor, 0, verts.Count, 0, 0);
        }
    
        vh.Clear();
        vh.AddUIVertexTriangleStream(verts);
    }
    

    }

    cs
    下一篇:没有了