1.前言
在项目组无可厚非会在一些描述的文本中加入粗体,比如标题或者是重要文字,然而Unity本身UGUI提供的Text的Bold属性在某些字体达到的效果并不尽人意,可以先看下原本Unity的效果:
2.优化(一)
原本的效果肯定是不满足美术需求的,我们需要通过字体渲染方面重新实现字体加粗效果,在本文中核心算法其实就是将文本重复绘制,也就是在同样的位置绘制某个字符网格多次,可以近似实现这个字符的加粗效果。
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&g