1. 程式人生 > >[UGUI]Text文字效果

[UGUI]Text文字效果

.get 參考 添加 set col gradient 內容 .cn osi

參考鏈接:

http://www.xuanyusong.com/archives/3471

https://www.cnblogs.com/lyh916/p/9162463.html

0.Text的頂點分布

 1 using System.Collections.Generic;
 2 using UnityEngine;
 3 using UnityEngine.UI;
 4 
 5 public class TestMesh : BaseMeshEffect {
 6 
 7     public override void ModifyMesh(VertexHelper vh)
 8     {
 9
List<UIVertex> vertexs = new List<UIVertex>(); 10 vh.GetUIVertexStream(vertexs); 11 for (int i = 0; i < vertexs.Count; i++) 12 { 13 Debug.LogWarning(vertexs[i].position); 14 } 15 16 print(vertexs.Count); 17 print(vh.currentIndexCount);
18 print(vh.currentVertCount); 19 } 20 }

技術分享圖片

新建一個text,然後使內容保留至一個字,添加上面的腳本。可以發現,1個字有4個頂點,而頂點的排列如下圖。1個字由2個三角形組成,繪制順序為0-1-2和2-3-0,順時針繪制。

技術分享圖片

1.漸變效果

 1 using System.Collections.Generic;
 2 using UnityEngine;
 3 using UnityEngine.UI;
 4 
 5 [AddComponentMenu("UI/Effects/Gradient")]
 6 public class Gradient : BaseMeshEffect
7 { 8 [SerializeField] 9 private Color32 topColor = Color.white; 10 [SerializeField] 11 private Color32 bottomColor = Color.black; 12 13 public override void ModifyMesh(VertexHelper vh) 14 { 15 List<UIVertex> vertexs = new List<UIVertex>(); 16 vh.GetUIVertexStream(vertexs); 17 for (int i = 0; i < vertexs.Count;) 18 { 19 SetVertexColor(vertexs, i, topColor); 20 SetVertexColor(vertexs, i + 1, topColor); 21 SetVertexColor(vertexs, i + 2, bottomColor); 22 SetVertexColor(vertexs, i + 3, bottomColor); 23 SetVertexColor(vertexs, i + 4, bottomColor); 24 SetVertexColor(vertexs, i + 5, topColor); 25 i += 6; 26 } 27 vh.Clear(); 28 vh.AddUIVertexTriangleStream(vertexs); 29 } 30 31 private void SetVertexColor(List<UIVertex> vertexs, int index, Color32 color) 32 { 33 UIVertex vertex = vertexs[index]; 34 vertex.color = color; 35 vertexs[index] = vertex; 36 } 37 }

技術分享圖片

2.陰影效果

3.描邊效果

[UGUI]Text文字效果