Skip to content

Add optional UniTask support (1.2.0) - #12

Merged
Severnbli merged 5 commits into
mainfrom
feature/unitask-extension
Oct 24, 2026
Merged

Severnbli merged 5 commits into
mainfrom
feature/unitask-extension

Conversation

@Severnbli

Copy link
Copy Markdown
Owner

Summary

This adds optional UniTask support and bumps the version to 1.2.0. Turn on UniTask Members and each generated member gets an awaitable …Async variant next to it:

label.text = await Ui.HelloWorldAsync(this.GetCancellationTokenOnDestroy());
var greeting = await Ui.GreetingAsync(player, count);   // smart string parameters are kept
Sprite icon  = await Icons.SwordAsync();                // asset entries return UniTask<T>

Projects without UniTask aren't affected at all. The new assembly compiles only when UniTask is installed.

Commits

Commit What
fc504bf Add optional UniTask runtime assembly New com.severnbli.localization-codegen.UniTask assembly, gated by an asmdef version define on com.cysharp.unitask (or the LOCALIZATION_CODEGEN_UNITASK define when UniTask lives under Assets/). It adds LocalizedTablesUniTask.GetStringAsync / GetAssetAsync with cancellation, plus a LocalizedString.GetLocalizedStringUniTask() extension. The result is read inside the completion callback because Localization releases its operations automatically. Comes with 10 runtime tests.
e27f077 Fix Ref members of asset tables not compiling Pre-existing bug. Ref emitted new LocalizedSprite(TableName, "Key"), but LocalizedAsset<T> and its subclasses only have a parameterless constructor. Any project with Generate Reference Members and an asset table got CS1729 errors. The emitter now uses an object initializer.
ab4ac0f Generate UniTask members and compile generated code in tests The UniTask Members setting. Async names are claimed after every key's own name, so turning the option on never renames an existing member. The token parameter avoids clashing with smart-string parameter names. If the add-on isn't compiled, generation skips the option with a warning. The generated .asmdef references UniTask. New GeneratedCodeCompilationTests compiles the emitted code with Unity's AssemblyBuilder, with warnings as errors and XML docs on, across 3 option sets, with and without UniTask. This test found the Ref bug above.
b1c4ac9 Sync the READMEs, document UniTask and explain Ref members The root README was an older copy of the package README. Both are now identical, and check-package.sh fails if the README or CHANGELOG copies drift apart. Adds a quick start, a nav bar, an updated feature table, the UniTask docs, and an explanation of what Ref is for.
c75f7ec Bump version to 1.2.0 package.json, Installer.Version, the README install snippet, both changelogs.

CI coverage

  • The 2022.3 test project now installs UniTask from OpenUPM. There the add-on compiles, its runtime tests run, and the UniTask compile test runs.
  • The 6000.3.1f1 project stays without UniTask. That checks the add-on compiles out cleanly; the UniTask compile test is skipped there by design.

Test plan

  • Unity 2022.3.62f3 with UniTask: EditMode 106/106, PlayMode 14/14 (including the 10 UniTask runtime tests), Installer 13/13
  • Unity 6000.5.9f1 without UniTask: EditMode 106 passed, 1 skipped (the UniTask compile variant, skipped by design)
  • commands/check-package.sh passes, and fails when a README copy drifts
  • Unity 6000.3.1f1: CI only (not installed locally)

🤖 Generated with Claude Code

Severnbli and others added 5 commits October 24, 2026 14:19
New com.severnbli.localization-codegen.UniTask assembly, compiled only
when UniTask (com.cysharp.unitask >= 2.0.0) is installed - via an asmdef
version define - or when LOCALIZATION_CODEGEN_UNITASK is defined for
projects that keep UniTask under Assets/.

- LocalizedTablesUniTask.GetStringAsync / GetAssetAsync return UniTask
  and take a CancellationToken. Positional and named smart string
  arguments follow the same rules as the synchronous LocalizedTables
  methods; missing LocalizationSettings return the key / null like the
  synchronous helpers.
- GetLocalizedStringUniTask() extension for LocalizedString (for Ref
  members and hand-written references).
- Results are read in the completion callback because Localization
  auto-releases its operations; cancelling only stops the wait.
- Runtime tests cover the no-settings fallbacks, pre-cancelled tokens,
  pending, cancelled, completed, failed and invalid operations.
- The 2022.3 test project installs UniTask from OpenUPM; the 6000.3.1f1
  project does not, so CI covers both the add-on and its absence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Ref class emitted `new LocalizedSprite(TableName, "Key")` for asset
table entries, but LocalizedAsset<T> and its subclasses (LocalizedSprite,
LocalizedObject, LocalizedMesh, LocalizedAudioClip, ...) only have a
parameterless constructor, so any project with "Generate Reference
Members" and an asset table got CS1729 errors in the generated code.
Use an object initializer that sets TableReference and
TableEntryReference instead. LocalizedString keeps its constructor.

Found by the new generated-code compilation test (next commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generator
- New "UniTask Members" setting (GenerateUniTask). When enabled, every
  string and asset member also gets a ...Async method returning UniTask
  that takes a CancellationToken; smart string methods keep their
  parameters and forward them to LocalizedTablesUniTask.
- Async names are claimed after every key's own name, so turning the
  option on never renames an existing member; a key that already ends in
  "Async" pushes the variant to a suffix. The token parameter avoids
  smart string parameter names.
- The option only takes effect when the UniTask add-on assembly is
  compiled; otherwise generation warns and skips it, since the code
  would not compile. The generated asmdef references UniTask when used.
- The option signature only changes when UniTask is enabled, so
  existing hashes and files stay valid after upgrading.

Tests
- GeneratedCodeCompilationTests compiles emitted code for three option
  sets (full features, PascalCase in the global namespace, 1.0 output)
  with Unity's AssemblyBuilder, -warnaserror and XML docs enabled, with
  and without UniTask. It found the Ref asset constructor bug fixed in
  the previous commit.
- Emitter tests for async members, argument forwarding, token and member
  name collisions, the option signature and the generated asmdef.
- Integration test for the option with and without the add-on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The repository README was an older, shorter copy of the package README
  (no smart strings, Ref, CI or most settings). Both are now the same
  file, and check-package.sh fails when the README or CHANGELOG copies
  drift apart again.
- Add a quick start, a navigation bar, a UniTask badge and an updated
  feature table.
- New UniTask section and settings row; UniTask in the requirements.
- Explain what Ref members are for (references that follow locale
  changes, e.g. LocalizeStringEvent.StringReference and StringChanged),
  not just how they look.
- Mention that CheckBatch catches hand-edited generated files and list
  the editor window buttons from the old root README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Severnbli
Severnbli merged commit 273881e into main Oct 24, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant