using UnityEngine;
using UnityEditor;
using TMPro;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.Localization.PropertyVariants;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization;
using UnityEngine.Localization.PropertyVariants.TrackedProperties;
using UnityEngine.Localization.PropertyVariants.TrackedObjects;
using UnityEngine.Events;
using UnityEngine.Localization.Components;
using UnityEngine.UI;
namespace GameCore.Editor
{
///
/// 用于批量设置TMP字体和材质的本地化
///
public class SetupTmpTextAndFont : EditorWindow
{
private Vector2 scrollPosition;
private bool processSelectedPrefabs = true;
private bool processFolderPrefabs = false;
private string folderPath = "Assets/";
private bool recursiveSearch = true;
// Unity Localization设置
private string tableReference = "text_AssetTable";
// 处理结果
private List processedPrefabs = new List();
private List errorMessages = new List();
[MenuItem("Tools/Setup TMP Text And Font")]
public static void ShowWindow()
{
SetupTmpTextAndFont window = GetWindow("Setup TMP Text And Font");
window.minSize = new Vector2(400, 500);
window.Show();
}
private void OnGUI()
{
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
GUILayout.Label("Setup TMP Text And Font", EditorStyles.boldLabel);
GUILayout.Space(10);
// 处理选项
GUILayout.Label("处理选项", EditorStyles.boldLabel);
processSelectedPrefabs = EditorGUILayout.Toggle("处理选中的Prefab", processSelectedPrefabs);
processFolderPrefabs = EditorGUILayout.Toggle("处理文件夹下的Prefab", processFolderPrefabs);
if (processFolderPrefabs)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label("文件夹路径:", GUILayout.Width(80));
folderPath = EditorGUILayout.TextField(folderPath);
if (GUILayout.Button("选择", GUILayout.Width(60)))
{
string selectedPath = EditorUtility.OpenFolderPanel("选择文件夹", "Assets", "");
if (!string.IsNullOrEmpty(selectedPath))
{
if (selectedPath.StartsWith(Application.dataPath))
{
folderPath = "Assets" + selectedPath.Substring(Application.dataPath.Length);
}
else
{
folderPath = selectedPath;
}
}
}
EditorGUILayout.EndHorizontal();
recursiveSearch = EditorGUILayout.Toggle("递归搜索子文件夹", recursiveSearch);
}
GUILayout.Space(10);
// Unity Localization设置
GUILayout.Label("Unity Localization 设置", EditorStyles.boldLabel);
tableReference = EditorGUILayout.TextField("表格引用", tableReference);
GUILayout.Space(10);
// 操作按钮
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("预览将要处理的Prefab"))
{
PreviewPrefabsToProcess();
}
if (GUILayout.Button("执行清理设置"))
{
ClearPrefabAll();
}
if (GUILayout.Button("执行批量设置"))
{
ProcessPrefabs();
}
if (GUILayout.Button("执行批量个性化设置"))
{
ProcessIndividuationPrefabs();
}
if (GUILayout.Button("执行批量WFC设置"))
{
ProcessWFCPrefabs();
}
EditorGUILayout.EndHorizontal();
GUILayout.Space(10);
// 显示处理结果
if (processedPrefabs.Count > 0 || errorMessages.Count > 0)
{
GUILayout.Label("处理结果", EditorStyles.boldLabel);
if (processedPrefabs.Count > 0)
{
GUILayout.Label($"成功处理 {processedPrefabs.Count} 个Prefab:", EditorStyles.boldLabel);
foreach (string prefab in processedPrefabs)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label("✓", GUILayout.Width(20));
if (GUILayout.Button(prefab, EditorStyles.label))
{
Object prefabAsset = AssetDatabase.LoadAssetAtPath