untiy3dUGUI实现text文本下划线

作者: 好怕怕 | 来源:发表于2017-07-07 17:32 被阅读126次
测试.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;
        }
    }
}

相关文章

  • untiy3dUGUI实现text文本下划线

  • 7/12 Day02 css样式

    文本格式设置 1 文本下划线 text-decoration:设置下划线,删除线,顶划线 属性值: none ...

  • 前端开发学习第二十四天

    文本样式 text-decoration属性 text-decoration是去除超链接下划线较重要 文本大小te...

  • CSS 文本描边效果

    text-shadow 实现文本描边 text-stroke 实现文本描边 text-stroke 是 ext-s...

  • 文本属性

    1.文本装饰属性 格式:text-decoration:underline; 取值 underline(下划线) ...

  • css-文本

    1.文本装饰 text-decoration----td+tab underline下划线 line-throu...

  • HTML基础学习02_CSS基础属性

    内容概述 一 、 文本属性 1.text-decoration 设置文本的修饰外观 (下划线、上划线、 贯穿性 、...

  • 02. Html和工具介绍

    概念 Hyper text markup language (超文本标记语言)超文本:能够实现网页跳转的文本...

  • TEXT函数

    Text函数的功能是实现格式化文本输出Text函数的语法格式:TEXT(value,format_text)参数说...

  • Unity UGUI基础控件

    UGUI基础控件 Text控件 Text是用来显示文本的,在游戏界面当中显示文本大多数是用Text控件来实现的,T...

网友评论

    本文标题:untiy3dUGUI实现text文本下划线

    本文链接:https://www.haomeiwen.com/subject/welrhxtx.html