unity3d曲线text文本

简介: 测试.png using System;using System.Collections.Generic;namespace UnityEngine.UI.Extensions{ /// /// Curved text.让文本按照曲线进行显示 【注意对Image的变形 也是可以的】 /// 说明: 对Text的操作就和 shadow 和 outline 组件类似。
img_0dfbbcce44f44ccc8a24433975c83f59.png
测试.png
 using System;
using System.Collections.Generic;

namespace UnityEngine.UI.Extensions
{
    /// <summary>
    /// Curved text.让文本按照曲线进行显示 【注意对Image的变形 也是可以的】
    /// 说明: 对Text的操作就和 shadow 和 outline 组件类似。
    /// </summary>
    // [RequireComponent(typeof(Text), typeof(RectTransform))]
    [AddComponentMenu("UI/Effects/Extensions/Curved Text")]
    public class CurvedText : BaseMeshEffect
    {
        // 曲线类型
        public AnimationCurve curveForText = AnimationCurve.Linear(0, 0, 1, 10);
        // 曲线程度
        public float curveMultiplier = 1;
        private RectTransform rectTrans;


#if UNITY_EDITOR
        protected override void OnValidate()
        {
            base.OnValidate();
            if (curveForText[0].time != 0)
            {
                var tmpRect = curveForText[0];
                tmpRect.time = 0;
                curveForText.MoveKey(0, tmpRect);
            }
            if (rectTrans == null)
                rectTrans = GetComponent<RectTransform>();
            if (curveForText[curveForText.length - 1].time != rectTrans.rect.width)
                OnRectTransformDimensionsChange();
        }
#endif
        protected override void Awake()
        {
            base.Awake();
            rectTrans = GetComponent<RectTransform>();
            OnRectTransformDimensionsChange();
        }
        protected override void OnEnable()
        {
            base.OnEnable();
            rectTrans = GetComponent<RectTransform>();
            OnRectTransformDimensionsChange();
        }
        /// <summary>
        /// Modifies the mesh. 最重要的重载函数
        /// </summary>
        /// <param name="mesh">Mesh.</param>
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!IsActive())
                return;

            // 从mesh 得到 顶点集
            List<UIVertex> verts = new List<UIVertex>();

            vh.GetUIVertexStream(verts);


            // 顶点的 y值按曲线变换
            for (int index = 0; index < verts.Count; index++)
            {
                var uiVertex = verts[index];
                //Debug.Log ();
                uiVertex.position.y += curveForText.Evaluate(rectTrans.rect.width * rectTrans.pivot.x + uiVertex.position.x) * curveMultiplier;
                verts[index] = uiVertex;
            }

            // 在合成mesh

            vh.AddUIVertexTriangleStream(verts);


        }
        protected override void OnRectTransformDimensionsChange()
        {
            var tmpRect = curveForText[curveForText.length - 1];
            if (rectTrans != null)
            {
                tmpRect.time = rectTrans.rect.width;
                curveForText.MoveKey(curveForText.length - 1, tmpRect);

            }
        }

    }
}

相关文章
|
8月前
SVG 文本(二)路径文本 <textPath>
SVG 文本(二)路径文本 <textPath>
78 0
echarts圆环图设置legend数据对齐百分比样式使用rich富文本标签和formatter函数
echarts圆环图设置legend数据对齐百分比样式使用rich富文本标签和formatter函数
403 0
|
10月前
|
数据挖掘
Seurat::DotPlot 样式美化-Facet方法添加X轴注释标签
本文示例了 Seurat::DotPlot 气泡图通过 GGPLOT Facet 美化展示效果的代码过程,以供参考学习
424 0
|
11月前
|
自然语言处理 算法 计算机视觉
Text2Room:第一个从文本生成室内三维场景的方法!
Text2Room:第一个从文本生成室内三维场景的方法!
167 0
|
图形学
Unity 【Content Size Fitter】- 聊天气泡自动适配Text文本框大小
Unity 【Content Size Fitter】- 聊天气泡自动适配Text文本框大小
387 1
Unity 【Content Size Fitter】- 聊天气泡自动适配Text文本框大小
答疑| ggplot 绘制火山图并添加文字标签
答疑| ggplot 绘制火山图并添加文字标签
399 1
答疑| ggplot 绘制火山图并添加文字标签
|
C#
【WPF】TextBlock文本文字分段显示不同颜色
原文:【WPF】TextBlock文本文字分段显示不同颜色 需求:一行文字中,不同字符显示不同颜色。如注册页面,为表示必填项,在文本最后加一个红色的型号* 目标效果: 方法一: 用< StackPanel >嵌套两个< TextBlock >。
1990 0
|
C#
C# 如何在PDF中绘制不同风格类型的文本
通过对控件Spire.PDF的测试,我们可以创建PDF文件并向文档中绘制文本、图片、表格、图形等内容,其中,对于绘制文本这一部分,Spire.PDF提供了三种字体类型来绘制文本,即: Standard fonts TrueType fonts Chinese, Japanese and Korean (CJK) fonts 从以上类中我们可以发现,是可以支持中、日、韩、英等字体类的,这为我们在操作PDF文件上提供了更多可能。
1109 0