File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Unity3dRichTextHelper
2+ This library helps you get substring of unity3d's rich text.
3+
4+ ## How to use(simple)
5+ ``` csharp
6+
7+ using RichTextSubstringHelper ;
8+
9+ var richText = " <color=blue>blue</color>black" ;
10+ richText .RichTextSubString (3 ); // <color=blue>blu</color>
11+ richText .RichTextSubString (6 ); // <color=blue>blue</color>bl
12+ ```
13+
14+ When you want to make a dialogue system, displaying richtext may cause a trouble.
15+ <image here >
16+ This library helps you get substring of richtext easily.
17+
18+ ## More example
19+ ``` csharp
20+ using System .Collections ;
21+ using UnityEngine ;
22+ using UnityEngine .UI ;
23+ using RichTextSubstringHelper ;
24+
25+ public class NewBehaviourScript : MonoBehaviour {
26+ [SerializeField ]
27+ Text uiText ;
28+ IEnumerator Start () {
29+ var firstText = " <color=blue>blah</color>x" ;
30+ for (int i = 0 ; i < firstText .RichTextLength (); i ++ )
31+ {
32+ yield return new WaitForSeconds (0 . 5 f );
33+ uiText .text = firstText .RichTextSubString (i + 1 );
34+ }
35+ }
36+
37+ }
38+ ```
39+
40+ ## Performance
41+
42+ ` richText.RichTextSubString(i) ` takes O(i) time because it should read string character by character every time.
43+
44+ If you consider performance, use like below example.
45+
46+ ``` csharp
47+ using System .Collections ;
48+ using UnityEngine ;
49+ using RichTextSubstringHelper ;
50+ using UnityEngine .UI ;
51+
52+ public class NewBehaviourScript : MonoBehaviour {
53+ [SerializeField ]
54+ Text uiText ;
55+
56+ IEnumerator Start ()
57+ {
58+ var richText = " <color=blue>blue</color>black" ;
59+ yield return null ;
60+ var maker = new RichTextSubStringMaker (richText );
61+
62+ while (maker .IsConsumable ())
63+ {
64+ maker .Consume ();
65+ uiText .text = maker .GetRichText ();
66+ }
67+ }
68+ }
69+
70+ ```
71+
72+
You can’t perform that action at this time.
0 commit comments