From f661375604d48478ea2b0716d11c9a31c336f013 Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期一, 11 五月 2026 10:53:25 +0800
Subject: [PATCH] 592 多语言适配 提交主干
---
Assets/Editor/UIComponent/TextLanguageAdapterScanTool.cs | 150 ++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 121 insertions(+), 29 deletions(-)
diff --git a/Assets/Editor/UIComponent/TextLanguageAdapterScanTool.cs b/Assets/Editor/UIComponent/TextLanguageAdapterScanTool.cs
index c72f011..4960ad9 100644
--- a/Assets/Editor/UIComponent/TextLanguageAdapterScanTool.cs
+++ b/Assets/Editor/UIComponent/TextLanguageAdapterScanTool.cs
@@ -44,7 +44,10 @@
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<PrefabScanResult> PrefabResults { get; } = new List<PrefabScanResult>();
+ public List<PrefabScanResult> PrefabResultsWithoutIssue { get; } = new List<PrefabScanResult>();
public ScanResultSummary(string dir) => ScanDirectory = dir;
@@ -55,13 +58,33 @@
{
prefabResult = new PrefabScanResult(item.PrefabPath, item.PrefabGUID);
PrefabResults.Add(prefabResult);
+ PrefabsWithIssueCount++;
}
prefabResult.Items.Add(item);
- AdaptersWithMissingConfig++;
+
+ if (item.MissingLanguages.Count > 0)
+ {
+ AdaptersWithMissingConfig++;
+ }
+ }
+
+ public void AddPrefabWithoutIssue(string path, string guid, List<ScanResultItem> items)
+ {
+ var prefabResult = new PrefabScanResult(path, guid);
+ prefabResult.Items.AddRange(items);
+ PrefabResultsWithoutIssue.Add(prefabResult);
+ PrefabsWithoutIssueCount++;
}
}
// ======================== TreeView 瀹炵幇 ========================
+
+public enum ScanResultFilterMode
+{
+ 鍏ㄩ儴,
+ 浠呮樉绀烘湁闂,
+ 浠呮樉绀烘棤闂
+}
public class MetadataTreeViewItem : TreeViewItem
{
@@ -72,10 +95,12 @@
public class ScanResultTreeView : TreeView
{
private ScanResultSummary m_Summary;
+ private ScanResultFilterMode m_FilterMode;
- public ScanResultTreeView(TreeViewState state, ScanResultSummary summary) : base(state)
+ public ScanResultTreeView(TreeViewState state, ScanResultSummary summary, ScanResultFilterMode filterMode) : base(state)
{
m_Summary = summary;
+ m_FilterMode = filterMode;
Reload();
ExpandAll();
}
@@ -84,28 +109,64 @@
{
var root = new TreeViewItem { id = 0, depth = -1, displayName = "Root" };
- // 銆愬叧閿慨澶� 1銆戯細蹇呴』鍒濆鍖� children 鍒楄〃銆�
- // 鍚﹀垯褰撴壂鎻忕粨鏋滃畬缇庯紙0涓敊璇級鏃讹紝root.children 涓� null 浼氬鑷� Unity 鎶ラ敊
root.children = new List<TreeViewItem>();
- if (m_Summary == null || m_Summary.PrefabResults.Count == 0)
+ if (m_Summary == null)
return root;
int itemId = 1;
- foreach (var prefabResult in m_Summary.PrefabResults)
- {
- string prefabName = Path.GetFileNameWithoutExtension(prefabResult.PrefabPath);
- var prefabItem = new MetadataTreeViewItem(itemId++, $"{prefabName} ({prefabResult.Items.Count}涓棶棰�)", prefabResult);
- foreach (var adapterItem in prefabResult.Items)
+ bool showWithIssue = m_FilterMode == ScanResultFilterMode.鍏ㄩ儴 ||
+ m_FilterMode == ScanResultFilterMode.浠呮樉绀烘湁闂;
+ bool showWithoutIssue = m_FilterMode == ScanResultFilterMode.鍏ㄩ儴 ||
+ m_FilterMode == ScanResultFilterMode.浠呮樉绀烘棤闂;
+
+ if (showWithIssue)
+ {
+ foreach (var prefabResult in m_Summary.PrefabResults)
{
- var adapterTreeItem = new MetadataTreeViewItem(itemId++, adapterItem.GetDisplayName(), adapterItem);
- prefabItem.AddChild(adapterTreeItem);
+ 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 MetadataTreeViewItem(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 MetadataTreeViewItem(itemId++, displayName, adapterItem);
+ prefabItem.AddChild(adapterTreeItem);
+ }
+ root.AddChild(prefabItem);
}
- root.AddChild(prefabItem);
}
- // 銆愬叧閿慨澶� 2銆戯細Unity 瀹樻柟瑙勮寖瑕佹眰锛屾墜鍔ㄤ娇鐢� AddChild 鏋勫缓鏍戜箣鍚庯紝蹇呴』璋冪敤姝ゆ柟娉曞埛鏂版繁搴﹀拰灞傜骇鍏崇郴
+ if (showWithoutIssue)
+ {
+ foreach (var prefabResult in m_Summary.PrefabResultsWithoutIssue)
+ {
+ string prefabName = Path.GetFileNameWithoutExtension(prefabResult.PrefabPath);
+ var prefabItem = new MetadataTreeViewItem(itemId++, $"{prefabName} (鏃犻棶棰�)", prefabResult);
+
+ foreach (var adapterItem in prefabResult.Items)
+ {
+ var displayName = $"{adapterItem.GameObjectPath} (閰嶇疆瀹屾暣)";
+ var adapterTreeItem = new MetadataTreeViewItem(itemId++, displayName, adapterItem);
+ prefabItem.AddChild(adapterTreeItem);
+ }
+ root.AddChild(prefabItem);
+ }
+ }
+
SetupDepthsFromParentsAndChildren(root);
return root;
@@ -117,7 +178,12 @@
if (item != null && item.Metadata is PrefabScanResult)
GUI.Label(args.rowRect, item.displayName, EditorStyles.boldLabel);
else if (item != null && item.Metadata is ScanResultItem adapterItem)
- GUI.Label(args.rowRect, $"{adapterItem.GameObjectPath} (缂哄皯: {string.Join(", ", adapterItem.MissingLanguages)})");
+ {
+ 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);
}
@@ -173,8 +239,8 @@
private ScanResultTreeView m_TreeView;
private TreeViewState m_TreeViewState;
+ private ScanResultFilterMode m_ResultFilterMode = ScanResultFilterMode.鍏ㄩ儴;
- // 鎵归噺鎿嶄綔鐨刄I鐘舵��
private int m_SourceLangIndex = 0;
private int m_TargetLangIndex = 0;
private bool m_OverwriteExisting = false;
@@ -279,7 +345,20 @@
if (m_ScanResult != null)
{
- EditorGUILayout.LabelField($"棰勫埗浣撴�绘暟: {m_ScanResult.TotalPrefabsScanned} | Adapter鎬绘暟: {m_ScanResult.TotalAdaptersFound} | 缂哄け閰嶇疆: {m_ScanResult.AdaptersWithMissingConfig}");
+ EditorGUILayout.LabelField($"棰勫埗浣撴�绘暟: {m_ScanResult.TotalPrefabsScanned} | 鏈堿dapter鐨勯鍒朵綋: {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 = (ScanResultFilterMode)EditorGUILayout.EnumPopup(m_ResultFilterMode);
+ if (EditorGUI.EndChangeCheck() && m_TreeView != null)
+ {
+ m_TreeViewState ??= new TreeViewState();
+ m_TreeView = new ScanResultTreeView(m_TreeViewState, m_ScanResult, m_ResultFilterMode);
+ }
+ }
EditorGUILayout.Space(5f);
if (m_TreeView != null)
@@ -304,7 +383,6 @@
}
}
- // ======================== 鏂板锛氭壒閲忔搷浣滃姛鑳� ========================
private void DrawBatchOperations()
{
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
@@ -370,7 +448,6 @@
string path = AssetDatabase.GUIDToAssetPath(prefabGuids[i]);
EditorUtility.DisplayProgressBar("鎵归噺澶嶅埗閰嶇疆", $"澶勭悊涓� ({i + 1}/{prefabGuids.Length}): {path}", (float)i / prefabGuids.Length);
- // 銆愭牳蹇冧慨鏀广�戯細鐩存帴鍔犺浇璧勪骇鍐呭瓨锛屼笉浣跨敤 LoadPrefabContents 杩涜瀹炰緥鍖�
GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>(path);
bool isModified = false;
@@ -380,7 +457,6 @@
{
if (m_OverwriteExisting || !adapter.HasConfig(targetLang))
{
- // 蹇呴』鏍囪瀵硅薄涓鸿剰锛屽惁鍒� Unity 涓嶄細鎶婅祫浜х殑淇敼瀛樼洏
Undo.RecordObject(adapter, "Batch Copy Language Config");
var clonedConfig = adapter.GetConfig(sourceLang).Clone();
@@ -402,7 +478,6 @@
finally
{
EditorUtility.ClearProgressBar();
- // 缁熶竴淇濆瓨鎵�鏈夋爣璁颁负 Dirty 鐨勮祫浜т慨鏀�
AssetDatabase.SaveAssets();
PerformScan();
@@ -412,8 +487,6 @@
"纭");
}
}
-
- // ======================== 鏍稿績鎵弿閫昏緫 ========================
private void StartScan()
{
@@ -460,7 +533,7 @@
}
m_TreeViewState ??= new TreeViewState();
- m_TreeView = new ScanResultTreeView(m_TreeViewState, m_ScanResult);
+ m_TreeView = new ScanResultTreeView(m_TreeViewState, m_ScanResult, m_ResultFilterMode);
m_ScanStatus = $"鎵弿瀹屾垚! 鍙戠幇 {m_ScanResult.AdaptersWithMissingConfig} 涓己澶遍厤缃�";
Repaint();
}
@@ -471,8 +544,12 @@
if (prefab == null) return;
var adapters = prefab.GetComponentsInChildren<TextLanguageAdapter>(true);
-
+ if (adapters.Length == 0) return;
+
m_ScanResult.TotalAdaptersFound += adapters.Length;
+
+ bool hasIssue = false;
+ List<ScanResultItem> allItems = new List<ScanResultItem>();
foreach (var adapter in adapters)
{
@@ -483,15 +560,30 @@
if (!adapter.HasConfig(langId)) missing.Add(langId);
}
+ var item = new ScanResultItem(path, GetGameObjectPath(adapter.gameObject, prefab), adapter.TargetTextType, guid)
+ {
+ MissingLanguages = missing
+ };
+
+ allItems.Add(item);
+
if (missing.Count > 0)
{
- var item = new ScanResultItem(path, GetGameObjectPath(adapter.gameObject, prefab), adapter.TargetTextType, guid)
- {
- MissingLanguages = missing
- };
+ 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)
--
Gitblit v1.8.0