Tanoda
CylinderText.cs
Go to the documentation of this file.
1
4
6{
7 [RequireComponent(typeof(Text), typeof(RectTransform))]
8 [AddComponentMenu("UI/Effects/Extensions/Cylinder Text")]
9 public class CylinderText : BaseMeshEffect
10 {
11 public float radius;
12
13#if UNITY_EDITOR
14 protected override void OnValidate()
15 {
16 base.OnValidate();
17 }
18#endif
19 protected override void Awake()
20 {
21 base.Awake();
22 OnRectTransformDimensionsChange();
23 }
24 protected override void OnEnable()
25 {
26 base.OnEnable();
27 OnRectTransformDimensionsChange();
28 }
29 public override void ModifyMesh(VertexHelper vh)
30 {
31 if (! IsActive()) return;
32
33 int count = vh.currentVertCount;
34 if (!IsActive() || count == 0)
35 {
36 return;
37 }
38 for (int index = 0; index < vh.currentVertCount; index++)
39 {
40 UIVertex uiVertex = new UIVertex();
41 vh.PopulateUIVertex(ref uiVertex, index);
42
43 // get x position
44 var x = uiVertex.position.x;
45
46 // calculate bend based on pivot and radius
47 uiVertex.position.z = -radius * Mathf.Cos(x / radius);
48 uiVertex.position.x = radius * Mathf.Sin(x / radius);
49
50 vh.SetUIVertex(uiVertex, index);
51 }
52 }
53 }
54}
override void ModifyMesh(VertexHelper vh)
Definition: CylinderText.cs:29
Credit Erdener Gonenc - @PixelEnvision.