2015-12-11 02:05:27 +08:00
|
|
|
|
/// adaption for cylindrical bending by herbst
|
|
|
|
|
/// Credit Breyer
|
2015-12-11 02:01:54 +08:00
|
|
|
|
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407
|
2023-07-09 23:48:55 +08:00
|
|
|
|
#if UNITY_2022_1_OR_NEWER
|
2015-12-11 02:01:54 +08:00
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
2023-02-07 22:35:43 +08:00
|
|
|
|
[RequireComponent(typeof(Text))]
|
|
|
|
|
[RequireComponent(typeof(RectTransform))]
|
2015-12-11 02:01:54 +08:00
|
|
|
|
[AddComponentMenu("UI/Effects/Extensions/Cylinder Text")]
|
|
|
|
|
public class CylinderText : BaseMeshEffect
|
|
|
|
|
{
|
|
|
|
|
public float radius;
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
protected override void OnValidate()
|
|
|
|
|
{
|
|
|
|
|
base.OnValidate();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
protected override void Awake()
|
|
|
|
|
{
|
|
|
|
|
base.Awake();
|
|
|
|
|
OnRectTransformDimensionsChange();
|
|
|
|
|
}
|
|
|
|
|
protected override void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
base.OnEnable();
|
|
|
|
|
OnRectTransformDimensionsChange();
|
|
|
|
|
}
|
|
|
|
|
public override void ModifyMesh(VertexHelper vh)
|
|
|
|
|
{
|
2015-12-11 06:15:39 +08:00
|
|
|
|
if (! IsActive()) return;
|
2015-12-11 06:04:32 +08:00
|
|
|
|
|
2015-12-11 02:01:54 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-09 23:48:55 +08:00
|
|
|
|
#endif
|