This library helps you get substring of unity3d's rich text. You can use this to implement a dialogue system
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Assets Fix bug that could not handle a text which ends with close tag Nov 18, 2018
Packages
ProjectSettings
.gitignore Initial commit Nov 11, 2018
README.md Update README.md Nov 18, 2018

README.md

Unity3dRichTextHelper

This library helps you get substring of unity3d's rich text. You can use this to implement a dialogue system

How to use(simple)

using RichTextSubstringHelper;

var richText = "<color=blue>blue</color>black";
richText.RichTextSubString(3); // <color=blue>blu</color>
richText.RichTextSubString(6); // <color=blue>blue</color>bl

When you want to make a dialogue system, displaying richtext may cause a trouble. CommonError

This library helps you get substring of richtext easily.

How to Install

Get unity package from below link

https://github.com/majecty/Unity3dRichTextHelper/releases

Or just copy and paste this file

https://github.com/majecty/Unity3dRichTextHelper/blob/master/Assets/RichTextHelper/RichTextHelper.cs

More example

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using RichTextSubstringHelper;

public class NewBehaviourScript : MonoBehaviour {
    [SerializeField]
    Text uiText;
    IEnumerator Start () {
        var firstText = "<color=blue>blah</color>x";
        for (int i = 0; i < firstText.RichTextLength(); i++)
        {
            yield return new WaitForSeconds(0.5f);
            uiText.text = firstText.RichTextSubString(i + 1);
        }
    }

}

Performance

richText.RichTextSubString(i) takes O(i) time because it should read string character by character every time.

If you consider performance, use like below example.

using System.Collections;
using UnityEngine;
using RichTextSubstringHelper;
using UnityEngine.UI;

public class NewBehaviourScript : MonoBehaviour {
    [SerializeField]
    Text uiText;

    IEnumerator Start ()
    {
        var richText = "<color=blue>blue</color>black";
        var maker = new RichTextSubStringMaker(richText);
        
        while (maker.IsConsumable())
        {
            maker.Consume();
            uiText.text = maker.GetRichText();
            yield return new WaitForSeconds(0.5f);
        }
    }
}