From e55bf61b9fc949008ff996ba8c411c2c55fe4107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Wed, 15 Oct 2025 11:05:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scriptable/GameLocaizationTableEditor.cs | 73 ++++++++++++++++--- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/Editor/Localization/LocalizationTableWindow/Scriptable/GameLocaizationTableEditor.cs b/Editor/Localization/LocalizationTableWindow/Scriptable/GameLocaizationTableEditor.cs index 259364e..3079d69 100644 --- a/Editor/Localization/LocalizationTableWindow/Scriptable/GameLocaizationTableEditor.cs +++ b/Editor/Localization/LocalizationTableWindow/Scriptable/GameLocaizationTableEditor.cs @@ -11,7 +11,6 @@ namespace AlicizaX.Localization.Editor [CustomEditor(typeof(GameLocaizationTable))] internal class GameLocaizationTableEditor : InspectorEditor { - [OnOpenAsset] public static bool OnOpenAsset(int instanceId, int line) @@ -107,25 +106,71 @@ namespace AlicizaX.Localization.Editor [MenuItem("Tools/AlicizaX/Localization/Create Localization Table")] private static void CreateLocalizationTable() { - string path = "Assets/Localization/"; - string fileName = "LocalizationTable.asset"; - string finalPath = Path.Combine(path, fileName); + string selectedFolderPath = "Assets"; + + string defaultFileName = "LocalizationTable.asset"; + string defaultPath = Path.Combine(selectedFolderPath, defaultFileName); + + + string path = EditorUtility.SaveFilePanel("Create Localization Table", selectedFolderPath, defaultFileName, "asset"); + + + if (string.IsNullOrEmpty(path)) + return; + + if (!path.StartsWith(Application.dataPath)) + { + string relativePath = "Assets" + path.Replace(Application.dataPath, ""); + if (path.StartsWith(Application.dataPath)) + { + path = relativePath; + } + else + { + EditorUtility.DisplayDialog("Error", "Localization table must be saved within the project's Assets folder!", "OK"); + return; + } + } + else + { + path = "Assets" + path.Replace(Application.dataPath, ""); + } + + if (!path.EndsWith(".asset")) + { + path += ".asset"; + } + + if (AssetDatabase.LoadMainAssetAtPath(path) != null) + { + bool overwrite = EditorUtility.DisplayDialog("File Exists", + "A file with the same name already exists. Do you want to overwrite it?", + "Yes", "No"); + if (!overwrite) + return; + } GameLocaizationTable table = ScriptableObject.CreateInstance(); - if (!Directory.Exists(path)) + string directory = Path.GetDirectoryName(path); + if (!Directory.Exists(directory)) { - Directory.CreateDirectory(path); + Directory.CreateDirectory(directory); } - AssetDatabase.CreateAsset(table, finalPath); - EditorUtility.SetDirty(table); - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); + + AssetDatabase.CreateAsset(table, path); + table.TableSheet = new List(); + if (table.Languages == null) + { + table.Languages = new List(); + } + IReadOnlyList languageTypes = LocalizationConfiguration.Instance.LanguageTypeNames; + for (int i = 0; i < languageTypes.Count; i++) { LocalizationLanguage asset = ScriptableObject.CreateInstance(); @@ -134,11 +179,17 @@ namespace AlicizaX.Localization.Editor asset.Strings = new List(); table.Languages.Add(asset); AssetDatabase.AddObjectToAsset(asset, table); - EditorUtility.SetDirty(asset); } + EditorUtility.SetDirty(table); AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + + Selection.activeObject = table; + EditorGUIUtility.PingObject(table); + + Debug.Log($"Localization table created successfully at: {path}"); } } }