From 92f5e2190dbc34285cbefc862d60bd1fee64e54e Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Sun, 11 Oct 2015 11:33:43 +0100 Subject: [PATCH] Initial patches for 5.2.1p+ / 5.3 fixes due to the immediate changes in the UI source. --HG-- branch : develop_5.3 --- Scripts/CurvedText.cs | 21 ++++++++++--------- Scripts/Gradient.cs | 43 +++++++++++++++++---------------------- Scripts/LetterSpacing.cs | 44 +++++++++++++++++++++------------------- Scripts/NicerOutline.cs | 18 ++++++---------- Scripts/UIFlippable.cs | 38 ++++++++++++++++++---------------- 5 files changed, 80 insertions(+), 84 deletions(-) diff --git a/Scripts/CurvedText.cs b/Scripts/CurvedText.cs index 6508187..244e99b 100644 --- a/Scripts/CurvedText.cs +++ b/Scripts/CurvedText.cs @@ -40,19 +40,20 @@ namespace UnityEngine.UI.Extensions rectTrans = GetComponent(); OnRectTransformDimensionsChange(); } - public override void ModifyMesh(Mesh mesh) + public override void ModifyMesh(VertexHelper vh) { - if (!IsActive()) - return; - Vector3[] verts = mesh.vertices; - for (int index = 0; index < verts.Length; index++) + int count = vh.currentVertCount; + if (!IsActive() || count == 0) { - var uiVertex = verts[index]; - //Debug.Log (); - uiVertex.y += curveForText.Evaluate(rectTrans.rect.width * rectTrans.pivot.x + uiVertex.x) * curveMultiplier; - verts[index] = uiVertex; + return; + } + for (int index = 0; index < vh.currentVertCount; index++) + { + UIVertex uiVertex = new UIVertex(); + vh.PopulateUIVertex(ref uiVertex, index); + uiVertex.position.y += curveForText.Evaluate(rectTrans.rect.width * rectTrans.pivot.x + uiVertex.position.x) * curveMultiplier; + vh.SetUIVertex(uiVertex, index); } - mesh.vertices = verts; } protected override void OnRectTransformDimensionsChange() { diff --git a/Scripts/Gradient.cs b/Scripts/Gradient.cs index 6393092..9fb93ee 100644 --- a/Scripts/Gradient.cs +++ b/Scripts/Gradient.cs @@ -20,18 +20,16 @@ namespace UnityEngine.UI.Extensions targetGraphic = GetComponent(); } - public override void ModifyMesh(Mesh mesh) + public override void ModifyMesh(VertexHelper vh) { - if (!IsActive() || mesh.vertexCount == 0) + int count = vh.currentVertCount; + if (!IsActive() || count == 0) { return; } - - Vector3[] vertexList = mesh.vertices; - Color[] vertexListColors = mesh.colors; - int count = mesh.vertexCount; - Vector3 uiVertex = vertexList[0]; - Color uiVertexColor = vertexListColors[0]; + var vertexList = new List(); + vh.GetUIVertexStream(vertexList); + UIVertex uiVertex = new UIVertex(); if (gradientMode == GradientMode.Global) { if (gradientDir == GradientDir.DiagonalLeftToRight || gradientDir == GradientDir.DiagonalRightToLeft) @@ -41,49 +39,46 @@ namespace UnityEngine.UI.Extensions #endif gradientDir = GradientDir.Vertical; } - float bottomY = gradientDir == GradientDir.Vertical ? vertexList[vertexList.Length - 1].y : vertexList[vertexList.Length - 1].x; - float topY = gradientDir == GradientDir.Vertical ? vertexList[0].y : vertexList[0].x; + float bottomY = gradientDir == GradientDir.Vertical ? vertexList[vertexList.Count - 1].position.y : vertexList[vertexList.Count - 1].position.x; + float topY = gradientDir == GradientDir.Vertical ? vertexList[0].position.y : vertexList[0].position.x; float uiElementHeight = topY - bottomY; for (int i = 0; i < count; i++) { - uiVertex = vertexList[i]; - uiVertexColor = vertexListColors[i]; - if (!overwriteAllColor && uiVertexColor != targetGraphic.color) + vh.PopulateUIVertex(ref uiVertex, i); + if (!overwriteAllColor && uiVertex.color != targetGraphic.color) continue; - uiVertexColor *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.y : uiVertex.x) - bottomY) / uiElementHeight); - vertexListColors[i] = uiVertexColor; + uiVertex.color *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.position.y : uiVertex.position.x) - bottomY) / uiElementHeight); + vh.SetUIVertex(uiVertex, i); } } else { for (int i = 0; i < count; i++) { - uiVertex = vertexList[i]; - uiVertexColor = vertexListColors[i]; - if (!overwriteAllColor && !CompareCarefully(uiVertexColor, targetGraphic.color)) + vh.PopulateUIVertex(ref uiVertex, i); + if (!overwriteAllColor && !CompareCarefully(uiVertex.color, targetGraphic.color)) continue; switch (gradientDir) { case GradientDir.Vertical: - uiVertexColor *= (i % 4 == 0 || (i - 1) % 4 == 0) ? vertex1 : vertex2; + uiVertex.color *= (i % 4 == 0 || (i - 1) % 4 == 0) ? vertex1 : vertex2; break; case GradientDir.Horizontal: - uiVertexColor *= (i % 4 == 0 || (i - 3) % 4 == 0) ? vertex1 : vertex2; + uiVertex.color *= (i % 4 == 0 || (i - 3) % 4 == 0) ? vertex1 : vertex2; break; case GradientDir.DiagonalLeftToRight: - uiVertexColor *= (i % 4 == 0) ? vertex1 : ((i - 2) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)); + uiVertex.color *= (i % 4 == 0) ? vertex1 : ((i - 2) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)); break; case GradientDir.DiagonalRightToLeft: - uiVertexColor *= ((i - 1) % 4 == 0) ? vertex1 : ((i - 3) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)); + uiVertex.color *= ((i - 1) % 4 == 0) ? vertex1 : ((i - 3) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f)); break; } - vertexListColors[i] = uiVertexColor; + vh.SetUIVertex(uiVertex, i); } } - mesh.colors = vertexListColors; } private bool CompareCarefully(Color col1, Color col2) { diff --git a/Scripts/LetterSpacing.cs b/Scripts/LetterSpacing.cs index 4f1d38d..93f7bf4 100644 --- a/Scripts/LetterSpacing.cs +++ b/Scripts/LetterSpacing.cs @@ -71,12 +71,13 @@ namespace UnityEngine.UI.Extensions if (graphic != null) graphic.SetVerticesDirty(); } } - - public override void ModifyMesh(Mesh mesh) - { - if (! IsActive()) return; - Vector3[] verts = mesh.vertices; + public override void ModifyMesh(VertexHelper vh) + { + if (! IsActive()) return; + + List verts = new List(); + vh.GetUIVertexStream(verts); Text text = GetComponent(); if (text == null) @@ -125,21 +126,21 @@ namespace UnityEngine.UI.Extensions int idx4 = glyphIdx * 4 + 3; // Check for truncated text (doesn't generate verts for all characters) - if (idx4 > verts.Length - 1) return; - - Vector3 vert1 = verts[idx1]; - Vector3 vert2 = verts[idx2]; - Vector3 vert3 = verts[idx3]; - Vector3 vert4 = verts[idx4]; - - pos = Vector3.right * (letterOffset * charIdx - lineOffset); - - vert1 += pos; - vert2 += pos; - vert3 += pos; - vert4 += pos; - - verts[idx1] = vert1; + if (idx4 > verts.Count - 1) return; + + UIVertex vert1 = verts[idx1]; + UIVertex vert2 = verts[idx2]; + UIVertex vert3 = verts[idx3]; + UIVertex vert4 = verts[idx4]; + + pos = Vector3.right * (letterOffset * charIdx - lineOffset); + + vert1.position += pos; + vert2.position += pos; + vert3.position += pos; + vert4.position += pos; + + verts[idx1] = vert1; verts[idx2] = vert2; verts[idx3] = vert3; verts[idx4] = vert4; @@ -150,7 +151,8 @@ namespace UnityEngine.UI.Extensions // Offset for carriage return character that still generates verts glyphIdx++; } - mesh.vertices = verts; + vh.Clear(); + vh.AddUIVertexTriangleStream(verts); } } } diff --git a/Scripts/NicerOutline.cs b/Scripts/NicerOutline.cs index 797d69f..044cbf1 100644 --- a/Scripts/NicerOutline.cs +++ b/Scripts/NicerOutline.cs @@ -122,17 +122,14 @@ namespace UnityEngine.UI.Extensions } - public override void ModifyMesh (Mesh mesh) - { - if (!this.IsActive ()) + public override void ModifyMesh(VertexHelper vh) + { + if (!this.IsActive ()) { return; } List < UIVertex > verts = new List(); - using (var helper = new VertexHelper(mesh)) - { - helper.GetUIVertexStream(verts); - } + vh.GetUIVertexStream(verts); Text foundtext = GetComponent(); @@ -174,11 +171,8 @@ namespace UnityEngine.UI.Extensions count = verts.Count; this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY); - using (var helper = new VertexHelper()) - { - helper.AddUIVertexTriangleStream(verts); - helper.FillMesh(mesh); - } + vh.Clear(); + vh.AddUIVertexTriangleStream(verts); } #if UNITY_EDITOR diff --git a/Scripts/UIFlippable.cs b/Scripts/UIFlippable.cs index cb9ec4d..2b2879f 100644 --- a/Scripts/UIFlippable.cs +++ b/Scripts/UIFlippable.cs @@ -1,6 +1,7 @@ + +using System; /// Credit ChoMPHi /// Sourced from - http://forum.unity3d.com/threads/script-flippable-for-ui-graphics.291711/ - using System.Collections.Generic; namespace UnityEngine.UI.Extensions @@ -37,27 +38,30 @@ namespace UnityEngine.UI.Extensions this.GetComponent().SetVerticesDirty(); } - public void ModifyMesh(Mesh mesh) + public void ModifyMesh(VertexHelper verts) { - Vector3[] verts = mesh.vertices; RectTransform rt = this.transform as RectTransform; - for (int i = 0; i < verts.Length; ++i) + for (int i = 0; i < verts.currentVertCount; ++i) { - Vector3 v = verts[i]; - - // Modify positions - v = new Vector3( - (this.m_Horizontal ? (v.x + (rt.rect.center.x - v.x) * 2) : v.x), - (this.m_Veritical ? (v.y + (rt.rect.center.y - v.y) * 2) : v.y), - v.z - ); - - // Apply - verts[i] = v; - } + UIVertex uiVertex = new UIVertex(); + verts.PopulateUIVertex(ref uiVertex,i); - mesh.vertices = verts; + // Modify positions + uiVertex.position = new Vector3( + (this.m_Horizontal ? (uiVertex.position.x + (rt.rect.center.x - uiVertex.position.x) * 2) : uiVertex.position.x), + (this.m_Veritical ? (uiVertex.position.y + (rt.rect.center.y - uiVertex.position.y) * 2) : uiVertex.position.y), + uiVertex.position.z + ); + + // Apply + verts.SetUIVertex(uiVertex, i); + } + } + + public void ModifyMesh(Mesh mesh) + { + //Obsolete member implementation } } } \ No newline at end of file