UGUI 超链接文字脚本

using System.Collections;
using System.Collections.Generic;
using System;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System.Globalization;

///


/// 超链接类型
///

public enum HyperlinkType
{
    Url = 0,//超链接url

    Task = 1,//任务

    Null,//下划线
}

///


/// 下划线可点击文字
/// 19.07.04 by Rocketjie
///

public class UnderLineScript : MonoBehaviour
{
    [Tooltip("Hyperlink type")]
    public HyperlinkType type = HyperlinkType.Null;

    [Tooltip("Hyperlink url")]
    public string HyperlinkUrl = "";

    private Text text;
    private Button btn;

    public void Awake()
    {
        text = gameObject.GetComponent();
    }

    public void Start()
    {
        if (text != null)
        {
            Text under_line = Instantiate(text) as Text;
            Destroy(under_line.transform.GetComponent());
            under_line.transform.SetParent(text.transform);

            RectTransform rt = under_line.rectTransform;
            rt.anchoredPosition3D = Vector3.zero;
            rt.offsetMax = Vector2.zero;
            rt.offsetMin = Vector2.zero;
            rt.anchorMax = Vector2.one;
            rt.anchorMin = Vector2.zero;

            under_line.text = "_";
            int line_count = (int)Mathf.Round(text.preferredWidth / under_line.preferredWidth);
            for (int i = 1; i < line_count; i++)
            {
                under_line.text += "_";
            }

            btn = gameObject.AddComponent

你可能感兴趣的:(unity,脚本,UGUI)