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
pull/413/head
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 // Methods
// //
public override void ModifyVertices (List<UIVertex> verts) public override void ModifyMesh (Mesh mesh)
{ {
if (!this.IsActive ()) if (!this.IsActive ())
{ {
return; 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; float best_fit_adjustment = 1f;
@ -35,16 +41,22 @@ namespace UnityEngine.UI.Extensions
int start = 0; int start = 0;
int count = verts.Count; 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; start = count;
count = verts.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; start = count;
count = verts.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; start = count;
count = verts.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))] [RequireComponent(typeof(Text), typeof(RectTransform))]
[AddComponentMenu("UI/Effects/Extensions/Curved Text")] [AddComponentMenu("UI/Effects/Extensions/Curved Text")]
public class CurvedText : BaseVertexEffect public class CurvedText : BaseMeshEffect
{ {
public AnimationCurve curveForText = AnimationCurve.Linear(0, 0, 1, 10); public AnimationCurve curveForText = AnimationCurve.Linear(0, 0, 1, 10);
public float curveMultiplier = 1; public float curveMultiplier = 1;
@ -40,18 +40,19 @@ namespace UnityEngine.UI.Extensions
rectTrans = GetComponent<RectTransform>(); rectTrans = GetComponent<RectTransform>();
OnRectTransformDimensionsChange(); OnRectTransformDimensionsChange();
} }
public override void ModifyVertices(System.Collections.Generic.List<UIVertex> verts) public override void ModifyMesh(Mesh mesh)
{ {
if (!IsActive()) if (!IsActive())
return; return;
Vector3[] verts = mesh.vertices;
for (int index = 0; index < verts.Count; index++) for (int index = 0; index < verts.Length; index++)
{ {
var uiVertex = verts[index]; var uiVertex = verts[index];
//Debug.Log (); //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; verts[index] = uiVertex;
} }
mesh.vertices = verts;
} }
protected override void OnRectTransformDimensionsChange() protected override void OnRectTransformDimensionsChange()
{ {

View File

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

View File

@ -46,7 +46,7 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
[AddComponentMenu("UI/Effects/Extensions/Letter Spacing")] [AddComponentMenu("UI/Effects/Extensions/Letter Spacing")]
public class LetterSpacing : BaseVertexEffect public class LetterSpacing : BaseMeshEffect
{ {
[SerializeField] [SerializeField]
private float m_spacing = 0f; 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; if (! IsActive()) return;
Text text = GetComponent<Text>(); Vector3[] verts = mesh.vertices;
Text text = GetComponent<Text>();
if (text == null) if (text == null)
{ {
Debug.LogWarning("LetterSpacing: Missing Text component"); Debug.LogWarning("LetterSpacing: Missing Text component");
@ -123,19 +125,19 @@ 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.Count - 1) return; if (idx4 > verts.Length - 1) return;
UIVertex vert1 = verts[idx1]; Vector3 vert1 = verts[idx1];
UIVertex vert2 = verts[idx2]; Vector3 vert2 = verts[idx2];
UIVertex vert3 = verts[idx3]; Vector3 vert3 = verts[idx3];
UIVertex vert4 = verts[idx4]; Vector3 vert4 = verts[idx4];
pos = Vector3.right * (letterOffset * charIdx - lineOffset); pos = Vector3.right * (letterOffset * charIdx - lineOffset);
vert1.position += pos; vert1 += pos;
vert2.position += pos; vert2 += pos;
vert3.position += pos; vert3 += pos;
vert4.position += pos; vert4 += pos;
verts[idx1] = vert1; verts[idx1] = vert1;
verts[idx2] = vert2; verts[idx2] = vert2;
@ -148,6 +150,7 @@ 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;
}
} }
} }

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 //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")] [AddComponentMenu("UI/Effects/Extensions/Nicer Outline")]
public class NicerOutline : BaseVertexEffect public class NicerOutline : BaseMeshEffect
{ {
[SerializeField] [SerializeField]
private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f); private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f);
@ -86,48 +86,55 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
// protected void ApplyShadowZeroAlloc(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
// Methods {
// UIVertex vt;
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);
Vector3 position = uIVertex.position; var neededCpacity = verts.Count * 2;
//Debug.Log("vertex pos: "+position); if (verts.Capacity < neededCpacity)
position.x += x; verts.Capacity = neededCpacity;
position.y += y;
uIVertex.position = position; for (int i = start; i < end; ++i)
Color32 color2 = color; {
if (this.m_UseGraphicAlpha) vt = verts[i];
{ verts.Add(vt);
color2.a = (byte)(color2.a * verts [i].color.a / 255);
} Vector3 v = vt.position;
uIVertex.color = color2; v.x += x;
//uIVertex.color = (Color32)Color.blue; v.y += y;
verts [i] = uIVertex; vt.position = v;
} var newColor = color;
} if (m_UseGraphicAlpha)
newColor.a = (byte)((newColor.a * verts[i].color.a) / 255);
public override void ModifyVertices (List<UIVertex> verts) 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 ()) if (!this.IsActive ())
{ {
return; 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; float best_fit_adjustment = 1f;
@ -166,7 +173,13 @@ namespace UnityEngine.UI.Extensions
start = count; start = count;
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())
{
helper.AddUIVertexTriangleStream(verts);
helper.FillMesh(mesh);
}
}
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void OnValidate () protected override void OnValidate ()

View File

@ -7,7 +7,7 @@ namespace UnityEngine.UI.Extensions
{ {
[RequireComponent(typeof(RectTransform), typeof(Graphic)), DisallowMultipleComponent] [RequireComponent(typeof(RectTransform), typeof(Graphic)), DisallowMultipleComponent]
[AddComponentMenu("UI/Effects/Extensions/Flippable")] [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_Horizontal = false;
[SerializeField] private bool m_Veritical = false; [SerializeField] private bool m_Veritical = false;
@ -37,24 +37,27 @@ namespace UnityEngine.UI.Extensions
this.GetComponent<Graphic>().SetVerticesDirty(); 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; 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 // Modify positions
v.position = new Vector3( v = new Vector3(
(this.m_Horizontal ? (v.position.x + (rt.rect.center.x - v.position.x) * 2) : v.position.x), (this.m_Horizontal ? (v.x + (rt.rect.center.x - v.x) * 2) : v.x),
(this.m_Veritical ? (v.position.y + (rt.rect.center.y - v.position.y) * 2) : v.position.y), (this.m_Veritical ? (v.y + (rt.rect.center.y - v.y) * 2) : v.y),
v.position.z v.z
); );
// Apply // Apply
verts[i] = v; verts[i] = v;
} }
mesh.vertices = verts;
} }
} }
} }