fixed letter spacing for 5.2.1+ (6 verts per character instead of 4);
added cylindrical text bending --HG-- branch : letterspacing_fixpull/413/head
parent
0dc0bc4e94
commit
6ebd7de12b
|
@ -0,0 +1,59 @@
|
|||
/// Credit Breyer
|
||||
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[RequireComponent(typeof(Text), typeof(RectTransform))]
|
||||
[AddComponentMenu("UI/Effects/Extensions/Cylinder Text")]
|
||||
public class CylinderText : BaseMeshEffect
|
||||
{
|
||||
public float radius;
|
||||
private RectTransform rectTrans;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnValidate()
|
||||
{
|
||||
base.OnValidate();
|
||||
if (rectTrans == null)
|
||||
rectTrans = GetComponent<RectTransform>();
|
||||
}
|
||||
#endif
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
rectTrans = GetComponent<RectTransform>();
|
||||
OnRectTransformDimensionsChange();
|
||||
}
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
rectTrans = GetComponent<RectTransform>();
|
||||
OnRectTransformDimensionsChange();
|
||||
}
|
||||
public override void ModifyMesh(VertexHelper vh)
|
||||
{
|
||||
Vector3 center = transform.position;
|
||||
|
||||
int count = vh.currentVertCount;
|
||||
if (!IsActive() || count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int index = 0; index < vh.currentVertCount; index++)
|
||||
{
|
||||
UIVertex uiVertex = new UIVertex();
|
||||
vh.PopulateUIVertex(ref uiVertex, index);
|
||||
|
||||
// get x position
|
||||
var x = uiVertex.position.x;
|
||||
|
||||
// calculate bend based on pivot and radius
|
||||
uiVertex.position.z = -radius * Mathf.Cos(x / radius);
|
||||
uiVertex.position.x = radius * Mathf.Sin(x / radius);
|
||||
|
||||
vh.SetUIVertex(uiVertex, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
[AddComponentMenu("UI/Effects/Extensions/Letter Spacing")]
|
||||
///Summary
|
||||
/// Note, LetterSpacing is now non-functional in 5.2.1p+ / 5.3, seems the vertex order has changed?
|
||||
/// Note, Vertex Count has changed in 5.2.1+, is now 6 (two tris) instead of 4 (tri strip).
|
||||
public class LetterSpacing : BaseMeshEffect
|
||||
{
|
||||
[SerializeField]
|
||||
|
@ -122,18 +122,22 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
for (int charIdx = 0; charIdx < line.Length; charIdx++)
|
||||
{
|
||||
int idx1 = glyphIdx * 4 + 0;
|
||||
int idx2 = glyphIdx * 4 + 1;
|
||||
int idx3 = glyphIdx * 4 + 2;
|
||||
int idx4 = glyphIdx * 4 + 3;
|
||||
int idx1 = glyphIdx * 6 + 0;
|
||||
int idx2 = glyphIdx * 6 + 1;
|
||||
int idx3 = glyphIdx * 6 + 2;
|
||||
int idx4 = glyphIdx * 6 + 3;
|
||||
int idx5 = glyphIdx * 6 + 4;
|
||||
int idx6 = glyphIdx * 6 + 5;
|
||||
|
||||
// Check for truncated text (doesn't generate verts for all characters)
|
||||
if (idx4 > verts.Count - 1) return;
|
||||
// Check for truncated text (doesn't generate verts for all characters)
|
||||
if (idx6 > verts.Count - 1) return;
|
||||
|
||||
UIVertex vert1 = verts[idx1];
|
||||
UIVertex vert2 = verts[idx2];
|
||||
UIVertex vert3 = verts[idx3];
|
||||
UIVertex vert4 = verts[idx4];
|
||||
UIVertex vert5 = verts[idx5];
|
||||
UIVertex vert6 = verts[idx6];
|
||||
|
||||
pos = Vector3.right * (letterOffset * charIdx - lineOffset);
|
||||
|
||||
|
@ -141,13 +145,17 @@ namespace UnityEngine.UI.Extensions
|
|||
vert2.position += pos;
|
||||
vert3.position += pos;
|
||||
vert4.position += pos;
|
||||
vert5.position += pos;
|
||||
vert6.position += pos;
|
||||
|
||||
verts[idx1] = vert1;
|
||||
verts[idx2] = vert2;
|
||||
verts[idx3] = vert3;
|
||||
verts[idx4] = vert4;
|
||||
verts[idx5] = vert5;
|
||||
verts[idx6] = vert6;
|
||||
|
||||
glyphIdx++;
|
||||
glyphIdx++;
|
||||
}
|
||||
|
||||
// Offset for carriage return character that still generates verts
|
||||
|
|
Loading…
Reference in New Issue