using System.Text.RegularExpressions;

private IEnumerator ScrollingText()
{
    isScrolling = true;
    dialogueText.text = "";
    foreach(char letter in dialogueLines[currentLine].ToCharArray())
    {
        dialogueText.text += letter;
        yield return new WaitForSeconds(textSpeed);
        
        // 检测富文本标记
        string text = dialogueText.text;
        string pattern = "<([^<>]*)>";
        MatchCollection matches = Regex.Matches(text, pattern);
        foreach (Match match in matches)
        {
            string richText = match.Groups[1].Value;
            // 处理富文本内容
            // 例如,您可以通过判断richText的值来应用不同的样式或操作
            // 例如,如果richText是"color=red",则将文本设置为红色
        }
    }
    isScrolling = false;
}

此代码使用了System.Text.RegularExpressions命名空间中的Regex类来进行正则表达式匹配。<([^<>]*)>是一个正则表达式模式,它会匹配两组<>之间的内容,并将其捕获到richText变量中。您可以根据需要在foreach循环中处理富文本内容。请注意,此示例代码仅用于演示目的,您可能需要根据您的具体需求进行适当的调整。

C# 代码:滚动文本并检测富文本标签

原文地址: https://www.cveoy.top/t/topic/pJnp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录