|
@@ -1,32 +1,38 @@
|
|
|
using UnityEngine;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
-[AddComponentMenu("UI/Effects/Gradient")]
|
|
|
+[AddComponentMenu( "UI/Effects/Gradient" )]
|
|
|
public class Gradient : BaseMeshEffect
|
|
|
{
|
|
|
- public Color32 topColor = Color.white;
|
|
|
- public Color32 bottomColor = Color.black;
|
|
|
+ [SerializeField]
|
|
|
+ private Color32 topColor = Color.white;
|
|
|
+ [SerializeField]
|
|
|
+ private Color32 bottomColor = Color.black;
|
|
|
|
|
|
- public override void ModifyMesh(VertexHelper helper)
|
|
|
+ public override void ModifyMesh( VertexHelper vh )
|
|
|
{
|
|
|
- if (!IsActive() || helper.currentVertCount == 0)
|
|
|
+ if( !IsActive() )
|
|
|
+ {
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
- List<UIVertex> vertices = new List<UIVertex>();
|
|
|
- helper.GetUIVertexStream(vertices);
|
|
|
-
|
|
|
- float bottomY = vertices[0].position.y;
|
|
|
- float topY = vertices[0].position.y;
|
|
|
+ int count = vh.currentVertCount;
|
|
|
+ UIVertex vertex = new UIVertex();
|
|
|
+ vh.PopulateUIVertex (ref vertex, 0);
|
|
|
+ float bottomY = vertex.position.y;
|
|
|
+ float topY = vertex.position.y;
|
|
|
|
|
|
- for (int i = 1; i < vertices.Count; i++)
|
|
|
+ for( int i = 1; i < count; i++ )
|
|
|
{
|
|
|
- float y = vertices[i].position.y;
|
|
|
- if (y > topY)
|
|
|
+ vh.PopulateUIVertex (ref vertex, i);
|
|
|
+ float y = vertex.position.y;
|
|
|
+ if( y > topY )
|
|
|
{
|
|
|
topY = y;
|
|
|
}
|
|
|
- else if (y < bottomY)
|
|
|
+ else if( y < bottomY )
|
|
|
{
|
|
|
bottomY = y;
|
|
|
}
|
|
@@ -34,13 +40,12 @@ public class Gradient : BaseMeshEffect
|
|
|
|
|
|
float uiElementHeight = topY - bottomY;
|
|
|
|
|
|
- UIVertex v = new UIVertex();
|
|
|
-
|
|
|
- for (int i = 0; i < helper.currentVertCount; i++)
|
|
|
+ for( int i = 0; i < count; i++ )
|
|
|
{
|
|
|
- helper.PopulateUIVertex(ref v, i);
|
|
|
- v.color = Color32.Lerp(bottomColor, topColor, (v.position.y - bottomY) / uiElementHeight);
|
|
|
- helper.SetUIVertex(v, i);
|
|
|
+ UIVertex uiVertex = new UIVertex();
|
|
|
+ vh.PopulateUIVertex (ref uiVertex, i);
|
|
|
+ uiVertex.color = Color32.Lerp( bottomColor, topColor, ( uiVertex.position.y - bottomY ) / uiElementHeight );
|
|
|
+ vh.SetUIVertex (uiVertex, i);
|
|
|
}
|
|
|
}
|
|
|
}
|