1.简单易用,只需要添加到带有Text脚本的GameObject对象即可
2.支持单行或者多行
3.可以根据Text文字内容改变而自动刷新
4. 效果图如下:
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<Image> _lines = new List<Image>();
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>();
_text.gameObject.AddComponent<Button>().onClick.AddListener(()=> {
if (ClickEvent != null)
ClickEvent();
});
}
void Update()
{
//做初始化
if (_text.cachedTextGenerator.lineCount