[UGUI]Text文字效果

参考链接:

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

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

https://www.cnblogs.com/zsb517/p/6565446.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.阴影效果

UGUI自带Shadow脚本,可以下载UGUI源码查看其实现。新建一个Text并添加Shadow组件,将effectDistance距离调大,如下图。其中白字是自身,黑字是阴影效果,可以看到,阴影效果就是将顶点复制一份,然后向某一方向移动位置。

 

3.描边效果

UGUI自带Outline脚本,Outline继承Shadow,换言之,其实现与Shadow类似。新建一个Text并添加Outline组件,将effectDistance距离调大,如下图。其中白字是自身,黑字是描边效果,可以看到,描边效果就是将顶点复制四份,然后向四个方向移动位置。

posted on 2018-06-23 16:42  艰苦奋斗中 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lyh916/p/9217617.html

Unity3D UGUI 专用文字特效插件 Text Effects 1.15 UI Text Effects are a set of effects for the standard Unity UI (uGUI) Text. - All script and shader sources included! - Extremely easy to use - just choose the effect from the component menu, and it's applied. - Add fancy titles, custom text appearance, mix multiple effects. - Rich Text support. - Mobile platform support. 12 extremely valuable effects: - Better Outline: a more continuous outline than the standard one. - Gradient Color: global/local, vertical/horizontal, override/additive/multiply. - Depth Effect: add thickness to text. - Soft Shadow: blurry shadow. - Outer Bevel: add outer lit and shaded edges. - Skew Effect: add horizontal+vertical transformations and perspective. - Curve Effect: bend or distort text vertically. - Character Spacing: increase or decrease the distance between individual characters. - Limit Visible Characters: hide characters, make a typewriter. - Overlay Texture: add an image overlay, local/global, override/additive/multiply. - Inner Bevel: add lit and shaded edges inside the characters, override/additive/multiply (only "override" on SM2 level GPUs). - Inner Outline: add outline inside the characters, override/additive/multiply. - With this package, you can finally echo effects from Photoshop or Word, while still using the standard Unity UI Text. - Suggestions for new effects are very welcome. The newly made effects will be added to the package. 仅供学习交流使用,如有侵权请告知删除。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值