Initial patches for 5.2.1p+ / 5.3 fixes due to the immediate changes in the UI source.
--HG-- branch : develop_5.3pull/413/head
parent
d344d459b1
commit
92f5e2190d
|
@ -40,19 +40,20 @@ namespace UnityEngine.UI.Extensions
|
|||
rectTrans = GetComponent<RectTransform>();
|
||||
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()
|
||||
{
|
||||
|
|
|
@ -20,18 +20,16 @@ namespace UnityEngine.UI.Extensions
|
|||
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;
|
||||
}
|
||||
|
||||
Vector3[] vertexList = mesh.vertices;
|
||||
Color[] vertexListColors = mesh.colors;
|
||||
int count = mesh.vertexCount;
|
||||
Vector3 uiVertex = vertexList[0];
|
||||
Color uiVertexColor = vertexListColors[0];
|
||||
var vertexList = new List<UIVertex>();
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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<UIVertex> verts = new List<UIVertex>();
|
||||
vh.GetUIVertexStream(verts);
|
||||
|
||||
Text text = GetComponent<Text>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<UIVertex>();
|
||||
using (var helper = new VertexHelper(mesh))
|
||||
{
|
||||
helper.GetUIVertexStream(verts);
|
||||
}
|
||||
vh.GetUIVertexStream(verts);
|
||||
|
||||
Text foundtext = GetComponent<Text>();
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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<Graphic>().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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue