Updated remainder of UI API updates.

--HG--
branch : develop_5.3
pull/413/head
Simon (darkside) Jackson 2015-10-11 12:05:53 +01:00
parent 92f5e2190d
commit 7e279b78a1
7 changed files with 185 additions and 209 deletions

View File

@ -9,6 +9,7 @@ namespace UnityEngine.UI.Extensions
{
/// <summary>
/// Image is a textured element in the UI hierarchy.
/// Non-Functional as of 5.2.1p+ / 5.3, need to see updated Image Base script updates to fix properly.
/// </summary>
[AddComponentMenu("UI/Extensions/Image Extended")]
@ -196,7 +197,6 @@ namespace UnityEngine.UI.Extensions
var size = overrideSprite == null ? Vector2.zero : new Vector2(overrideSprite.rect.width, overrideSprite.rect.height);
Rect r = GetPixelAdjustedRect();
// Debug.Log(string.Format("r:{2}, size:{0}, padding:{1}", size, padding, r));
int spriteW = Mathf.RoundToInt(size.x);
int spriteH = Mathf.RoundToInt(size.y);
@ -253,13 +253,10 @@ namespace UnityEngine.UI.Extensions
/// Update the UI renderer mesh.
/// </summary>
protected override void OnPopulateMesh(Mesh toFill)
protected override void OnPopulateMesh(VertexHelper vh)
{
List<UIVertex> vbo = new List<UIVertex>();
using (var helper = new VertexHelper(toFill))
{
helper.GetUIVertexStream(vbo);
}
vh.GetUIVertexStream(vbo);
switch (type)
{
@ -276,12 +273,8 @@ namespace UnityEngine.UI.Extensions
GenerateFilledSprite(vbo, m_PreserveAspect);
break;
}
using (var helper = new VertexHelper())
{
helper.AddUIVertexTriangleStream(vbo);
helper.FillMesh(toFill);
}
vh.Clear();
vh.AddUIVertexTriangleStream(vbo);
}
#region Various fill functions

View File

@ -46,6 +46,8 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Effects/Extensions/Letter Spacing")]
///Summary
/// Note, LetterSpacing is now non-functional in 5.2.1p+ / 5.3, seems the vertex order has changed?
public class LetterSpacing : BaseMeshEffect
{
[SerializeField]

View File

@ -15,8 +15,9 @@ namespace UnityEngine.UI.Extensions
public float c = 1;
public float d = 1;
protected override void OnPopulateMesh(Mesh m)
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
float wHalf = rectTransform.rect.width / 2;
//float hHalf = rectTransform.rect.height / 2;
a = Math.Min(1, Math.Max(0, a));
@ -25,8 +26,6 @@ namespace UnityEngine.UI.Extensions
d = Math.Min(1, Math.Max(0, d));
Color32 color32 = color;
using (var vh = new VertexHelper())
{
vh.AddVert(new Vector3(-wHalf * a, 0), color32, new Vector2(0f, 0f));
vh.AddVert(new Vector3(0, wHalf * b), color32, new Vector2(0f, 1f));
vh.AddVert(new Vector3(wHalf * c, 0), color32, new Vector2(1f, 1f));
@ -34,8 +33,6 @@ namespace UnityEngine.UI.Extensions
vh.AddTriangle(0, 1, 2);
vh.AddTriangle(2, 3, 0);
vh.FillMesh(m);
}
}
}
}

View File

@ -67,13 +67,12 @@ namespace UnityEngine.UI.Extensions
}
protected override void OnPopulateMesh(Mesh toFill)
protected override void OnPopulateMesh(VertexHelper vh)
{
float outer = -rectTransform.pivot.x * rectTransform.rect.width;
float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.thickness;
toFill.Clear();
var vbo = new VertexHelper(toFill);
vh.Clear();
Vector2 prevX = Vector2.zero;
Vector2 prevY = Vector2.zero;
@ -119,15 +118,9 @@ namespace UnityEngine.UI.Extensions
prevX = pos1;
prevY = pos2;
vbo.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
}
if (vbo.currentVertCount > 3)
{
vbo.FillMesh(toFill);
}
}
}
}

View File

@ -41,21 +41,23 @@ namespace UnityEngine.UI.Extensions {
// [HideUnless("useColorDown")]
public Color32 colorDown = Color.green;
protected override void OnPopulateMesh(Mesh m) {
protected override void OnPopulateMesh(VertexHelper vh)
{
var rect = rectTransform.rect;
var rectNew = rect;
Color32 color32 = color;
using (var vh = new VertexHelper()) {
bool up = cutUL | cutUR;
bool down = cutLL | cutLR;
bool left = cutLL | cutUL;
bool right = cutLR | cutUR;
bool any = up | down;
if (any && cornerSize.sqrMagnitude > 0) {
//nibble off the sides
if (any && cornerSize.sqrMagnitude > 0)
{
//nibble off the sides
vh.Clear();
if (left)
rectNew.xMin += cornerSize.x;
if (down)
@ -68,7 +70,8 @@ namespace UnityEngine.UI.Extensions {
//add two squares to the main square
Vector2 ul, ur, ll, lr;
if (makeColumns) {
if (makeColumns)
{
ul = new Vector2(rect.xMin, cutUL ? rectNew.yMax : rect.yMax);
ur = new Vector2(rect.xMax, cutUR ? rectNew.yMax : rect.yMax);
ll = new Vector2(rect.xMin, cutLL ? rectNew.yMin : rect.yMin);
@ -86,7 +89,9 @@ namespace UnityEngine.UI.Extensions {
new Vector2(rectNew.xMax, rect.yMin),
new Vector2(rectNew.xMax, rect.yMax),
rect, useColorDown ? colorDown : color32, vh);
} else {
}
else
{
ul = new Vector2(cutUL ? rectNew.xMin : rect.xMin, rect.yMax);
ur = new Vector2(cutUR ? rectNew.xMax : rect.xMax, rect.yMax);
ll = new Vector2(cutLL ? rectNew.xMin : rect.xMin, rect.yMin);
@ -104,7 +109,6 @@ namespace UnityEngine.UI.Extensions {
new Vector2(rect.xMin, rectNew.yMax),
rect, useColorUp ? colorUp : color32, vh);
}
}
//center
if (makeColumns)
@ -112,7 +116,6 @@ namespace UnityEngine.UI.Extensions {
else
AddSquare(new Rect(rect.xMin, rectNew.yMin, rect.width, rectNew.height), rect, color32, vh);
vh.FillMesh(m);
}
}

View File

@ -65,7 +65,7 @@ namespace UnityEngine.UI.Extensions
}
}
protected override void OnPopulateMesh(Mesh toFill)
protected override void OnPopulateMesh(VertexHelper vh)
{
// requires sets of quads
if (Points == null || Points.Length < 2)
@ -107,8 +107,7 @@ namespace UnityEngine.UI.Extensions
offsetY += Margin.y / 2f;
}
toFill.Clear();
var vbo = new VertexHelper(toFill);
vh.Clear();
Vector2 prevV1 = Vector2.zero;
Vector2 prevV2 = Vector2.zero;
@ -144,24 +143,19 @@ namespace UnityEngine.UI.Extensions
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
if (i > 1)
vbo.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
vh.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == TempPoints.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };
vbo.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));
vh.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));
prevV1 = v3;
prevV2 = v4;
}
if (vbo.currentVertCount > 3)
{
vbo.FillMesh(toFill);
}
}
protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs)

View File

@ -66,7 +66,7 @@ namespace UnityEngine.UI.Extensions
}
}
protected override void OnPopulateMesh(Mesh toFill)
protected override void OnPopulateMesh(VertexHelper vh)
{
// requires sets of quads
if (Points == null || Points.Length < 2)
@ -108,8 +108,7 @@ namespace UnityEngine.UI.Extensions
offsetY += Margin.y / 2f;
}
toFill.Clear();
var vbo = new VertexHelper(toFill);
vh.Clear();
Vector2 prevV1 = Vector2.zero;
Vector2 prevV2 = Vector2.zero;
@ -145,24 +144,19 @@ namespace UnityEngine.UI.Extensions
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
if (i > 1)
vbo.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
vh.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == TempPoints.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };
vbo.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));
vh.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));
prevV1 = v3;
prevV2 = v4;
}
if (vbo.currentVertCount > 3)
{
vbo.FillMesh(toFill);
}
}
protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs)