Initial patches for 5.2.1p+ / 5.3 fixes due to the immediate changes in the UI source.

--HG--
branch : develop_5.3
pull/413/head
Simon (darkside) Jackson 2015-10-11 11:33:43 +01:00
parent d344d459b1
commit 92f5e2190d
5 changed files with 80 additions and 84 deletions

View File

@ -40,19 +40,20 @@ namespace UnityEngine.UI.Extensions
rectTrans = GetComponent<RectTransform>(); rectTrans = GetComponent<RectTransform>();
OnRectTransformDimensionsChange(); OnRectTransformDimensionsChange();
} }
public override void ModifyMesh(Mesh mesh) public override void ModifyMesh(VertexHelper vh)
{ {
if (!IsActive()) int count = vh.currentVertCount;
return; if (!IsActive() || count == 0)
Vector3[] verts = mesh.vertices;
for (int index = 0; index < verts.Length; index++)
{ {
var uiVertex = verts[index]; return;
//Debug.Log (); }
uiVertex.y += curveForText.Evaluate(rectTrans.rect.width * rectTrans.pivot.x + uiVertex.x) * curveMultiplier; for (int index = 0; index < vh.currentVertCount; index++)
verts[index] = uiVertex; {
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() protected override void OnRectTransformDimensionsChange()
{ {

View File

@ -20,18 +20,16 @@ namespace UnityEngine.UI.Extensions
targetGraphic = GetComponent<Graphic>(); targetGraphic = GetComponent<Graphic>();
} }
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; return;
} }
var vertexList = new List<UIVertex>();
Vector3[] vertexList = mesh.vertices; vh.GetUIVertexStream(vertexList);
Color[] vertexListColors = mesh.colors; UIVertex uiVertex = new UIVertex();
int count = mesh.vertexCount;
Vector3 uiVertex = vertexList[0];
Color uiVertexColor = vertexListColors[0];
if (gradientMode == GradientMode.Global) if (gradientMode == GradientMode.Global)
{ {
if (gradientDir == GradientDir.DiagonalLeftToRight || gradientDir == GradientDir.DiagonalRightToLeft) if (gradientDir == GradientDir.DiagonalLeftToRight || gradientDir == GradientDir.DiagonalRightToLeft)
@ -41,49 +39,46 @@ namespace UnityEngine.UI.Extensions
#endif #endif
gradientDir = GradientDir.Vertical; gradientDir = GradientDir.Vertical;
} }
float bottomY = gradientDir == GradientDir.Vertical ? vertexList[vertexList.Length - 1].y : vertexList[vertexList.Length - 1].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].y : vertexList[0].x; float topY = gradientDir == GradientDir.Vertical ? vertexList[0].position.y : vertexList[0].position.x;
float uiElementHeight = topY - bottomY; float uiElementHeight = topY - bottomY;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
uiVertex = vertexList[i]; vh.PopulateUIVertex(ref uiVertex, i);
uiVertexColor = vertexListColors[i]; if (!overwriteAllColor && uiVertex.color != targetGraphic.color)
if (!overwriteAllColor && uiVertexColor != targetGraphic.color)
continue; continue;
uiVertexColor *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.y : uiVertex.x) - bottomY) / uiElementHeight); uiVertex.color *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.position.y : uiVertex.position.x) - bottomY) / uiElementHeight);
vertexListColors[i] = uiVertexColor; vh.SetUIVertex(uiVertex, i);
} }
} }
else else
{ {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
uiVertex = vertexList[i]; vh.PopulateUIVertex(ref uiVertex, i);
uiVertexColor = vertexListColors[i]; if (!overwriteAllColor && !CompareCarefully(uiVertex.color, targetGraphic.color))
if (!overwriteAllColor && !CompareCarefully(uiVertexColor, targetGraphic.color))
continue; continue;
switch (gradientDir) switch (gradientDir)
{ {
case GradientDir.Vertical: 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; break;
case GradientDir.Horizontal: 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; break;
case GradientDir.DiagonalLeftToRight: 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; break;
case GradientDir.DiagonalRightToLeft: 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; break;
} }
vertexListColors[i] = uiVertexColor; vh.SetUIVertex(uiVertex, i);
} }
} }
mesh.colors = vertexListColors;
} }
private bool CompareCarefully(Color col1, Color col2) private bool CompareCarefully(Color col1, Color col2)
{ {

View File

@ -71,12 +71,13 @@ namespace UnityEngine.UI.Extensions
if (graphic != null) graphic.SetVerticesDirty(); 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<UIVertex> verts = new List<UIVertex>();
vh.GetUIVertexStream(verts);
Text text = GetComponent<Text>(); Text text = GetComponent<Text>();
if (text == null) if (text == null)
@ -125,21 +126,21 @@ namespace UnityEngine.UI.Extensions
int idx4 = glyphIdx * 4 + 3; int idx4 = glyphIdx * 4 + 3;
// Check for truncated text (doesn't generate verts for all characters) // Check for truncated text (doesn't generate verts for all characters)
if (idx4 > verts.Length - 1) return; if (idx4 > verts.Count - 1) return;
Vector3 vert1 = verts[idx1]; UIVertex vert1 = verts[idx1];
Vector3 vert2 = verts[idx2]; UIVertex vert2 = verts[idx2];
Vector3 vert3 = verts[idx3]; UIVertex vert3 = verts[idx3];
Vector3 vert4 = verts[idx4]; UIVertex vert4 = verts[idx4];
pos = Vector3.right * (letterOffset * charIdx - lineOffset); pos = Vector3.right * (letterOffset * charIdx - lineOffset);
vert1 += pos; vert1.position += pos;
vert2 += pos; vert2.position += pos;
vert3 += pos; vert3.position += pos;
vert4 += pos; vert4.position += pos;
verts[idx1] = vert1; verts[idx1] = vert1;
verts[idx2] = vert2; verts[idx2] = vert2;
verts[idx3] = vert3; verts[idx3] = vert3;
verts[idx4] = vert4; verts[idx4] = vert4;
@ -150,7 +151,8 @@ namespace UnityEngine.UI.Extensions
// Offset for carriage return character that still generates verts // Offset for carriage return character that still generates verts
glyphIdx++; glyphIdx++;
} }
mesh.vertices = verts; vh.Clear();
vh.AddUIVertexTriangleStream(verts);
} }
} }
} }

View File

@ -122,17 +122,14 @@ namespace UnityEngine.UI.Extensions
} }
public override void ModifyMesh (Mesh mesh) public override void ModifyMesh(VertexHelper vh)
{ {
if (!this.IsActive ()) if (!this.IsActive ())
{ {
return; return;
} }
List < UIVertex > verts = new List<UIVertex>(); List < UIVertex > verts = new List<UIVertex>();
using (var helper = new VertexHelper(mesh)) vh.GetUIVertexStream(verts);
{
helper.GetUIVertexStream(verts);
}
Text foundtext = GetComponent<Text>(); Text foundtext = GetComponent<Text>();
@ -174,11 +171,8 @@ namespace UnityEngine.UI.Extensions
count = verts.Count; count = verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY); this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY);
using (var helper = new VertexHelper()) vh.Clear();
{ vh.AddUIVertexTriangleStream(verts);
helper.AddUIVertexTriangleStream(verts);
helper.FillMesh(mesh);
}
} }
#if UNITY_EDITOR #if UNITY_EDITOR

View File

@ -1,6 +1,7 @@
using System;
/// Credit ChoMPHi /// Credit ChoMPHi
/// Sourced from - http://forum.unity3d.com/threads/script-flippable-for-ui-graphics.291711/ /// Sourced from - http://forum.unity3d.com/threads/script-flippable-for-ui-graphics.291711/
using System.Collections.Generic; using System.Collections.Generic;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
@ -37,27 +38,30 @@ namespace UnityEngine.UI.Extensions
this.GetComponent<Graphic>().SetVerticesDirty(); this.GetComponent<Graphic>().SetVerticesDirty();
} }
public void ModifyMesh(Mesh mesh) public void ModifyMesh(VertexHelper verts)
{ {
Vector3[] verts = mesh.vertices;
RectTransform rt = this.transform as RectTransform; 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]; UIVertex uiVertex = new UIVertex();
verts.PopulateUIVertex(ref uiVertex,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;
}
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
} }
} }
} }