Unity3d UGUI Text 增加下划线

1.简单易用,只需要添加到带有Text脚本的GameObject对象即可
2.支持单行或者多行
3.可以根据Text文字内容改变而自动刷新
4. 效果图如下:
Unity3d UGUI Text 增加下划线_第1张图片 Unity3d UGUI Text 增加下划线_第2张图片

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

class UnderlineProperty
{
    public Color _color;
    public Vector3 _position;
    public float _width;
    public float _height;
    public Vector2 _privot;
}

public class MultipleLinkButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    private Text _text;
    private int _curCharacterCount = 0;
    private List _lines = new List();
    private System.Action _clickEvent = null; //下划线点击事件
    private bool _isInitUnderline = false;

    public System.Action ClickEvent
    {
        get
        {
            return _clickEvent;
        }

        set
        {
            _clickEvent = value;
        }
    }

    // Use this for initialization
    void Start () {
        _text = transform.GetComponent();
        _text.gameObject.AddComponent

附加说明:

  1. 参考他人网上通过实例化一个同样的Text,用"_"来实现下划线,在非等宽字符中会出现下划线和显示文本长度不一致,所以自己用image实现了一下
  2. 参考过别人实现链接: https://blog.csdn.net/bszk81340089/article/details/50017317
  3. demo下载地址: https://github.com/a834286983/project/raw/master/Underline.zip
  4. 不足之处欢迎指教:[email protected]

你可能感兴趣的:(Unity3d)