BITKit/Src/UnityEditor/TMPFontCheckWindow.cs

70 lines
2.1 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.TextCore.Text;
using UnityEngine.UIElements;
namespace BITKit.GameEditor
{
public class TMPFontCheck : EditorWindow
{
public static FontAsset CurrentFont;
[MenuItem("Tools/TextMeshPro Font Check")]
public static void ShowExample()
{
GetWindow<TMPFontCheck>().Show();
}
private void CreateGUI()
{
rootVisualElement.Clear();
var refreshButton = rootVisualElement.Create<Button>();
refreshButton.text = "刷新";
refreshButton.clicked += CreateGUI;
var mergeButton = rootVisualElement.Create<Button>();
mergeButton.text = "合并字符串";
var fontField = rootVisualElement.Create<ObjectField>();
fontField.objectType = typeof(FontAsset);
fontField.RegisterValueChangedCallback(x =>
{
CurrentFont = x.newValue as FontAsset;
});
fontField.SetValueWithoutNotify(CurrentFont);
var container = rootVisualElement.Create<VisualElement>();
container.style.flexDirection = FlexDirection.Column;
var label = container.Create<Label>();
label.style.unityFontDefinition = new FontDefinition()
{
fontAsset = CurrentFont
};
var textfield = container.Create<TextField>();
textfield.label = "Test Font";
textfield.multiline = true;
textfield.RegisterValueChangedCallback(x =>
{
label.text = x.newValue;
});
textfield.style.unityFontDefinition = label.style.unityFontDefinition;
mergeButton.clicked += () =>
{
textfield.value =new string(Regex.Replace(textfield.value, @"\s+", "").Distinct().ToArray());
};
}
}
}