From cb64f1cde0d11b42525b25f1ab1423023500a623 Mon Sep 17 00:00:00 2001 From: Usevalad Buben Date: Wed, 28 Oct 2026 11:49:19 +0300 Subject: [PATCH 1/2] Regenerate on table save after metadata edits and ask on settings changes Editing Smart Parameter Types metadata no longer regenerates on every click; the asset postprocessor regenerates when the table is saved. On Metadata Edit restores regeneration after each edit. Every setting that changes the generated code now asks whether to regenerate, as the smart string settings already did, and Silently On Settings Change regenerates without asking. Key Separators is a delayed field, so typing asks once. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 14 ++++ README.md | 6 +- Unity-Package/Assets/root/CHANGELOG.md | 14 ++++ .../Assets/root/Editor/CodegenSettings.cs | 6 ++ .../Assets/root/Editor/SettingsGui.cs | 73 +++++++++++++++---- .../root/Editor/SmartParameterTypesDrawer.cs | 16 +++- Unity-Package/Assets/root/README.md | 6 +- 7 files changed, 114 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b26b28..1e5dc21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [1.3.3] - 2026-10-28 + +### Added +- **Silently On Settings Change**: regenerate without asking when a setting that changes the generated code is + edited. Off by default. +- **On Metadata Edit**: regenerate on every edit of the **Smart Parameter Types** metadata. Off by default. + +### Changed +- Editing **Smart Parameter Types** metadata no longer regenerates on every click; the code regenerates when the + table is saved. +- Every setting that changes the generated code (namespace, output folder, table kinds, members, naming, `.asmdef`) + now asks whether to regenerate, like **Smart Strings** and **Smart Parameter Types** already did. +- **Key Separators** applies when you press Enter or leave the field, so typing asks to regenerate once. + ## [1.3.2] - 2026-10-28 ### Added diff --git a/README.md b/README.md index 619151d..3b397db 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,7 @@ public static string Greeting(object arg0, int count) - Variables provided by a **Global Variables Group** are not parameters; Unity resolves them. - **Smart Parameter Types = Inferred** uses `int` for `plural`, `IEnumerable` for `list`, otherwise `object`. - **Smart Parameter Types = Mapping** uses the types you set in the entry's [Smart Parameter Types metadata](#parameter-types) and infers the rest like `Inferred`. -- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change. +- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change. So does every other setting that changes the generated code, unless **Silently On Settings Change** is on. - Placeholder differences between locales are reported as warnings. Enable **Fail CI On Smart String Mismatch** to make `CheckBatch` fail on them. - **MethodsAndRefs** additionally emits `Ref.Greeting(...)` returning a `LocalizedString` whose arguments and local variables are set. @@ -271,6 +271,8 @@ With **Smart Parameter Types = Mapping**, you choose parameter types per entry. 3. Click **Add All Parameters** to add a row for every variable the entry uses in any locale, pre-filled with the inferred type, then change the types you care about. **Add Parameter** adds a single variable. 4. Each row's name is a dropdown of the entry's variables, labelled with their formatters and locales (`count (plural; en, ru)`). A warning icon marks a row that generation would warn about; hover it for the reason. +Metadata edits regenerate when you save the table (**File > Save Project** or Ctrl+S), not on every click. Turn on **On Metadata Edit** to regenerate after each edit instead. + Rows you delete simply fall back to the inferred type. Outside the Table Editor, names can be typed by hand: the variable name as written in the string (`count`, or `0` for `{0}`). ```csharp @@ -377,6 +379,8 @@ Open **Project Settings > Localization Codegen**, or **Window > Localization Cod | String Tables | on | Generate classes for string table collections. Disabling deletes the matching files on the next run. | | Asset Tables | on | Generate classes for asset table collections. Disabling deletes the matching files on the next run. | | Regenerate On Changes | on | Debounced automatic regeneration after table edits and external (VCS) changes. | +| Silently On Settings Change | off | Regenerate without asking when a setting that changes the generated code is edited. Off asks first. Needs **Regenerate On Changes**. | +| On Metadata Edit | off | Regenerate after every edit of the Smart Parameter Types metadata. Off regenerates when the table is saved. Needs **Regenerate On Changes**. | | Generate Reference Members | off | Emit the nested [`Ref` class](#reference-members). | | XML Documentation | off | Add XML docs with the default locale text and smart string parameters. | | Smart Strings | off (upgraded) / `Methods` (new) | `Off`, `Methods` or `MethodsAndRefs`. | diff --git a/Unity-Package/Assets/root/CHANGELOG.md b/Unity-Package/Assets/root/CHANGELOG.md index 9b26b28..1e5dc21 100644 --- a/Unity-Package/Assets/root/CHANGELOG.md +++ b/Unity-Package/Assets/root/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [1.3.3] - 2026-10-28 + +### Added +- **Silently On Settings Change**: regenerate without asking when a setting that changes the generated code is + edited. Off by default. +- **On Metadata Edit**: regenerate on every edit of the **Smart Parameter Types** metadata. Off by default. + +### Changed +- Editing **Smart Parameter Types** metadata no longer regenerates on every click; the code regenerates when the + table is saved. +- Every setting that changes the generated code (namespace, output folder, table kinds, members, naming, `.asmdef`) + now asks whether to regenerate, like **Smart Strings** and **Smart Parameter Types** already did. +- **Key Separators** applies when you press Enter or leave the field, so typing asks to regenerate once. + ## [1.3.2] - 2026-10-28 ### Added diff --git a/Unity-Package/Assets/root/Editor/CodegenSettings.cs b/Unity-Package/Assets/root/Editor/CodegenSettings.cs index 3432bd0..b66c99a 100644 --- a/Unity-Package/Assets/root/Editor/CodegenSettings.cs +++ b/Unity-Package/Assets/root/Editor/CodegenSettings.cs @@ -43,6 +43,10 @@ public sealed class CodegenSettings : ScriptableSingleton // Options introduced in 1.3.1. Off by default, so no migration is needed. [SerializeField] private bool generateLoadTable; + // Options introduced in 1.3.3. Off by default, so no migration is needed. + [SerializeField] private bool regenerateSilently; + [SerializeField] private bool regenerateOnMetadataEdit; + public bool SetupCompleted { get => setupCompleted; set => setupCompleted = value; } public string OutputFolder { get => outputFolder; set => outputFolder = value; } public string Namespace { get => generatedNamespace; set => generatedNamespace = value; } @@ -62,6 +66,8 @@ public sealed class CodegenSettings : ScriptableSingleton public bool FailOnSmartStringMismatch { get => failOnSmartStringMismatch; set => failOnSmartStringMismatch = value; } public bool GenerateUniTask { get => generateUniTask; set => generateUniTask = value; } public bool GenerateLoadTable { get => generateLoadTable; set => generateLoadTable = value; } + public bool RegenerateSilently { get => regenerateSilently; set => regenerateSilently = value; } + public bool RegenerateOnMetadataEdit { get => regenerateOnMetadataEdit; set => regenerateOnMetadataEdit = value; } public SmartStringMode SmartStrings { diff --git a/Unity-Package/Assets/root/Editor/SettingsGui.cs b/Unity-Package/Assets/root/Editor/SettingsGui.cs index 3cb6760..25d03d3 100644 --- a/Unity-Package/Assets/root/Editor/SettingsGui.cs +++ b/Unity-Package/Assets/root/Editor/SettingsGui.cs @@ -32,6 +32,11 @@ internal static class Content "Generate classes for asset table collections. Disabling this deletes the matching generated files on the next run."); public static readonly GUIContent AutoRegenerate = new GUIContent("Regenerate On Changes", "Automatically regenerate when table collections or entries change."); + public static readonly GUIContent RegenerateSilently = new GUIContent("Silently On Settings Change", + "Regenerate without asking when a setting that changes the generated code is edited. " + + "Off asks first."); + public static readonly GUIContent RegenerateOnMetadataEdit = new GUIContent("On Metadata Edit", + "Regenerate on every edit of the Smart Parameter Types metadata. Off regenerates when the table is saved."); public static readonly GUIContent SmartStrings = new GUIContent("Smart Strings", "Generate methods with parameters for smart string entries. Off keeps the 1.0 behaviour."); @@ -89,6 +94,7 @@ public static bool Draw() var oldSmartStrings = s.SmartStrings; var oldSmartParamTypes = s.SmartParamTypes; + var oldOutput = OutputSettingsKey(s); var oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = LabelWidth; EditorGUI.BeginChangeCheck(); @@ -108,8 +114,8 @@ public static bool Draw() var smartChanged = s.SmartStrings != oldSmartStrings || s.SmartParamTypes != oldSmartParamTypes; // The setup wizard generates when it finishes, so it is not asked about. - if (smartChanged && s.SetupCompleted) - PromptRegenerate(); + if (OutputSettingsKey(s) != oldOutput && s.SetupCompleted) + OnOutputSettingsChanged(s, smartChanged); else CodegenHooks.MarkDirtyExternal(); @@ -120,29 +126,54 @@ public static bool Draw() return changed; } + /// Every setting that changes the generated code. Settings outside it never ask to regenerate. + static string OutputSettingsKey(CodegenSettings s) + { + return string.Join("|", new[] + { + s.Namespace, s.OutputFolder, s.GenerateStringTables.ToString(), s.GenerateAssetTables.ToString(), + s.SmartStrings.ToString(), s.SmartParamTypes.ToString(), s.GenerateReferences.ToString(), + s.GenerateLoadTable.ToString(), s.GenerateUniTask.ToString(), s.GenerateXmlDocs.ToString(), + s.Naming.ToString(), s.KeySeparators, s.GenerateAsmdef.ToString() + }); + } + + /// + /// Regenerates after a setting that changes the generated code, asking first unless + /// is on. Without automatic regeneration only changes to the + /// method signatures ask, as nothing else would regenerate either. + /// + static void OnOutputSettingsChanged(CodegenSettings s, bool signaturesChanged) + { + if (s.AutoRegenerate && s.RegenerateSilently) + CodegenHooks.MarkDirtyExternal(); + else if (s.AutoRegenerate || signaturesChanged) + PromptRegenerate(signaturesChanged); + } + static bool s_RegeneratePromptPending; + static bool s_RegeneratePromptSignatures; /// - /// Asks whether to regenerate after the smart string settings change, since they change method signatures. - /// The dialog opens after the current GUI pass, and only once for several changes in a row. + /// Asks whether to regenerate after the settings change. The dialog opens after the current GUI pass, and only + /// once for several changes in a row. /// - static void PromptRegenerate() + static void PromptRegenerate(bool signaturesChanged) { + s_RegeneratePromptSignatures |= signaturesChanged; if (s_RegeneratePromptPending) return; s_RegeneratePromptPending = true; EditorApplication.delayCall += () => { + var message = s_RegeneratePromptSignatures + ? "The smart string settings changed the generated method signatures. Regenerate the code now?" + : "The settings changed the generated code. Regenerate the code now?"; s_RegeneratePromptPending = false; - if (EditorUtility.DisplayDialog( - "Localization Codegen", - "The smart string settings changed the generated method signatures. Regenerate the code now?", - "Regenerate", - "Later")) - { + s_RegeneratePromptSignatures = false; + if (EditorUtility.DisplayDialog("Localization Codegen", message, "Regenerate", "Later")) CodeGenerator.Run(new GenerateOptions { IsAutomatic = false, PromptOnMassDeletion = true }); - } }; } @@ -328,7 +359,8 @@ static void ApplyOwnerChoice(CodegenSettings s, OwningAssembly owner, bool addRe { s.GenerateAsmdef = true; s.SaveSettings(); - CodegenHooks.MarkDirtyExternal(); + if (s.SetupCompleted) + OnOutputSettingsChanged(s, signaturesChanged: false); } s_OwnerCacheKey = null; @@ -339,6 +371,13 @@ static void DrawTables(CodegenSettings s) s.GenerateStringTables = EditorGUILayout.Toggle(Content.StringTables, s.GenerateStringTables); s.GenerateAssetTables = EditorGUILayout.Toggle(Content.AssetTables, s.GenerateAssetTables); s.AutoRegenerate = EditorGUILayout.Toggle(Content.AutoRegenerate, s.AutoRegenerate); + using (new EditorGUI.DisabledScope(!s.AutoRegenerate)) + using (new EditorGUI.IndentLevelScope()) + { + s.RegenerateSilently = EditorGUILayout.Toggle(Content.RegenerateSilently, s.RegenerateSilently); + s.RegenerateOnMetadataEdit = + EditorGUILayout.Toggle(Content.RegenerateOnMetadataEdit, s.RegenerateOnMetadataEdit); + } if (!s.GenerateStringTables && !s.GenerateAssetTables) EditorGUILayout.HelpBox("Both table kinds are off, so nothing will be generated.", MessageType.Warning); @@ -373,7 +412,8 @@ static void DrawMembers(CodegenSettings s) static void DrawNaming(CodegenSettings s) { s.Naming = (NamingConvention)EditorGUILayout.EnumPopup(Content.Naming, s.Naming); - s.KeySeparators = EditorGUILayout.TextField(Content.KeySeparators, s.KeySeparators); + // Delayed, so typing several characters asks to regenerate once. + s.KeySeparators = EditorGUILayout.DelayedTextField(Content.KeySeparators, s.KeySeparators); } static void DrawAdvanced(CodegenSettings s) @@ -414,8 +454,11 @@ static void PickOutputFolder(CodegenSettings s) if (s.OutputFolder != previous) { s.SaveSettings(); - CodegenHooks.MarkDirtyExternal(); OnOutputFolderChanged(); + if (s.SetupCompleted) + OnOutputSettingsChanged(s, signaturesChanged: false); + else + CodegenHooks.MarkDirtyExternal(); } GUI.FocusControl(null); diff --git a/Unity-Package/Assets/root/Editor/SmartParameterTypesDrawer.cs b/Unity-Package/Assets/root/Editor/SmartParameterTypesDrawer.cs index ccb5120..ba4edd0 100644 --- a/Unity-Package/Assets/root/Editor/SmartParameterTypesDrawer.cs +++ b/Unity-Package/Assets/root/Editor/SmartParameterTypesDrawer.cs @@ -9,6 +9,8 @@ namespace Severnbli.LocalizationCodegen.Editor /// /// Editor for : picks names from the variables the entry uses in any locale, /// adds every variable at once, and shows the warnings generation would report. + /// Edits regenerate only with ; otherwise the asset + /// postprocessor does once the table is saved. /// [CustomPropertyDrawer(typeof(SmartParameterTypes))] sealed class SmartParameterTypesDrawer : PropertyDrawer @@ -115,7 +117,7 @@ static void DrawBody(Rect rect, SerializedProperty property, SerializedProperty if (remove >= 0) { parameters.DeleteArrayElementAtIndex(remove); - CodegenHooks.MarkDirtyExternal(); + OnEdited(); } } @@ -195,7 +197,7 @@ static bool DrawRow( if (EditorGUI.EndChangeCheck()) { nameProperty.stringValue = typed; - CodegenHooks.MarkDirtyExternal(); + OnEdited(); } } else @@ -210,7 +212,7 @@ static bool DrawRow( EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(typeRect, typeProperty, GUIContent.none); if (EditorGUI.EndChangeCheck()) - CodegenHooks.MarkDirtyExternal(); + OnEdited(); var normalized = SmartParameterMapping.NormalizeName(name); var duplicate = normalized.Length > 0 && !seen.Add(normalized); @@ -294,7 +296,13 @@ static void Modify(Target target, Action change) change(parameters); serializedObject.ApplyModifiedProperties(); - CodegenHooks.MarkDirtyExternal(); + OnEdited(); + } + + static void OnEdited() + { + if (CodegenSettings.instance.RegenerateOnMetadataEdit) + CodegenHooks.MarkDirtyExternal(); } } } diff --git a/Unity-Package/Assets/root/README.md b/Unity-Package/Assets/root/README.md index 619151d..3b397db 100644 --- a/Unity-Package/Assets/root/README.md +++ b/Unity-Package/Assets/root/README.md @@ -255,7 +255,7 @@ public static string Greeting(object arg0, int count) - Variables provided by a **Global Variables Group** are not parameters; Unity resolves them. - **Smart Parameter Types = Inferred** uses `int` for `plural`, `IEnumerable` for `list`, otherwise `object`. - **Smart Parameter Types = Mapping** uses the types you set in the entry's [Smart Parameter Types metadata](#parameter-types) and infers the rest like `Inferred`. -- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change. +- Changing **Smart Strings** or **Smart Parameter Types** asks whether to regenerate, since method signatures change. So does every other setting that changes the generated code, unless **Silently On Settings Change** is on. - Placeholder differences between locales are reported as warnings. Enable **Fail CI On Smart String Mismatch** to make `CheckBatch` fail on them. - **MethodsAndRefs** additionally emits `Ref.Greeting(...)` returning a `LocalizedString` whose arguments and local variables are set. @@ -271,6 +271,8 @@ With **Smart Parameter Types = Mapping**, you choose parameter types per entry. 3. Click **Add All Parameters** to add a row for every variable the entry uses in any locale, pre-filled with the inferred type, then change the types you care about. **Add Parameter** adds a single variable. 4. Each row's name is a dropdown of the entry's variables, labelled with their formatters and locales (`count (plural; en, ru)`). A warning icon marks a row that generation would warn about; hover it for the reason. +Metadata edits regenerate when you save the table (**File > Save Project** or Ctrl+S), not on every click. Turn on **On Metadata Edit** to regenerate after each edit instead. + Rows you delete simply fall back to the inferred type. Outside the Table Editor, names can be typed by hand: the variable name as written in the string (`count`, or `0` for `{0}`). ```csharp @@ -377,6 +379,8 @@ Open **Project Settings > Localization Codegen**, or **Window > Localization Cod | String Tables | on | Generate classes for string table collections. Disabling deletes the matching files on the next run. | | Asset Tables | on | Generate classes for asset table collections. Disabling deletes the matching files on the next run. | | Regenerate On Changes | on | Debounced automatic regeneration after table edits and external (VCS) changes. | +| Silently On Settings Change | off | Regenerate without asking when a setting that changes the generated code is edited. Off asks first. Needs **Regenerate On Changes**. | +| On Metadata Edit | off | Regenerate after every edit of the Smart Parameter Types metadata. Off regenerates when the table is saved. Needs **Regenerate On Changes**. | | Generate Reference Members | off | Emit the nested [`Ref` class](#reference-members). | | XML Documentation | off | Add XML docs with the default locale text and smart string parameters. | | Smart Strings | off (upgraded) / `Methods` (new) | `Off`, `Methods` or `MethodsAndRefs`. | From a01ae323d0705c9192b0f36424bc89f567896bf8 Mon Sep 17 00:00:00 2001 From: Usevalad Buben Date: Wed, 28 Oct 2026 11:49:19 +0300 Subject: [PATCH 2/2] Bump version to 1.3.3 Co-Authored-By: Claude Opus 5.5 --- .../Assets/Editor/Localization Codegen Installer/Installer.cs | 2 +- README.md | 2 +- Unity-Package/Assets/root/README.md | 2 +- Unity-Package/Assets/root/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Installer/Assets/Editor/Localization Codegen Installer/Installer.cs b/Installer/Assets/Editor/Localization Codegen Installer/Installer.cs index 1044794..34ef095 100644 --- a/Installer/Assets/Editor/Localization Codegen Installer/Installer.cs +++ b/Installer/Assets/Editor/Localization Codegen Installer/Installer.cs @@ -16,7 +16,7 @@ namespace Severnbli.LocalizationCodegen.Installer public static partial class Installer { public const string PackageId = "com.severnbli.localization-codegen"; - public const string Version = "1.3.2"; + public const string Version = "1.3.3"; static Installer() { diff --git a/README.md b/README.md index 3b397db..e965c77 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Add the scoped registry and the dependency to `Packages/manifest.json`: } ], "dependencies": { - "com.severnbli.localization-codegen": "1.3.2" + "com.severnbli.localization-codegen": "1.3.3" } } ``` diff --git a/Unity-Package/Assets/root/README.md b/Unity-Package/Assets/root/README.md index 3b397db..e965c77 100644 --- a/Unity-Package/Assets/root/README.md +++ b/Unity-Package/Assets/root/README.md @@ -134,7 +134,7 @@ Add the scoped registry and the dependency to `Packages/manifest.json`: } ], "dependencies": { - "com.severnbli.localization-codegen": "1.3.2" + "com.severnbli.localization-codegen": "1.3.3" } } ``` diff --git a/Unity-Package/Assets/root/package.json b/Unity-Package/Assets/root/package.json index 39dede0..0443c68 100644 --- a/Unity-Package/Assets/root/package.json +++ b/Unity-Package/Assets/root/package.json @@ -10,7 +10,7 @@ "Generation", "Code Generation" ], - "version": "1.3.2", + "version": "1.3.3", "unity": "2021.3", "description": "C# classes and properties generator from Unity Localization tables", "documentationUrl": "https://github.com/Severnbli/localization-codegen/blob/main/README.md",