Skip to content

setchi/uGUI-Hypertext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uGUI-Hypertext license Release

UnityEngine.UI.Text で任意の部分文字列をクリック可能にするコンポーネントです。English (by Google Translate)

screencast

public class RegexExample : MonoBehaviour
{
    [SerializeField] RegexHypertext text = default;

    const string RegexUrl = @"https?://(?:[!-~]+\.)+[!-~]+";
    const string RegexHashtag = @"[\s^][##]\w+";

    void Start()
    {
        text.OnClick(RegexUrl, Color.cyan, url => Debug.Log(url));
        text.OnClick(RegexHashtag, Color.green, hashtag => Debug.Log(hashtag));
    }
}

導入

Releases から Hypertext.unitypackage をダウンロードして Unity Project にインポートします。

サンプル

Hypertext/Examples に正規表現によるパターンマッチで任意の部分文字列をクリック可能にする実装例があるので参考にしてください。

使い方

HypertextBase を継承したクラスを作成し、OnClick メソッドを使って任意の部分文字列がクリックされた時のコールバックを登録できます。詳細はサンプルの RegexHypertext を参考にしてください。

/// <summary>
/// 指定した部分文字列にクリックイベントを登録します
/// </summary>
/// <param name="startIndex">部分文字列の開始文字位置</param>
/// <param name="length">部分文字列の長さ</param>
/// <param name="color">部分文字列につける色</param>
/// <param name="onClick">部分文字列がクリックされたときのコールバック</param>
protected void OnClick(int startIndex, int length, Color color, Action<string> onClick)

開発環境

Unity 2019.2.10f1

Author

setchi

License

MIT

Packages

No packages published

Contributors 2

  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy