Communitygithub.com

unity-technologies/localization

Unity Localization のセットアップと設定を行います。ロケール、String/Asset テーブル、CJK フォント対応、Addressables ワークフローを含みます。プロジェクトに言語を追加したい場合、UI テキストを翻訳したい場合、アジア言語(CJK)を TMP フォントでサポートしたい場合、または i18n、l10n、多言語対応、ゲームの多言語サポートについて言及された場合に使用します。

localization とは?

このスキルは、Unity プロジェクトで Localization パッケージを使用した多言語対応を包括的にセットアップおよび設定するためのガイドです。主な機能として、ロケールの追加・管理、String テーブルと Asset テーブルを使用したテキストやアセットの翻訳、Addressables との統合、そしてアジア言語(CJK)向けのフォントスワッピングを Asset テーブル経由で行う方法を提供します。 このスキルは、Claude Code、Coder、または同様の AI エージェントで使用することを想定しており、Unity エディターのスクリプト API(`AssetDatabase`、`LocalizationEditorSettings` など)を活用して、プロジェクトの設定ファイルやテーブルを直接操作します。パッケージのインストール確認から、ロケール設定、テーブルの編集、UI 要素へのローカライズイベントのバインド、そしてレイアウトの更新まで、実践的な手順を提供します。 特に重要な点として、パッケージの内部 API を使用せず、公開された `LocalizeStringEvent` のような安定した API を使用すること、ロケールの切り替えは `LocalizationSettings.SelectedLocale` のみを介して行うこと、そして Asset テーブルによる CJK フォントスワッピングが TMP のフォールバックフォントよりも信頼性が高いことなどが強調されています。これにより、開発者や AI エージェントは、壊れやすくデバッグが難しいアプローチを避け、堅牢なローカリゼーションシステムを構築できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/unity-technologies/skills/tree/main/skills/localization

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

このガイドでは、Unity Localization のセットアップと設定について説明します。ロケール、String および Asset テーブル、Addressables 統合、Asset テーブルを使用した CJK フォントサポートが含まれます。

0. パッケージインストール確認

他の作業を行う前に、Localization パッケージがインストールされていることを確認してください。このスキルの多くの API は、パッケージが存在しない場合、黙って失敗したり、混乱を招くエラーをスローしたりします。

  1. パッケージマネージャーに問い合わせるのではなく、プロジェクトを読み取って確認します。 Packages/packages-lock.json 内の com.unity.localization を探してください。このファイルには、Unity が実際に解決した内容が記録されており、プレーンな JSON であるため、エディターや非同期呼び出しを必要とせずに読み取ることができます。(Packages/manifest.json は 要求された 内容のみを記録するため、ロックファイルを確認してください。)
  2. 欠落している場合にインストール: UnityEditor.PackageManager.Client.Add("com.unity.localization")。
  3. 適切に待機します。 Client.Add と Client.List は 非同期 です。返されるリクエストは、呼び出しが戻った時点でも InProgress 状態であるため、同じステートメントで結果を読み取っても意味がありません。IsCompleted でビジーウェイトしないでください。実行中のメインスレッドをブロックします。代わりに、インストールを実行したら一度戻り、後の呼び出しで packages-lock.json をポーリングして ID が表示されるまで待ちます。インストールによってドメインリロードもトリガーされるため、最初の数回のポーリングは失敗することが予想されます。新規インストールは通常、数秒で解決します。
  4. タイプが実際にロードされていることを確認 してから使用します。ロックファイルはアセンブリの準備ができる前に書き込まれる可能性があるためです:
    var t = System.Type.GetType(
        "UnityEngine.Localization.Settings.LocalizationSettings, Unity.Localization");
    return t != null ? "ready" : "not loaded yet";
    
    ready が返されるまで先に進まないでください。

1. Localization Settings と Locales

LocalizationEditorSettings.ActiveLocalizationSettings が null の場合、それを見つけるか作成する必要があります:

  1. 検索: AssetDatabase.FindAssets("t:LocalizationSettings", new[] { "Assets" }) を使用します。見つかった場合は、最初のものをロードし、LocalizationEditorSettings.ActiveLocalizationSettings に割り当てます。
    • 常に検索フォルダを指定してください。 スコープ指定なしの FindAssets は読み取り専用パッケージを含むプロジェクト全体を検索するため、パッケージからアセットを返し、編集できないものをプロジェクトが指すことになる可能性があります。これは、このスキル内のすべての FindAssets 呼び出しに適用されます。
  2. 作成: 見つからない場合は、新しいインスタンスを作成し、Assets/Localization/LocalizationSettings.asset に保存します。ScriptableObject.CreateInstance<LocalizationSettings>() の後に AssetDatabase.CreateAsset() を使用します。
  3. アクティブ化: LocalizationEditorSettings.ActiveLocalizationSettings = settings を設定します。
  4. ロケール: ロケール(en、fr、de など)が存在することを確認します。存在しない場合は作成し、LocalizationEditorSettings.AddLocale(locale) を使用して設定に追加します。

2. Localization テーブルの変更

String または Asset テーブルへのプログラムによる変更は、エディターに通知する必要があります。 プロジェクトに既存のものがない限り、必要なアセットテーブルを常に作成してください。

安全なデータ投入パターン

データセットからテーブルにデータを投入する場合、Locale.Identifier.Code で明示的に一致させてください。GetLocales() の順序は入力データ配列と一致することが保証されていません。一致すると仮定すると、デバッグが非常に困難なサイレントなデータ不一致が発生します。 Asset テーブル の場合、アセットの GUID を使用します:table.GetEntry(sharedId) ?? table.AddEntry(sharedId, guid);。

リフレッシュと通知

変更(キーの追加、値の更新)後は、エディターに内部状態をリフレッシュするよう通知します。これをスキップすると、エディターは次の再インポートまで古いデータを表示し続けます。

  1. 変更された各 Table に対して EditorUtility.SetDirty(collection)、EditorUtility.SetDirty(collection.SharedData) を呼び出します。
  2. Unity 6+ の通知: LocalizationEditorSettings.EditorEvents.RaiseCollectionModified(sender, collection);
  3. 最後に必ず AssetDatabase.SaveAssets() を呼び出します。

3. UI ローカリゼーションとレイアウト

名前空間と競合

  • 名前は常に完全修飾してください: UnityEngine.UI.Image、UnityEngine.UI.VerticalLayoutGroup、UnityEngine.UI.ScrollRect、UnityEngine.UI.Mask、UnityEngine.UI.CanvasScaler、UnityEngine.UI.GraphicRaycaster、UnityEngine.UI.ContentSizeFitter、UnityEngine.UI.LayoutRebuilder などを使用します。
  • UnityEngine.UI は名前空間であると同時にクラスコンテナでもあるため、非修飾名は CS0118(名前空間が型として使用されている)を生成します。完全修飾によりこれを完全に回避できます。
  • シングルインスタンス: 常に GameObject.Find("YourCanvasName") をチェックし、新しいものを作成する前に古いものを破棄してください。
  • ロケール切り替え:パッケージを使用し、プレビューとランタイムを分離してください。 これらは 2 つの異なるメカニズムであり、それらを混同することが、ロケール切り替えが手作業で実装されがちな理由です。
    • オーサリング中にロケールをプレビューするには、Localization Scene Controls ウィンドウ(Window > Asset Management > Localization Scene Controls)を使用します。これはエディター専用です。ランタイム機能ではないため、ゲーム自体に言語設定が必要な場合の解決策にはなりません。
    • ランタイムにロケールを切り替えるには、LocalizationSettings.SelectedLocale を割り当てます。これがサポートされているエントリポイントであり、LocalizeStringEvent を通じてバインドされたすべてのものがこれから更新されます。
    • ゲームが開始するロケールを固定するには、Localization Settings アセットでスタートアップロケールセレクターを設定します。SpecificLocaleSelector は選択したロケールを強制するものです。デフォルトのチェーンはシステム言語を取得します。
    • ロケールの状態を手動で管理しないでください。 実際のゲーム内言語メニューは問題なく、むしろ推奨されます。ただし、それは SelectedLocale を設定し、パッケージに変更を伝播させる限りにおいてです。禁止されているのは、独自の「現在の言語」変数を追跡し、自ら文字列を入れ替えたり、パッケージを回避したりするデバッグドロップダウンやメニューです。プロジェクト内の他の何もそれを追跡しなくなります。

ローカライズされた文字列イベント(堅牢なバインディング)

  • コンポーネントタイプを確認: ターゲットが TextMeshPro か、従来の UnityEngine.UI.Text かを特定します。

  • 正しくバインド: パブリックな UnityEngine.Localization.Components.LocalizeStringEvent コンポーネントを追加し、自分で配線します。StringReference をテーブルエントリに設定し、OnUpdateString リスナーを追加して、値をテキストコンポーネント(TextMeshPro の場合は TMP_Text.text、従来の Text の場合は UnityEngine.UI.Text.text)に割り当てます。

    UnityEditor.Localization.Plugins.TMPro.LocalizeComponent_TMPro やその UGUI 版にリフレクトしないでください。これらは internal(Localization 1.5.12 で確認)であるため、それらにアクセスするにはアクセス制御を回避し、Unity が安定性を保証しない API に到達することになります。これはパッケージリリースごとに変更または削除される可能性があります。LocalizeStringEvent はパブリックであり、配線を明示的にして同じ仕事をします。

  • レイアウト再構築: ローカライズされたテキストを設定したり、リストを設定した後は、UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(parentTransform) を呼び出して、ディメンションが更新されるようにします。

4. アジア言語フォントサポート(CJK)

CJK ロケールには TMP フォールバックフォントを避けてください。代わりに、各ロケールに固有の Asset テーブルフォントスワッピング を使用してください。フォールバックは信頼性が低く、グリフが欠落している場合のデバッグが困難です。

前提条件:TMP Essential Resources をインポートしておく必要があります

TMP API に触れる前にこれを確認してください。 これまでにインポートされたことのないプロジェクトでは、TMP_Settings.instance は null であり、TMP 呼び出しは役に立たない NullReferenceException で失敗します。TMP_FontAsset.CreateFontAsset はその一つであり、フォント作成は最初の行でエラーにより停止します。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

unity-technologies/2d-pixel-perfect

Sets up, diagnoses, and fixes pixel perfect 2D rendering in Unity projects. Use when working on any retro-style or pixel art 2D game.

unity-technologies/audio-setup-mixers

Scans the scene and audio assets to appropriately route Audio Sources into existing Audio Mixer Groups, classifying each source by what it plays. Use when the user asks about cleaning up mixer assignments, routing audio through a mixer, or which group a sound belongs in. Creating mixers and groups, and setting volumes, are not automated — the skill inventories what exists and asks the user to add anything missing.

unity-technologies/build-live-game

Build and operate a live game using Unity Services. Use when the user needs to implement, connect, or debug backend-driven features — battle passes, achievements, player progression, cloud saves, leaderboards, matchmaking, virtual economies, server-authoritative logic, anti-cheat, player accounts and authentication, remote configuration, feature flags, A/B testing, analytics, or cloud resource deployment. Triggers on live-ops, live service, backend, server authority, cloud code, cloud save, remote config, player data, retention, monetization loop, season pass, ranking, multiplayer sessions, lobbies, or any Unity Services integration.

unity-technologies/generate-editor-search-query

Generates Unity Search / Quick Search queries and opens the Unity Search window for read-only Unity Editor asset or scene-object lookup requests. Always use when the user asks to find, search, show, locate, filter, look up, query, or list concrete assets or scene objects in the current project or scene, even if Unity Search is not named. Covers materials, textures, prefabs, scenes, scripts, shaders, GameObjects, components, Lights, Cameras, UI objects, labels, paths, references, selected or named assets, and asset types. Also use when the user explicitly mentions Unity Search, Quick Search, Search window, open Search, or asks what Unity Search query to use. Do not use for general project overview, project structure, folder-purpose summaries, gameplay/system explanations, how-to programming questions, web search, repository text search, build logs, package installation, menu or settings search, modifying results, or non-Unity filesystem search unless the user explicitly asks to use Unity Search.

unity-technologies/implement-in-app-purchases

Implement, configure, and debug Unity In-App Purchases (IAP) — store connection, product catalog, consumable/non-consumable/subscription purchases, two-step pending-confirm flow, receipt validation, entitlement checking, restore transactions, Apple extensions (promotional purchases, Ask-to-Buy, code redemption), and Google Play extensions (subscription upgrade/downgrade), D2C Capabilities(direct to customer), 3rd party payment provider (Stripe/Coda) via Unity IAP/Unity Cloud. Use when the user needs to add, modify, debug, or migrate from native Android/iOS billing, 3rd party packages(RevenueCat/Adapty/Essential Kit/Unipay supported) to IAP. Triggers on microtransactions (MTX), monetization, real-money purchases, store purchases, buying items, support D2C, purchase via Stripe/Coda, migrate from native billing(Google's BillingClient or Apple's StoreKit/SKPaymentQueue/SKProduct)/RevenueCat/Adapty/EssentialKit/Unipay.

unity-technologies/initialize-ai-navigation

Sets up and configures the Unity AI Navigation system — NavMesh surfaces, NavMesh agents, obstacles, links, modifiers, areas and costs. Use when creating walkable navigation meshes, adding pathfinding agents, setting up patrol routes, configuring obstacle avoidance and carving, connecting separate NavMeshes with links, coupling navigation with animation, or troubleshooting navigation issues.

unity-technologies/levelplay-unity-integration

Integrates the LevelPlay Mediation SDK via the Ads Mediation UPM package. Use when a developer asks about adding ads to a Unity game, implementing rewarded, interstitial, or banner ads, setting up ad mediation, configuring ad networks, installing or updating the Ads Mediation package, troubleshooting LevelPlay namespace errors, resolving Android gradle or iOS CocoaPods dependency issues for ads, configuring ATT or privacy settings for ad compliance, tracking impression-level revenue (ILRD), initializing the LevelPlay SDK, or setting up ad unit IDs. Also use when a developer wants to monetize their Unity game with ads, asks how to get started with LevelPlay, ads, or mediation, or needs help with any part of the LevelPlay integration workflow including platform-specific setup for iOS or Android. Also use when upgrading the LevelPlay or IronSource SDK version, migrating from deprecated IronSource.Agent APIs, or migrating a game from Unity Ads to LevelPlay.

unity-technologies/manage-sprite-atlas

Manage SpriteAtlas using prebuild pipeline with IPreprocessBuildWithReport (DEFAULT approach). Use it to configure master atlases, variant atlases, texture settings, packing settings, and platform-specific configurations. Use when the user asks about creating sprite atlases, optimizing sprites, configuring atlas settings, adding sprites to atlases, creating variant atlases, implementing automated atlas generation, or runtime sprite atlas access. Always use prebuild approach unless user explicitly requests manual authoring.

unity-technologies/migrate-birp-to-urp

Plans, executes, and troubleshoots Unity projects moving from the Built-in Render Pipeline (BiRP/BIRP/Built-in RP) to the Universal Render Pipeline (URP). Use when the user asks to upgrade, convert, switch, or migrate a project, scene, material, or shader to URP/Universal Render Pipeline; fix pink or magenta materials after URP; convert Built-in materials/shaders; move a 2D project to URP 2D; review lighting, quality, post-processing, baked lightmaps, or reflection probes after URP; or diagnose visual problems after a render-pipeline migration.

関連スキル