I'm using this for something in a hobby game I'm working on. This allows you to create colour gradient effects on sprites. In case this of use to anyone:
Of course this would be better if you could set the colours from within the inspector. I don't need that myself so I haven't done it. And it really would be better to ensure the list is filled before trying to render.
In UIBasicSprite.cs:
- add a new Type, "VertexColoured".
- in the Fill() method, add the following case to the code:
case Type.VertexColoured:
VertexColouredFill(verts, uvs, cols);
break;
And then you need this code somewhere:
BetterList<Color> vertexColours;
public void SetVertexColours(Color c1, Color c2, Color c3, Color c4)
{
BetterList
<Color
> colourList
= new BetterList
<Color
>(); colourList.Add(c1);
colourList.Add(c2);
colourList.Add(c3);
colourList.Add(c4);
this.vertexColours = colourList;
}
protected void VertexColouredFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
{
Vector2 uv0
= new Vector2
(mOuterUV
.xMin, mOuterUV
.yMin); Vector2 uv1
= new Vector2
(mOuterUV
.xMax, mOuterUV
.yMax);
Vector4 v = drawingDimensions;
verts
.Add(new Vector3
(v
.x, v
.y)); verts
.Add(new Vector3
(v
.x, v
.w)); verts
.Add(new Vector3
(v
.z, v
.w)); verts
.Add(new Vector3
(v
.z, v
.y));
uvs.Add(uv0);
uvs
.Add(new Vector2
(uv0
.x, uv1
.y)); uvs.Add(uv1);
uvs
.Add(new Vector2
(uv1
.x, uv0
.y));
foreach (Color vc in this.vertexColours)
{
cols.Add(vc);
}
}