55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
|
|
public class CollectPlayerNameChars : EditorWindow
|
|
{
|
|
[MenuItem("Tools/收集玩家名字字符(场景+预制体)")]
|
|
static void Collect()
|
|
{
|
|
HashSet<char> chars = new HashSet<char>();
|
|
|
|
// 1. 基础字符集
|
|
string baseChars = "一二三四五六七八九十" +
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
|
"0123456789" +
|
|
"_-.,";
|
|
foreach (char c in baseChars) chars.Add(c);
|
|
|
|
// 2. 扫描所有场景
|
|
foreach (var scene in EditorBuildSettings.scenes)
|
|
{
|
|
if (!scene.enabled) continue;
|
|
var sceneObj = EditorSceneManager.OpenScene(scene.path);
|
|
foreach (var tmpText in Object.FindObjectsOfType<TMP_Text>())
|
|
{
|
|
foreach (char c in tmpText.text) chars.Add(c);
|
|
}
|
|
}
|
|
|
|
// 3. 扫描所有预制体
|
|
string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab");
|
|
foreach (string guid in prefabGuids)
|
|
{
|
|
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
|
if (prefab == null) continue;
|
|
|
|
foreach (var tmpText in prefab.GetComponentsInChildren<TMP_Text>(true))
|
|
{
|
|
foreach (char c in tmpText.text) chars.Add(c);
|
|
}
|
|
}
|
|
|
|
// 4. 保存到文本文件
|
|
string savePath = Application.dataPath + "/player_name_chars.txt";
|
|
File.WriteAllText(savePath, new string(new List<char>(chars).ToArray()));
|
|
AssetDatabase.Refresh();
|
|
|
|
Debug.Log($"已收集 {chars.Count} 个字符,保存至:{savePath}");
|
|
}
|
|
}
|