三国卡牌客户端基础资源仓库
yyl
2026-05-15 ed78a369fb55ddaaab42508553e066317f285cd9
Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_client
6个文件已添加
880 ■■■■■ 已修改文件
Assets/Editor/UIComponent/CommonLanguageAdapterEditor.cs 188 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/UIComponent/CommonLanguageAdapterEditor.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/UIComponent/CommonLanguageAdapterHelper.cs 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/UIComponent/CommonLanguageAdapterHelper.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/UIComponent/CommonLanguageAdapterScanTool.cs 593 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/UIComponent/CommonLanguageAdapterScanTool.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/UIComponent/CommonLanguageAdapterEditor.cs
New file
@@ -0,0 +1,188 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(CommonLanguageAdapter), true)]
[CanEditMultipleObjects]
public class CommonLanguageAdapterEditor : Editor
{
    private Dictionary<string, bool> m_FoldoutStates = new Dictionary<string, bool>();
    private void OnEnable()
    {
        CommonLanguageAdapterHelper.Initialize();
        if (target is CommonLanguageAdapter adapter)
        {
            if (!adapter.HasConfig(CommonLanguageAdapter.DefaultLangId))
            {
                adapter.ReadCurrentToConfig(CommonLanguageAdapter.DefaultLangId);
                EditorUtility.SetDirty(adapter);
            }
            foreach (var langId in adapter.GetConfiguredLanguages()) m_FoldoutStates.TryAdd(langId, false);
        }
    }
    public override void OnInspectorGUI()
    {
        var adapter = target as CommonLanguageAdapter;
        DrawBasicInfo(adapter);
        EditorGUILayout.Space();
        DrawLanguageConfigs(adapter);
        if (GUI.changed) EditorUtility.SetDirty(target);
    }
    private void DrawBasicInfo(CommonLanguageAdapter adapter)
    {
        using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
        {
            EditorGUILayout.LabelField("基本信息", EditorStyles.boldLabel);
            EditorGUI.BeginChangeCheck();
            RectTransform newTarget = (RectTransform)EditorGUILayout.ObjectField("目标 RectTransform", adapter.TargetRectTransform, typeof(RectTransform), true);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(adapter, "Update Basic Info");
                adapter.TargetRectTransform = newTarget;
            }
            EditorGUILayout.HelpBox("留空则默认控制本物体的 RectTransform。修改组件状态 (enabled) 会直接影响其所在 GameObject 的 Active 状态。", MessageType.Info);
        }
    }
    private void DrawLanguageConfigs(CommonLanguageAdapter adapter)
    {
        using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
        {
            EditorGUILayout.LabelField("语言排版配置", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("default仅用于编辑时恢复初始状态,无对应语言配置时用组件当前状态", MessageType.Info);
            foreach (var langId in adapter.GetConfiguredLanguages()) DrawLanguageConfigItem(adapter, langId);
            EditorGUILayout.Space();
            DrawAddLanguageConfig(adapter);
        }
    }
    private void DrawLanguageConfigItem(CommonLanguageAdapter adapter, string langId)
    {
        m_FoldoutStates.TryAdd(langId, false);
        int presetIndex = System.Array.IndexOf(CommonLanguageAdapterHelper.PresetLanguageIds, langId);
        string name = presetIndex >= 0 ? CommonLanguageAdapterHelper.PresetLanguageNames[presetIndex] : CommonLanguageAdapter.GetLanguageShowName(langId);
        string label = string.IsNullOrEmpty(name) ? langId : $"{langId} ({name})";
        EditorGUI.indentLevel++;
        if (langId == CommonLanguageAdapter.DefaultLangId) GUI.backgroundColor = new Color(1f, 0.9f, 0.7f);
        m_FoldoutStates[langId] = EditorGUILayout.Foldout(m_FoldoutStates[langId], label, true);
        GUI.backgroundColor = Color.white;
        if (m_FoldoutStates[langId])
        {
            EditorGUI.indentLevel++;
            var config = adapter.LanguageConfigs.Get(langId);
            if (config != null)
            {
                DrawConfigItem(config);
                EditorGUILayout.Space();
                DrawConfigItemActions(adapter, langId);
            }
            EditorGUI.indentLevel--;
        }
        EditorGUI.indentLevel--;
    }
    private void DrawConfigItem(CommonLanguageConfigItem cfg)
    {
        EditorGUILayout.LabelField("RectTransform 配置", EditorStyles.miniBoldLabel);
        EditorGUI.BeginChangeCheck();
        cfg.anchoredPosition = EditorGUILayout.Vector2Field("Anchored Position", cfg.anchoredPosition);
        cfg.sizeDelta = EditorGUILayout.Vector2Field("Size Delta", cfg.sizeDelta);
        cfg.anchorMin = EditorGUILayout.Vector2Field("Anchor Min", cfg.anchorMin);
        cfg.anchorMax = EditorGUILayout.Vector2Field("Anchor Max", cfg.anchorMax);
        cfg.pivot = EditorGUILayout.Vector2Field("Pivot", cfg.pivot);
        cfg.localScale = EditorGUILayout.Vector3Field("Local Scale", cfg.localScale);
        cfg.localRotation = EditorGUILayout.Vector3Field("Local Rotation", cfg.localRotation);
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("基础配置", EditorStyles.miniBoldLabel);
        cfg.enabled = EditorGUILayout.Toggle("显示 (Active)", cfg.enabled);
        if (EditorGUI.EndChangeCheck()) EditorUtility.SetDirty(target);
    }
    private void DrawConfigItemActions(CommonLanguageAdapter adapter, string langId)
    {
        using (new EditorGUILayout.HorizontalScope())
        {
            GUILayout.Space(EditorGUI.indentLevel * 15f);
            if (GUILayout.Button("从当前读取", GUILayout.Width(80)))
            {
                Undo.RecordObject(adapter, "Read Current Config");
                adapter.ReadCurrentToConfig(langId);
            }
            if (GUILayout.Button("应用", GUILayout.Width(60)))
            {
                Undo.RecordObject(adapter, "Apply Config");
                adapter.ApplyConfig(langId);
            }
            using (new EditorGUI.DisabledScope(langId == CommonLanguageAdapter.DefaultLangId))
            {
                if (GUILayout.Button("删除", GUILayout.Width(50)))
                {
                    Undo.RecordObject(adapter, "Remove Config");
                    adapter.RemoveConfig(langId);
                    m_FoldoutStates.Remove(langId);
                }
            }
        }
    }
    private void DrawAddLanguageConfig(CommonLanguageAdapter adapter)
    {
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(15f);
        EditorGUILayout.LabelField("添加预设语言:", GUILayout.Width(100));
        float viewWidth = EditorGUIUtility.currentViewWidth - 30f;
        float currentWidth = 115f;
        float buttonWidth = 64f;
        for (int i = 0; i < CommonLanguageAdapterHelper.PresetLanguageIds.Length; i++)
        {
            string langId = CommonLanguageAdapterHelper.PresetLanguageIds[i];
            if (!adapter.HasConfig(langId))
            {
                if (currentWidth + buttonWidth > viewWidth)
                {
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(115f);
                    currentWidth = 115f;
                }
                if (GUILayout.Button(CommonLanguageAdapterHelper.PresetLanguageNames[i], GUILayout.Width(60)))
                {
                    Undo.RecordObject(adapter, "Add Language Config");
                    var newConfig = adapter.HasConfig(CommonLanguageAdapter.DefaultLangId)
                        ? adapter.LanguageConfigs.Get(CommonLanguageAdapter.DefaultLangId).Clone()
                        : new CommonLanguageConfigItem();
                    adapter.SetConfig(langId, newConfig);
                    m_FoldoutStates[langId] = true;
                }
                currentWidth += buttonWidth;
            }
        }
        EditorGUILayout.EndHorizontal();
    }
}
Assets/Editor/UIComponent/CommonLanguageAdapterEditor.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8dbb6e90c0c026a4595e16a47e779cb5
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/Editor/UIComponent/CommonLanguageAdapterHelper.cs
New file
@@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.IO;
using LitJson;
using UnityEngine;
/// <summary>
/// 编辑器通用语言配置读取助手
/// </summary>
public static class CommonLanguageAdapterHelper
{
    public static string[] PresetLanguageIds { get; private set; }
    public static string[] PresetLanguageNames { get; private set; }
    private static bool s_Initialized;
    public static void Initialize()
    {
        if (s_Initialized) return;
        var idList = new List<string> { CommonLanguageAdapter.DefaultLangId };
        var nameList = new List<string> { "默认" };
        string configPath = Path.Combine(Application.dataPath, "ResourcesOut/Config/InitialFunction.txt");
        if (File.Exists(configPath))
        {
            try
            {
                string[] lines = File.ReadAllLines(configPath);
                for (int i = 3; i < lines.Length; i++)
                {
                    string line = lines[i];
                    if (string.IsNullOrWhiteSpace(line)) continue;
                    int index = line.IndexOf('\t');
                    if (index == -1) continue;
                    string key = line.Substring(0, index);
                    if (key == "LanguageEx")
                    {
                        string[] fields = line.Split('\t');
                        if (fields.Length > 1 && !string.IsNullOrEmpty(fields[1]))
                        {
                            var dict = JsonMapper.ToObject<Dictionary<string, string>>(fields[1]);
                            if (dict != null)
                            {
                                foreach (var kvp in dict)
                                {
                                    idList.Add(kvp.Key);
                                    nameList.Add(kvp.Value);
                                }
                            }
                        }
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning($"[CommonLanguageAdapterHelper] 读取配置失败: {ex.Message}");
            }
        }
        PresetLanguageIds = idList.ToArray();
        PresetLanguageNames = nameList.ToArray();
        s_Initialized = true;
    }
}
Assets/Editor/UIComponent/CommonLanguageAdapterHelper.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49e8aba27e9412b48bf84c3a91a5b701
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/Editor/UIComponent/CommonLanguageAdapterScanTool.cs
New file
@@ -0,0 +1,593 @@
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
public class CommonScanResultItem
{
    public string PrefabPath { get; }
    public string GameObjectPath { get; }
    public List<string> MissingLanguages { get; set; } = new List<string>();
    public string PrefabGUID { get; }
    public CommonScanResultItem(string path, string goPath, string guid)
    {
        PrefabPath = path;
        GameObjectPath = goPath;
        PrefabGUID = guid;
    }
    public string GetDisplayName() => $"{GameObjectPath} (缺少: {string.Join(", ", MissingLanguages)})";
}
public class CommonPrefabScanResult
{
    public string PrefabPath { get; }
    public string PrefabGUID { get; }
    public List<CommonScanResultItem> Items { get; } = new List<CommonScanResultItem>();
    public CommonPrefabScanResult(string path, string guid)
    {
        PrefabPath = path;
        PrefabGUID = guid;
    }
}
public class CommonScanResultSummary
{
    public string ScanDirectory { get; }
    public int TotalPrefabsScanned { get; set; }
    public int TotalAdaptersFound { get; set; }
    public int AdaptersWithMissingConfig { get; private set; }
    public int PrefabsWithIssueCount { get; private set; }
    public int PrefabsWithoutIssueCount { get; private set; }
    public List<CommonPrefabScanResult> PrefabResults { get; } = new List<CommonPrefabScanResult>();
    public List<CommonPrefabScanResult> PrefabResultsWithoutIssue { get; } = new List<CommonPrefabScanResult>();
    public CommonScanResultSummary(string dir) => ScanDirectory = dir;
    public void AddResult(CommonScanResultItem item)
    {
        var prefabResult = PrefabResults.Find(p => p.PrefabPath == item.PrefabPath);
        if (prefabResult == null)
        {
            prefabResult = new CommonPrefabScanResult(item.PrefabPath, item.PrefabGUID);
            PrefabResults.Add(prefabResult);
            PrefabsWithIssueCount++;
        }
        prefabResult.Items.Add(item);
        if (item.MissingLanguages.Count > 0)
        {
            AdaptersWithMissingConfig++;
        }
    }
    public void AddPrefabWithoutIssue(string path, string guid, List<CommonScanResultItem> items)
    {
        var prefabResult = new CommonPrefabScanResult(path, guid);
        prefabResult.Items.AddRange(items);
        PrefabResultsWithoutIssue.Add(prefabResult);
        PrefabsWithoutIssueCount++;
    }
}
public enum CommonScanResultFilterMode
{
    全部,
    仅显示有问题,
    仅显示无问题
}
public class CommonMetadataTreeViewItem : TreeViewItem
{
    public object Metadata { get; }
    public CommonMetadataTreeViewItem(int id, string name, object meta) : base(id, 0, name) => Metadata = meta;
}
public class CommonScanResultTreeView : TreeView
{
    private CommonScanResultSummary m_Summary;
    private CommonScanResultFilterMode m_FilterMode;
    public CommonScanResultTreeView(TreeViewState state, CommonScanResultSummary summary, CommonScanResultFilterMode filterMode) : base(state)
    {
        m_Summary = summary;
        m_FilterMode = filterMode;
        Reload();
        ExpandAll();
    }
    protected override TreeViewItem BuildRoot()
    {
        var root = new TreeViewItem { id = 0, depth = -1, displayName = "Root" };
        root.children = new List<TreeViewItem>();
        if (m_Summary == null)
            return root;
        int itemId = 1;
        bool showWithIssue = m_FilterMode == CommonScanResultFilterMode.全部 ||
                             m_FilterMode == CommonScanResultFilterMode.仅显示有问题;
        bool showWithoutIssue = m_FilterMode == CommonScanResultFilterMode.全部 ||
                                m_FilterMode == CommonScanResultFilterMode.仅显示无问题;
        if (showWithIssue)
        {
            foreach (var prefabResult in m_Summary.PrefabResults)
            {
                string prefabName = Path.GetFileNameWithoutExtension(prefabResult.PrefabPath);
                int issueCount = 0;
                foreach (var item in prefabResult.Items)
                {
                    if (item.MissingLanguages != null && item.MissingLanguages.Count > 0)
                        issueCount++;
                }
                var prefabItem = new CommonMetadataTreeViewItem(itemId++, $"{prefabName} ({issueCount}个问题)", prefabResult);
                foreach (var adapterItem in prefabResult.Items)
                {
                    string displayName;
                    if (adapterItem.MissingLanguages.Count > 0)
                        displayName = adapterItem.GetDisplayName();
                    else
                        displayName = $"{adapterItem.GameObjectPath} (配置完整)";
                    var adapterTreeItem = new CommonMetadataTreeViewItem(itemId++, displayName, adapterItem);
                    prefabItem.AddChild(adapterTreeItem);
                }
                root.AddChild(prefabItem);
            }
        }
        if (showWithoutIssue)
        {
            foreach (var prefabResult in m_Summary.PrefabResultsWithoutIssue)
            {
                string prefabName = Path.GetFileNameWithoutExtension(prefabResult.PrefabPath);
                var prefabItem = new CommonMetadataTreeViewItem(itemId++, $"{prefabName} (无问题)", prefabResult);
                foreach (var adapterItem in prefabResult.Items)
                {
                    var displayName = $"{adapterItem.GameObjectPath} (配置完整)";
                    var adapterTreeItem = new CommonMetadataTreeViewItem(itemId++, displayName, adapterItem);
                    prefabItem.AddChild(adapterTreeItem);
                }
                root.AddChild(prefabItem);
            }
        }
        SetupDepthsFromParentsAndChildren(root);
        return root;
    }
    protected override void RowGUI(RowGUIArgs args)
    {
        var item = args.item as CommonMetadataTreeViewItem;
        if (item != null && item.Metadata is CommonPrefabScanResult)
            GUI.Label(args.rowRect, item.displayName, EditorStyles.boldLabel);
        else if (item != null && item.Metadata is CommonScanResultItem adapterItem)
        {
            if (adapterItem.MissingLanguages.Count > 0)
                GUI.Label(args.rowRect, $"{adapterItem.GameObjectPath} (缺少: {string.Join(", ", adapterItem.MissingLanguages)})");
            else
                GUI.Label(args.rowRect, item.displayName);
        }
        else
            base.RowGUI(args);
    }
    protected override void DoubleClickedItem(int id)
    {
        var item = FindItem(id, rootItem) as CommonMetadataTreeViewItem;
        if (item == null) return;
        if (item.Metadata is CommonScanResultItem adapterItem)
            PingGameObject(adapterItem.PrefabPath, adapterItem.GameObjectPath);
        else if (item.Metadata is CommonPrefabScanResult prefabResult)
        {
            var obj = AssetDatabase.LoadAssetAtPath<GameObject>(prefabResult.PrefabPath);
            if (obj != null)
            {
                Selection.activeObject = obj;
                EditorGUIUtility.PingObject(obj);
            }
        }
    }
    private void PingGameObject(string prefabPath, string gameObjectPath)
    {
        var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
        if (prefab == null) return;
        Transform target = prefab.transform.Find(gameObjectPath);
        if (target != null)
        {
            Selection.activeObject = target.gameObject;
            EditorGUIUtility.PingObject(target.gameObject);
        }
        else
        {
            Selection.activeObject = prefab;
            EditorGUIUtility.PingObject(prefab);
            Debug.LogWarning($"[CommonScanTool] 找不到路径 '{gameObjectPath}',已选中整个预制体");
        }
    }
}
public class CommonLanguageAdapterScanTool : EditorWindow
{
    private string m_ScanDirectory = "Assets";
    private Vector2 m_ScrollPosition;
    private CommonScanResultSummary m_ScanResult;
    private bool m_IsScanning;
    private float m_ScanProgress;
    private string m_ScanStatus;
    private CommonScanResultTreeView m_TreeView;
    private TreeViewState m_TreeViewState;
    private CommonScanResultFilterMode m_ResultFilterMode = CommonScanResultFilterMode.全部;
    private int m_SourceLangIndex = 0;
    private int m_TargetLangIndex = 0;
    private bool m_OverwriteExisting = false;
    [MenuItem("程序/CommonLanguageAdapter扫描与管理工具")]
    public static void ShowWindow()
    {
        var window = GetWindow<CommonLanguageAdapterScanTool>("通用排版适配器扫描");
        window.minSize = new Vector2(600f, 500f);
    }
    private void OnEnable() => CommonLanguageAdapterHelper.Initialize();
    private void OnGUI()
    {
        DrawHeader();
        EditorGUILayout.Space(5f);
        DrawScanSettings();
        EditorGUILayout.Space(5f);
        DrawScanButton();
        EditorGUILayout.Space(5f);
        DrawResults();
        EditorGUILayout.Space(5f);
        DrawBatchOperations();
    }
    private void DrawHeader()
    {
        using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
        {
            EditorGUILayout.LabelField("CommonLanguageAdapter 配置缺失扫描与批量操作工具", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("扫描指定目录下所有预制体,检测组件的语言配置是否完整,或执行批量语言配置复制。", MessageType.Info);
        }
    }
    private void DrawScanSettings()
    {
        using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
        {
            EditorGUILayout.LabelField("扫描设置", EditorStyles.boldLabel);
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("目标目录:", GUILayout.Width(80f));
                m_ScanDirectory = EditorGUILayout.TextField(m_ScanDirectory);
                if (GUILayout.Button("选择...", GUILayout.Width(70f)))
                {
                    string path = EditorUtility.OpenFolderPanel("选择扫描目录", Application.dataPath, "");
                    if (!string.IsNullOrEmpty(path))
                        m_ScanDirectory = path.StartsWith(Application.dataPath) ? "Assets" + path.Substring(Application.dataPath.Length) : path;
                }
            }
            EditorGUILayout.Space(5f);
            EditorGUILayout.LabelField($"预设语言:");
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(15f);
            int displayCount = 0;
            foreach (var langId in CommonLanguageAdapterHelper.PresetLanguageIds)
            {
                if (langId == CommonLanguageAdapter.DefaultLangId) continue;
                EditorGUILayout.LabelField(langId, GUILayout.Width(50f));
                if (++displayCount % 8 == 0)
                {
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(15f);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
    }
    private void DrawScanButton()
    {
        using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                using (new EditorGUI.DisabledScope(m_IsScanning || string.IsNullOrEmpty(m_ScanDirectory)))
                {
                    if (GUILayout.Button("开始扫描", GUILayout.Height(30f))) StartScan();
                }
                if (m_IsScanning)
                {
                    EditorGUILayout.LabelField("扫描中...", GUILayout.Width(100f));
                    m_ScanProgress = EditorGUILayout.Slider(m_ScanProgress, 0f, 1f);
                    Repaint();
                }
            }
            if (!string.IsNullOrEmpty(m_ScanStatus)) EditorGUILayout.LabelField(m_ScanStatus);
        }
    }
    private void DrawResults()
    {
        using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
        {
            EditorGUILayout.LabelField("扫描结果", EditorStyles.boldLabel);
            if (m_ScanResult != null)
            {
                EditorGUILayout.LabelField($"预制体总数: {m_ScanResult.TotalPrefabsScanned} | 有Adapter的预制体: {m_ScanResult.PrefabsWithIssueCount + m_ScanResult.PrefabsWithoutIssueCount} | Adapter总数: {m_ScanResult.TotalAdaptersFound} | 缺失配置: {m_ScanResult.AdaptersWithMissingConfig} | 有问题预制体: {m_ScanResult.PrefabsWithIssueCount} | 无问题预制体: {m_ScanResult.PrefabsWithoutIssueCount}");
                EditorGUILayout.Space(5f);
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.LabelField("显示模式:", GUILayout.Width(60f));
                    EditorGUI.BeginChangeCheck();
                    m_ResultFilterMode = (CommonScanResultFilterMode)EditorGUILayout.EnumPopup(m_ResultFilterMode);
                    if (EditorGUI.EndChangeCheck() && m_TreeView != null)
                    {
                        m_TreeViewState ??= new TreeViewState();
                        m_TreeView = new CommonScanResultTreeView(m_TreeViewState, m_ScanResult, m_ResultFilterMode);
                    }
                }
                EditorGUILayout.Space(5f);
                if (m_TreeView != null)
                {
                    m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition, GUILayout.MinHeight(150f));
                    var rect = EditorGUILayout.GetControlRect(false, m_TreeView.totalHeight);
                    m_TreeView.OnGUI(rect);
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.Space(5f);
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("展开全部")) m_TreeView?.ExpandAll();
                    if (GUILayout.Button("折叠全部")) m_TreeView?.CollapseAll();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("点击「开始扫描」按钮进行扫描", MessageType.None);
            }
        }
    }
    private void DrawBatchOperations()
    {
        using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
        {
            EditorGUILayout.LabelField("批量操作 (针对目标目录下的所有预制体上的CommonLanguageAdapter组件)", EditorStyles.boldLabel);
            if (CommonLanguageAdapterHelper.PresetLanguageIds == null || CommonLanguageAdapterHelper.PresetLanguageIds.Length == 0)
                return;
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("旧语言:", GUILayout.Width(60f));
                m_SourceLangIndex = EditorGUILayout.Popup(m_SourceLangIndex, CommonLanguageAdapterHelper.PresetLanguageNames);
                GUILayout.Space(20f);
                EditorGUILayout.LabelField("新语言:", GUILayout.Width(60f));
                m_TargetLangIndex = EditorGUILayout.Popup(m_TargetLangIndex, CommonLanguageAdapterHelper.PresetLanguageNames);
            }
            m_OverwriteExisting = EditorGUILayout.Toggle("覆盖已存在的目标配置", m_OverwriteExisting);
            EditorGUILayout.Space(5f);
            bool isSameLanguage = m_SourceLangIndex == m_TargetLangIndex;
            using (new EditorGUI.DisabledScope(isSameLanguage || m_IsScanning || string.IsNullOrEmpty(m_ScanDirectory)))
            {
                if (GUILayout.Button("批量复制配置", GUILayout.Height(30f)))
                {
                    string sourceLang = CommonLanguageAdapterHelper.PresetLanguageIds[m_SourceLangIndex];
                    string targetLang = CommonLanguageAdapterHelper.PresetLanguageIds[m_TargetLangIndex];
                    if (EditorUtility.DisplayDialog("高危操作确认",
                        $"此操作将遍历【{m_ScanDirectory}】下所有预制体。\n\n" +
                        $"把它们的 [{sourceLang}] 配置复制并应用到 [{targetLang}] 配置上。\n\n" +
                        $"此操作不可撤销!建议提前使用 Git/SVN 提交代码。\n确定要继续吗?",
                        "确定执行", "取消"))
                    {
                        ExecuteBatchCopy(sourceLang, targetLang);
                    }
                }
            }
            if (isSameLanguage)
            {
                EditorGUILayout.HelpBox("旧语言与新语言不能相同", MessageType.Warning);
            }
        }
    }
    private void ExecuteBatchCopy(string sourceLang, string targetLang)
    {
        string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab", new[] { m_ScanDirectory });
        if (prefabGuids.Length == 0) return;
        int modifiedPrefabCount = 0;
        int modifiedAdapterCount = 0;
        try
        {
            for (int i = 0; i < prefabGuids.Length; i++)
            {
                string path = AssetDatabase.GUIDToAssetPath(prefabGuids[i]);
                EditorUtility.DisplayProgressBar("批量复制配置", $"处理中 ({i + 1}/{prefabGuids.Length}): {path}", (float)i / prefabGuids.Length);
                GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>(path);
                bool isModified = false;
                foreach (var adapter in prefabAsset.GetComponentsInChildren<CommonLanguageAdapter>(true))
                {
                    if (adapter.HasConfig(sourceLang))
                    {
                        if (m_OverwriteExisting || !adapter.HasConfig(targetLang))
                        {
                            Undo.RecordObject(adapter, "Batch Copy Language Config");
                            var clonedConfig = adapter.GetConfig(sourceLang).Clone();
                            adapter.SetConfig(targetLang, clonedConfig);
                            EditorUtility.SetDirty(adapter);
                            isModified = true;
                            modifiedAdapterCount++;
                        }
                    }
                }
                if (isModified)
                {
                    modifiedPrefabCount++;
                }
            }
        }
        finally
        {
            EditorUtility.ClearProgressBar();
            AssetDatabase.SaveAssets();
            PerformScan();
            EditorUtility.DisplayDialog("批量操作完成",
                $"批量复制结束!\n\n修改的预制体数量: {modifiedPrefabCount} 个\n更新的适配器配置数量: {modifiedAdapterCount} 个",
                "确认");
        }
    }
    private void StartScan()
    {
        m_IsScanning = true;
        m_ScanProgress = 0f;
        m_ScanStatus = "准备扫描...";
        EditorApplication.CallbackFunction updateCallback = null;
        updateCallback = () =>
        {
            if (!m_IsScanning)
            {
                EditorApplication.update -= updateCallback;
                return;
            }
            PerformScan();
            m_IsScanning = false;
            EditorApplication.update -= updateCallback;
        };
        EditorApplication.update += updateCallback;
    }
    private void PerformScan()
    {
        m_ScanResult = new CommonScanResultSummary(m_ScanDirectory);
        string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab", new[] { m_ScanDirectory });
        m_ScanResult.TotalPrefabsScanned = prefabGuids.Length;
        if (prefabGuids.Length == 0)
        {
            m_ScanStatus = "未找到任何预制体";
            return;
        }
        for (int i = 0; i < prefabGuids.Length; i++)
        {
            string path = AssetDatabase.GUIDToAssetPath(prefabGuids[i]);
            ScanPrefab(path, prefabGuids[i]);
            m_ScanProgress = (float)(i + 1) / prefabGuids.Length;
            m_ScanStatus = $"正在扫描: {Path.GetFileName(path)} ({i + 1}/{prefabGuids.Length})";
            if (i % 10 == 0) Repaint();
        }
        m_TreeViewState ??= new TreeViewState();
        m_TreeView = new CommonScanResultTreeView(m_TreeViewState, m_ScanResult, m_ResultFilterMode);
        m_ScanStatus = $"扫描完成! 发现 {m_ScanResult.AdaptersWithMissingConfig} 个缺失配置";
        Repaint();
    }
    private void ScanPrefab(string path, string guid)
    {
        GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
        if (prefab == null) return;
        var adapters = prefab.GetComponentsInChildren<CommonLanguageAdapter>(true);
        if (adapters.Length == 0) return;
        m_ScanResult.TotalAdaptersFound += adapters.Length;
        bool hasIssue = false;
        List<CommonScanResultItem> allItems = new List<CommonScanResultItem>();
        foreach (var adapter in adapters)
        {
            List<string> missing = new List<string>();
            foreach (var langId in CommonLanguageAdapterHelper.PresetLanguageIds)
            {
                if (langId == CommonLanguageAdapter.DefaultLangId) continue;
                if (!adapter.HasConfig(langId)) missing.Add(langId);
            }
            // 此处去除了对组件类型的引用传参
            var item = new CommonScanResultItem(path, GetGameObjectPath(adapter.gameObject, prefab), guid)
            {
                MissingLanguages = missing
            };
            allItems.Add(item);
            if (missing.Count > 0)
            {
                hasIssue = true;
            }
        }
        if (hasIssue)
        {
            foreach (var item in allItems)
            {
                m_ScanResult.AddResult(item);
            }
        }
        else
        {
            m_ScanResult.AddPrefabWithoutIssue(path, guid, allItems);
        }
    }
    private string GetGameObjectPath(GameObject go, GameObject root)
    {
        var parts = new List<string>();
        Transform curr = go.transform;
        while (curr != null && curr != root.transform)
        {
            parts.Insert(0, curr.name);
            curr = curr.parent;
        }
        return string.Join("/", parts);
    }
}
Assets/Editor/UIComponent/CommonLanguageAdapterScanTool.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5663d366e7b6b1c44b005bfdc1dc8d0f
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant: