Initial Check-int 5.2

Resolved forced script errors due to change from UIVertex to Mesh

**ToDo
Updated FILLVBO updates to PopulateMesh

--HG--
branch : develop_5.2
release
Simon (darkside) Jackson 2015-09-09 22:31:17 +01:00
parent a6b6d4793b
commit 79d8969f83
6 changed files with 125 additions and 86 deletions

View File

@ -17,14 +17,20 @@ namespace UnityEngine.UI.Extensions
//
// Methods
//
public override void ModifyVertices (List<UIVertex> verts)
public override void ModifyMesh (Mesh mesh)
{
if (!this.IsActive ())
{
return;
}
Text foundtext = GetComponent<Text>();
List<UIVertex> verts = new List<UIVertex>();
using (var helper = new VertexHelper(mesh))
{
helper.GetUIVertexStream(verts);
}
Text foundtext = GetComponent<Text>();
float best_fit_adjustment = 1f;
@ -35,16 +41,22 @@ namespace UnityEngine.UI.Extensions
int start = 0;
int count = verts.Count;
base.ApplyShadow (verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
start = count;
count = verts.Count;
base.ApplyShadow (verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
start = count;
count = verts.Count;
base.ApplyShadow (verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
start = count;
count = verts.Count;
base.ApplyShadow (verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
}
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
using (var helper = new VertexHelper())
{
helper.AddUIVertexTriangleStream(verts);
helper.FillMesh(mesh);
}
}
}
}

View File

@ -5,7 +5,7 @@ namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(Text), typeof(RectTransform))]
[AddComponentMenu("UI/Effects/Extensions/Curved Text")]
public class CurvedText : BaseVertexEffect
public class CurvedText : BaseMeshEffect
{
public AnimationCurve curveForText = AnimationCurve.Linear(0, 0, 1, 10);
public float curveMultiplier = 1;
@ -40,18 +40,19 @@ namespace UnityEngine.UI.Extensions
rectTrans = GetComponent<RectTransform>();
OnRectTransformDimensionsChange();
}
public override void ModifyVertices(System.Collections.Generic.List<UIVertex> verts)
public override void ModifyMesh(Mesh mesh)
{
if (!IsActive())
return;
for (int index = 0; index < verts.Count; index++)
Vector3[] verts = mesh.vertices;
for (int index = 0; index < verts.Length; index++)
{
var uiVertex = verts[index];
//Debug.Log ();
uiVertex.position.y += curveForText.Evaluate(rectTrans.rect.width * rectTrans.pivot.x + uiVertex.position.x) * curveMultiplier;
uiVertex.y += curveForText.Evaluate(rectTrans.rect.width * rectTrans.pivot.x + uiVertex.x) * curveMultiplier;
verts[index] = uiVertex;
}
mesh.vertices = verts;
}
protected override void OnRectTransformDimensionsChange()
{

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Effects/Extensions/Gradient")]
public class Gradient : BaseVertexEffect
public class Gradient : BaseMeshEffect
{
public GradientMode gradientMode = GradientMode.Global;
public GradientDir gradientDir = GradientDir.Vertical;
@ -20,14 +20,18 @@ namespace UnityEngine.UI.Extensions
targetGraphic = GetComponent<Graphic>();
}
public override void ModifyVertices(List<UIVertex> vertexList)
public override void ModifyMesh(Mesh mesh)
{
if (!IsActive() || vertexList.Count == 0)
if (!IsActive() || mesh.vertexCount == 0)
{
return;
}
int count = vertexList.Count;
UIVertex uiVertex = vertexList[0];
Vector3[] vertexList = mesh.vertices;
Color[] vertexListColors = mesh.colors;
int count = mesh.vertexCount;
Vector3 uiVertex = vertexList[0];
Color uiVertexColor = vertexListColors[0];
if (gradientMode == GradientMode.Global)
{
if (gradientDir == GradientDir.DiagonalLeftToRight || gradientDir == GradientDir.DiagonalRightToLeft)
@ -37,18 +41,19 @@ namespace UnityEngine.UI.Extensions
#endif
gradientDir = GradientDir.Vertical;
}
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 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 uiElementHeight = topY - bottomY;
for (int i = 0; i < count; i++)
{
uiVertex = vertexList[i];
if (!overwriteAllColor && uiVertex.color != targetGraphic.color)
uiVertexColor = vertexListColors[i];
if (!overwriteAllColor && uiVertexColor != targetGraphic.color)
continue;
uiVertex.color *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.position.y : uiVertex.position.x) - bottomY) / uiElementHeight);
vertexList[i] = uiVertex;
uiVertexColor *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.y : uiVertex.x) - bottomY) / uiElementHeight);
vertexListColors[i] = uiVertexColor;
}
}
else
@ -56,27 +61,29 @@ namespace UnityEngine.UI.Extensions
for (int i = 0; i < count; i++)
{
uiVertex = vertexList[i];
if (!overwriteAllColor && !CompareCarefully(uiVertex.color, targetGraphic.color))
uiVertexColor = vertexListColors[i];
if (!overwriteAllColor && !CompareCarefully(uiVertexColor, targetGraphic.color))
continue;
switch (gradientDir)
{
case GradientDir.Vertical:
uiVertex.color *= (i % 4 == 0 || (i - 1) % 4 == 0) ? vertex1 : vertex2;
uiVertexColor *= (i % 4 == 0 || (i - 1) % 4 == 0) ? vertex1 : vertex2;
break;
case GradientDir.Horizontal:
uiVertex.color *= (i % 4 == 0 || (i - 3) % 4 == 0) ? vertex1 : vertex2;
uiVertexColor *= (i % 4 == 0 || (i - 3) % 4 == 0) ? vertex1 : vertex2;
break;
case GradientDir.DiagonalLeftToRight:
uiVertex.color *= (i % 4 == 0) ? vertex1 : ((i - 2) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f));
uiVertexColor *= (i % 4 == 0) ? vertex1 : ((i - 2) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f));
break;
case GradientDir.DiagonalRightToLeft:
uiVertex.color *= ((i - 1) % 4 == 0) ? vertex1 : ((i - 3) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f));
uiVertexColor *= ((i - 1) % 4 == 0) ? vertex1 : ((i - 3) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f));
break;
}
vertexList[i] = uiVertex;
vertexListColors[i] = uiVertexColor;
}
}
mesh.colors = vertexListColors;
}
private bool CompareCarefully(Color col1, Color col2)
{

View File

@ -46,7 +46,7 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Effects/Extensions/Letter Spacing")]
public class LetterSpacing : BaseVertexEffect
public class LetterSpacing : BaseMeshEffect
{
[SerializeField]
private float m_spacing = 0f;
@ -72,11 +72,13 @@ namespace UnityEngine.UI.Extensions
}
}
public override void ModifyVertices(List<UIVertex> verts)
public override void ModifyMesh(Mesh mesh)
{
if (! IsActive()) return;
Text text = GetComponent<Text>();
Vector3[] verts = mesh.vertices;
Text text = GetComponent<Text>();
if (text == null)
{
Debug.LogWarning("LetterSpacing: Missing Text component");
@ -123,19 +125,19 @@ namespace UnityEngine.UI.Extensions
int idx4 = glyphIdx * 4 + 3;
// Check for truncated text (doesn't generate verts for all characters)
if (idx4 > verts.Count - 1) return;
if (idx4 > verts.Length - 1) return;
UIVertex vert1 = verts[idx1];
UIVertex vert2 = verts[idx2];
UIVertex vert3 = verts[idx3];
UIVertex vert4 = verts[idx4];
Vector3 vert1 = verts[idx1];
Vector3 vert2 = verts[idx2];
Vector3 vert3 = verts[idx3];
Vector3 vert4 = verts[idx4];
pos = Vector3.right * (letterOffset * charIdx - lineOffset);
vert1.position += pos;
vert2.position += pos;
vert3.position += pos;
vert4.position += pos;
vert1 += pos;
vert2 += pos;
vert3 += pos;
vert4 += pos;
verts[idx1] = vert1;
verts[idx2] = vert2;
@ -148,6 +150,7 @@ namespace UnityEngine.UI.Extensions
// Offset for carriage return character that still generates verts
glyphIdx++;
}
}
mesh.vertices = verts;
}
}
}

View File

@ -6,7 +6,7 @@ namespace UnityEngine.UI.Extensions
{
//An outline that looks a bit nicer than the default one. It has less "holes" in the outline by drawing more copies of the effect
[AddComponentMenu("UI/Effects/Extensions/Nicer Outline")]
public class NicerOutline : BaseVertexEffect
public class NicerOutline : BaseMeshEffect
{
[SerializeField]
private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f);
@ -86,48 +86,55 @@ namespace UnityEngine.UI.Extensions
}
}
}
//
// Methods
//
protected void ApplyShadow (List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
{
//Debug.Log("verts count: "+verts.Count);
int num = verts.Count * 2;
if (verts.Capacity < num)
{
verts.Capacity = num;
}
for (int i = start; i < end; i++)
{
UIVertex uIVertex = verts [i];
verts.Add (uIVertex);
protected void ApplyShadowZeroAlloc(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
{
UIVertex vt;
Vector3 position = uIVertex.position;
//Debug.Log("vertex pos: "+position);
position.x += x;
position.y += y;
uIVertex.position = position;
Color32 color2 = color;
if (this.m_UseGraphicAlpha)
{
color2.a = (byte)(color2.a * verts [i].color.a / 255);
}
uIVertex.color = color2;
//uIVertex.color = (Color32)Color.blue;
verts [i] = uIVertex;
}
}
public override void ModifyVertices (List<UIVertex> verts)
var neededCpacity = verts.Count * 2;
if (verts.Capacity < neededCpacity)
verts.Capacity = neededCpacity;
for (int i = start; i < end; ++i)
{
vt = verts[i];
verts.Add(vt);
Vector3 v = vt.position;
v.x += x;
v.y += y;
vt.position = v;
var newColor = color;
if (m_UseGraphicAlpha)
newColor.a = (byte)((newColor.a * verts[i].color.a) / 255);
vt.color = newColor;
verts[i] = vt;
}
}
protected void ApplyShadow(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
{
var neededCpacity = verts.Count * 2;
if (verts.Capacity < neededCpacity)
verts.Capacity = neededCpacity;
ApplyShadowZeroAlloc(verts, color, start, end, x, y);
}
public override void ModifyMesh (Mesh mesh)
{
if (!this.IsActive ())
{
return;
}
List < UIVertex > verts = new List<UIVertex>();
using (var helper = new VertexHelper(mesh))
{
helper.GetUIVertexStream(verts);
}
Text foundtext = GetComponent<Text>();
Text foundtext = GetComponent<Text>();
float best_fit_adjustment = 1f;
@ -166,7 +173,13 @@ namespace UnityEngine.UI.Extensions
start = count;
count = verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY);
}
using (var helper = new VertexHelper())
{
helper.AddUIVertexTriangleStream(verts);
helper.FillMesh(mesh);
}
}
#if UNITY_EDITOR
protected override void OnValidate ()

View File

@ -7,7 +7,7 @@ namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform), typeof(Graphic)), DisallowMultipleComponent]
[AddComponentMenu("UI/Effects/Extensions/Flippable")]
public class UIFlippable : MonoBehaviour, IVertexModifier
public class UIFlippable : MonoBehaviour, IMeshModifier
{
[SerializeField] private bool m_Horizontal = false;
[SerializeField] private bool m_Veritical = false;
@ -37,24 +37,27 @@ namespace UnityEngine.UI.Extensions
this.GetComponent<Graphic>().SetVerticesDirty();
}
public void ModifyVertices(List<UIVertex> verts)
public void ModifyMesh(Mesh mesh)
{
Vector3[] verts = mesh.vertices;
RectTransform rt = this.transform as RectTransform;
for (int i = 0; i < verts.Count; ++i)
for (int i = 0; i < verts.Length; ++i)
{
UIVertex v = verts[i];
Vector3 v = verts[i];
// Modify positions
v.position = new Vector3(
(this.m_Horizontal ? (v.position.x + (rt.rect.center.x - v.position.x) * 2) : v.position.x),
(this.m_Veritical ? (v.position.y + (rt.rect.center.y - v.position.y) * 2) : v.position.y),
v.position.z
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;
}
}
}