Tanoda
ShineEffect.cs
Go to the documentation of this file.
1
3
5{
6 public class ShineEffect : MaskableGraphic
7 {
8
9 [SerializeField]
10 float yoffset = -1;
11
12 public float Yoffset
13 {
14 get
15 {
16 return yoffset;
17 }
18 set
19 {
20 SetVerticesDirty();
21 yoffset = value;
22 }
23 }
24
25 [SerializeField]
26 float width = 1;
27
28 public float Width
29 {
30 get
31 {
32 return width;
33 }
34 set
35 {
36 SetAllDirty();
37 width = value;
38 }
39 }
40
41 protected override void OnPopulateMesh(VertexHelper vh)
42 {
43 var r = GetPixelAdjustedRect();
44 var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);
45 float dif = (v.w - v.y) * 2;
46 Color32 color32 = color;
47 vh.Clear();
48
49 color32.a = (byte)0;
50 vh.AddVert(new Vector3(v.x - 50, width * v.y + yoffset * dif), color32, new Vector2(0f, 0f));
51 vh.AddVert(new Vector3(v.z + 50, width * v.y + yoffset * dif), color32, new Vector2(1f, 0f));
52
53 color32.a = (byte)(color.a * 255);
54 vh.AddVert(new Vector3(v.x - 50, width * (v.y / 4) + yoffset * dif), color32, new Vector2(0f, 1f));
55 vh.AddVert(new Vector3(v.z + 50, width * (v.y / 4) + yoffset * dif), color32, new Vector2(1f, 1f));
56
57 color32.a = (byte)(color.a * 255);
58 vh.AddVert(new Vector3(v.x - 50, width * (v.w / 4) + yoffset * dif), color32, new Vector2(0f, 1f));
59 vh.AddVert(new Vector3(v.z + 50, width * (v.w / 4) + yoffset * dif), color32, new Vector2(1f, 1f));
60 color32.a = (byte)(color.a * 255);
61
62 color32.a = (byte)0;
63 vh.AddVert(new Vector3(v.x - 50, width * v.w + yoffset * dif), color32, new Vector2(0f, 1f));
64 vh.AddVert(new Vector3(v.z + 50, width * v.w + yoffset * dif), color32, new Vector2(1f, 1f));
65
66 vh.AddTriangle(0, 1, 2);
67 vh.AddTriangle(2, 3, 1);
68
69 vh.AddTriangle(2, 3, 4);
70 vh.AddTriangle(4, 5, 3);
71
72 vh.AddTriangle(4, 5, 6);
73 vh.AddTriangle(6, 7, 5);
74 }
75
76 public void Triangulate(VertexHelper vh)
77 {
78 int triangleCount = vh.currentVertCount - 2;
79 Debug.Log(triangleCount);
80 for (int i = 0; i <= triangleCount / 2 + 1; i += 2)
81 {
82 vh.AddTriangle(i, i + 1, i + 2);
83 vh.AddTriangle(i + 2, i + 3, i + 1);
84 }
85 }
86
87#if UNITY_EDITOR
88 public override void OnRebuildRequested()
89 {
90 base.OnRebuildRequested();
91 }
92#endif
93
94 }
95}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
override void OnPopulateMesh(VertexHelper vh)
Definition: ShineEffect.cs:41
void Triangulate(VertexHelper vh)
Definition: ShineEffect.cs:76
Credit Erdener Gonenc - @PixelEnvision.