untiy3dUGUI实现text文本下划线

简介: 测试.pngusing UnityEngine;using UnityEngine.UI;/// /// 链接下划线的制作/// public class UnderLine : MonoBehaviour{ ///...
img_9623c2ccc8cc7c750bbc134992b65ac4.png
测试.png
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 链接下划线的制作
/// </summary>
public class UnderLine : MonoBehaviour
{
    /// 
    /// URL文本
    /// 
    public GameObject URL;
    /// 
    /// URL下划线文本
    /// 
    public GameObject URL_UderLine;
    /// 
    /// URL下划线Image
    /// 
    public GameObject Line_Image;
    /// 
    /// 实现下划线的方式类型
    /// 
    public int Type = 0;


    void Awake()
    {
        SetURLUnderLine(Type);
    }


    /// 
    /// 设定隐私协议文本的下划线
    /// type值为0表示使用“拼接Text:_”方式实现,有缺点
    /// type值为1表示使用“拉伸Image”方式实现,比较完美
    /// 
    private void SetURLUnderLine(int type)
    {
        Debug.Log("设定隐私协议文本的下划线,方式:" + type);

        switch (type)
        {
            case 0:
                //计算URL文本的宽度
                URL.GetComponent<Text>().text = "www.baidu.com";
                float width = URL.GetComponent<Text>().preferredWidth;

                //计算单个下划线宽度  
                Text underLineText = URL_UderLine.GetComponent<Text>();
                underLineText.text = "_";
                float perlineWidth = underLineText.preferredWidth;

                int lineCount = (int)Mathf.Round(width / perlineWidth);
                for (int i = 1; i < lineCount; i++)
                {
                    underLineText.text += "_";
                }
                break;
            case 1:
                //计算URL文本的宽度
                URL.GetComponent<Text>().text = "www.xmutalbaa.com";
                float width2 = URL.GetComponent<Text>().preferredWidth;

                Vector2 curSizeDelta = Line_Image.GetComponent<RectTransform>().sizeDelta;
                //  Line_Image.GetComponent<RectTransform>().pivot = new Vector2(0, 0.5f);
                Line_Image.GetComponent<RectTransform>().sizeDelta = new Vector2(width2, curSizeDelta.y);
                break;
        }
    }
}
相关文章
|
API Android开发 图形学
【Unity3D】Android App Bundle(aab)打包上架Google Play介绍
总体说来,Android App Bundle打包有3种方式,每种方式都有成功上架Google Play进行测试通过,因此实用程度还是挺高的。能够理解以下内容的前提是会打apk包,知道如何生成Asset Bundle文件,这块内容可以参考我的上一篇文章。
3143 0
【Unity3D】Android App Bundle(aab)打包上架Google Play介绍
|
存储 缓存 开发工具
AppsFlyer 研究(二)应用内事件
AppsFlyer 研究(二)应用内事件
1466 0
|
算法 Unix Linux
【C/C++ 实用工具】性能分析工具一览
【C/C++ 实用工具】性能分析工具一览
1565 0
|
API 开发工具 Android开发
AppsFlyer 研究(一)AppsFlyer SDK 集成(1)
AppsFlyer 研究(一)AppsFlyer SDK 集成
2879 0
|
缓存 程序员 Shell
【最全面】SourceTree使用教程详解(连接远程仓库,克隆,拉取,提交,推送,新建/切换/合并分支,冲突解决,提交PR) (三)
【最全面】SourceTree使用教程详解(连接远程仓库,克隆,拉取,提交,推送,新建/切换/合并分支,冲突解决,提交PR) (三)
3297 0
【最全面】SourceTree使用教程详解(连接远程仓库,克隆,拉取,提交,推送,新建/切换/合并分支,冲突解决,提交PR) (三)
|
缓存 监控 Ubuntu
Ubuntu操作系统下清除系统缓存与无用文件的方法
通过上述步骤断行综合性地对Ubuntu进行优化与整洁可显著改善其性能表现及响应速度。然而,请注意在执行某些操作前确保充分了解其潜在影响;例如,在移除旧内核之前确认新内核稳定运行无问题;而对于关键配置更改则需确保备份好相关设置以便恢复原状态。
2991 0
|
iOS开发
IOS编译出现Command PhaseScriptExecution failed with a nonzero exit code
IOS编译出现Command PhaseScriptExecution failed with a nonzero exit code
4229 2