Unity 若要使用漸層字型,可以新增一個TextGradient的cs來控制,這個檔案丟在你Assets中scripts底下就可以使用了

using UnityEngine;
using UnityEngine.UI;
 
/// <summary>
/// 該效果為 UGUI Text 文字顏色漸層效果. 
/// </summary>
[AddComponentMenu"UI/Effects/Gradient" )]
public class TextGradient : BaseMeshEffect
{
  public Color32 topColor = Color.white;
  public Color32 bottomColor = Color.black;
 
  public override void ModifyMeshVertexHelper vh )
  {
    float bottomY = -1;
    float topY = -1;
 
    for ( int i = 0i < vh.currentVertCounti++ )
    {
      UIVertex v = new UIVertex();
      vh.PopulateUIVertexref vi );
 
      if ( bottomY == -1 ) 
        bottomY = v.position.y;
      if ( topY == -1 ) 
        topY = v.position.y;
 
      if ( v.position.y > topY ) 
        topY = v.position.y;
      else if ( v.position.y < bottomY ) 
        bottomY = v.position.y;
    }
 
    float uiElementHeight = topY - bottomY;
 
    for ( int i = 0i < vh.currentVertCounti++ )
    {
      UIVertex v = new UIVertex();
      vh.PopulateUIVertexref vi );
 
      v.color = Color32.LerpbottomColortopColor, (v.position.y - bottomY/ uiElementHeight );
      vh.SetUIVertexvi );
    }
  }
 
}
arrow
arrow

    狼翔月影 發表在 痞客邦 留言(0) 人氣()