DCS/ruiyiweiUX/Assets/GeneralTools/Scripts/Always/Text/CustomText.cs

43 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
public class CustomText : Text
{
private readonly string mArkList = @"(\|\|\|\。|\《|\》|\|\|\“|\|\、|\|\+|\-)";
public override void SetVerticesDirty()
{
var settings = GetGenerationSettings(rectTransform.rect.size);
cachedTextGenerator.Populate(text, settings);
StringBuilder stringBuilder = new StringBuilder(text);
IList<UILineInfo> lineList = cachedTextGenerator.lines;
int changeIndex = -1;
for (int i = 1; i < lineList.Count; i++)
{
bool isMark = Regex.IsMatch(text[lineList[i].startCharIdx].ToString(), mArkList);
if (isMark)
{
bool b = Regex.IsMatch(text[lineList[i].startCharIdx].ToString(), mArkList);
if (b)
{
changeIndex = lineList[i].startCharIdx - 1;
break;
}
}
}
if (changeIndex >= 0)
{
stringBuilder.Insert(changeIndex, '\n');
text = stringBuilder.ToString();
}
base.SetVerticesDirty();
}
}