69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Diagnostics;
|
|||
|
using UnityEngine;
|
|||
|
using Debug = UnityEngine.Debug;
|
|||
|
|
|||
|
public class RichText : MonoBehaviour
|
|||
|
{
|
|||
|
[Header("<22>ı<EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>")] public GameObject textItem;
|
|||
|
private string text = "";
|
|||
|
|
|||
|
public string Text
|
|||
|
{
|
|||
|
[DebuggerStepThrough] get => text;
|
|||
|
[DebuggerStepThrough]
|
|||
|
set
|
|||
|
{
|
|||
|
text = value;
|
|||
|
Debug.Log("===------");
|
|||
|
Debug.Log("<p>" + text + "</p>");
|
|||
|
foreach (string item in SplitStringByTags("<p>" + text + "</p>", 23))
|
|||
|
{
|
|||
|
|
|||
|
GameObject gameObject = Instantiate(textItem, GameObject.Find(name).transform);
|
|||
|
gameObject.GetComponent<TextItem>().updateText(item);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static string[] SplitStringByTags(string input, int maxLength)
|
|||
|
{
|
|||
|
// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽƥ<CABD><C6A5> <p> <20><>ǩ<EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
var regex = new System.Text.RegularExpressions.Regex(@"<p>(.*?)</p>");
|
|||
|
var matches = regex.Matches(input);
|
|||
|
|
|||
|
// <20><><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD><EFBFBD>
|
|||
|
var resultList = new System.Collections.Generic.List<string>();
|
|||
|
|
|||
|
foreach (System.Text.RegularExpressions.Match match in matches)
|
|||
|
{
|
|||
|
string line = match.Groups[1].Value; // <20><>ȡ<p><3E><></p>֮<><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
if (line.Length > maxLength)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>еij<D0B5><C4B3>ȴ<EFBFBD><C8B4><EFBFBD>maxLength<74><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳɶ<D6B3><C9B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
for (int i = 0; i < line.Length; i += maxLength)
|
|||
|
{
|
|||
|
int length = Math.Min(maxLength, line.Length - i);
|
|||
|
resultList.Add(line.Substring(i, length));
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
resultList.Add(line);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return resultList.ToArray();
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|