バージョン
menu

Wwise Unity Integration Documentation
DLCをパッケージングするための基本チュートリアル

This example demonstrates how to separate certain assets (such as new items or characters) into a DLC asset bundle that is packaged using Addressables.

Prerequisites

Before you proceed with this tutorial, do the following:

Addressablesのデモシーンをインストールする

An Addressables Demo Scene is available on GitHub.

To install the Addressables Demo Scene:

  1. In a browser, open https://github.com/audiokinetic/WwiseUnityAddressablesDemoScene.
  2. Clone the repository to your computer.
  3. In the Unity Editor, open the WwiseDemoScene.
  4. Select Window > Package Manager.
  5. Click + and select Add package from disk.
    警告: Do not select Add package from git URL. If you install the package that way, you cannot open the sample scenes.
  6. Open the package.json file in the WwiseUnityAddressablesDemoScene repository.

始めてみよう

このチュートリアル用に、Wwiseプロジェクトに2つのサウンドエフェクト、1つのイベント、そして1つのSoundBankを用意しました。

AkBankコンポーネントとAkEventコンポーネントのある、2つのGameObject prefabを作成しました: DlcAssetHighImpact、DlcAssetLowImpactです。 これらのprefabは、DLC SoundBankをロードして、インスタンス化されるとサウンドエフェクトを再生します。

また、AddressablesDemoScene、AddressablesSubSceneの2つのシーンを作成しました。 AddressablesDemoSceneはインタラクティブボタンがいくつかある簡単なUnityシーンで、Addressableアセットのロード・アンロードをテストするのに使います。 AddressablesSubSceneはDlcAssetLowImpact prefabだけが入ったシーンです。Addressablesで、Wwiseオブジェクトの入ったシーンをロードするのを、テストします。

注記: AddressablesDemoSceneには、ローカライズされたボイスを使い、Wwise Addressablesパッケージでランゲージを切り替える例も入っています。

これらのアセットや以下のセクションに記載のスクリプトはすべて WwiseUnityAddressablesDemoScene パッケージにあります。

以下の3つのアセットをAddressableで管理できるように、それぞれのInspectorでAddressableチェックボックスを有効にします。

  • AddressablesSubScene.unity
  • Prefabs/DlcAssetHighImpact.prefab
  • Prefabs/DlcAssetLowImpact.prefab
注意: あなたのプロジェクトでUnity Addressablesパッケージを削除すると、全アセットでこのAddressableフィールドが消え、このチェックボックスの状態は、パッケージを再インストールしても保存されていません。

これらのAddressableアセットは Addressables Groups ウィンドウを見ると、デフォルトでDefault Local Groupに入っています。

新しいグループを作成するためにはグループウィンドウを右クリックしてCreate New Groupを選択するか、メニューでNew > Packed Assetsを選択します。 DLCアセット用に、次の2つの新しいグループを作成します:

  • Prefabやサブシーン用に、DLC_Assets。
  • プラットフォーム専用のSoundbankアセット用に、DLC_WwiseData_Windows。
注記: 今回の例で追加で作成するのはWindowsプラットフォーム用のSoundBankグループを1つだけですが、一般的には、デプロイ予定の各プラットフォーム用に、それぞれ1つずつ、グループを作成してください。
  • DlcAssetHighImpact、DlcAssetLowImpact、AddressablesSubSceneを、Default Local GroupからDLC_Assetsグループに移します。
  • プラットフォーム専用のDLC SoundBankアセットを、WwiseData_WindowsからDLC_WwiseData_Windowsグループに移します。
注記:
  • プラットフォーム専用のグループ名にWwiseDataという文字列とプラットフォーム名のWindowsを必ず入れるように気を付けて、Addressablesをビルドする時にBuildWwiseDataスクリプトが正しく処理できるようにしています。
  • グループの変更を保存するには、 Use Sample Metadata Preserver 設定を有効にしてから Assets > Wwise > Addressables > Serialize addressable asset metadata アクションを実行してください。

Groupsウィンドウで、 Play Mode ScriptUse Existing Build に設定し、新しいAddressableパッケージをWwise Build Scriptでビルドします( Building the Project で説明したとおり)。

次にAddressablesDemoSceneを開きます。

Addressablesを使ってアセットをロードする

このシーンには、2つのボタンがあります

  • 左側のボタンで、Addressablesを使ってDlcAssetHighImpact Prefabをロードし、インスタンス化できます。
  • 右側のボタンで、AddressableSubSceneをロードし、インスタンス化できます。
  • このシーンには、DlcAssetLowImpactアセットが入っています。

Loading DLC Assets Demo GameObjectを見ると、AssetLoaderオブジェクトが作成されていて、そこにAddressablePrefabLoaderコンポーネントが入っているのが確認できます。

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class AddressablePrefabLoader : MonoBehaviour
{
public AssetReference reference;
public void Load()
{
Addressables.LoadAssetAsync<GameObject>(reference).Completed += asyncOp =>
{
if (asyncOp.Status == AsyncOperationStatus.Succeeded)
{
Instantiate(asyncOp.Result,this.transform);
}
};
}
}

このコンポーネントにはAssetReferenceが入っていて、ここではInspectorで、これをDlcAssetHighImpact Prefabに設定しました。

ゲームを実行して左ボタンを押すと、AddressablePrefabLoaderのLoadメソッドがコールされ、それがDLC_Assetsからロードされ、DlcAssetHighImpact Prefabがインスタンス化されます。 一旦インスタンス化されると、AkBankコンポーネントが、DLC_WwiseData_WindowsアセットパンドルからSoundBankをロードします。

Addressablesを使ってシーンをロードする

Loading DLC Scene Demo GameObjectを見ると、SceneLoaderオブジェクトが作成されていて、そこにAddressableSceneLoaderコンポーネントが入っているのが確認できます。

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
public class AddressableSceneLoader : MonoBehaviour
{
public AssetReference scene;
private AsyncOperationHandle<SceneInstance> sceneHandle;
public void Awake()
{
DontDestroyOnLoad(gameObject);
}
public void LoadScene()
{
if (!sceneHandle.IsValid() )
{
scene.LoadSceneAsync( LoadSceneMode.Additive).Completed += SceneLoadComplete;
}
else
{
UnloadScene();
}
}
public void UnloadScene()
{
Addressables.UnloadSceneAsync(sceneHandle).Completed += op =>
{
if (op.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log("Successfully unloaded scene");
}
};
}
private void SceneLoadComplete(AsyncOperationHandle<SceneInstance> obj)
{
sceneHandle = obj;
if (obj.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log(obj.Result.Scene.name + " successfully loaded");
}
}
}

このコンポーネントは、AssetReferenceを使って、私たちのAddressablesSubSceneへのレファレンスを保持しています。 このボタンを最初に押すとLoadSceneMethodがコールされ、シーンがLoadSceneAsyncメソッドを使ってロードされ、現在のシーンに追加されます。 もう一度このボタンを押すと、このシーンがアンロードされます。

AddressablesSubSceneにはDlcAssetLowImpact Prefabだけが入っていて、これをインスタンス化するとDLCサウンドバンクがロードされ、それに対応するイベントが再生されます。

ランゲージを変える

このシーンの3つ目のデモは、ランゲージを英語とフランス語で切り替えて、ローカライズされたボイスサンプルを再生するものです。 このデモにはAkWwiseSetLocalizationスクリプトが使われます。緑ボタンまたは青ボタンを押すと、AkAddressableBankManager.SetLanguageAndReloadLocalizedBanksファンクションがコールされ、ランゲージが英語、またはフランス語に変わります。

このファンクションで、以下の操作が実行されます:

  • すべてのローカライズされたバンクのアンロード
  • Initバンクのアンロード
  • Set the language using AkUnitySoundEngine.SetCurrentLanguage
  • Initバンクのリロード
  • ローカライズされたバンクのリロード
using UnityEngine;
public class AkWwiseSetLocalization : MonoBehaviour
{
public string LanguageString;
public void SetLanguage()
{
Debug.Log($"Setting language to {LanguageString}");
AK.Wwise.Unity.WwiseAddressables.AkAddressableBankManager.Instance.SetLanguageAndReloadLocalizedBanks(LanguageString);
}
}

これで、AddressablesDemoSceneをビルドして、ボタンをテストしながら、ビルドされたゲームがこれらのアセットをロードしているかを確認できます。

Addressablesのホスティングを設定する

This section explains how to configure Unity to serve the addressable DLC assets from a remote server. Certain details, such as how you transfer assets from a build path to a remote server, depend on your workflow and the systems you use. The following procedure describes the basic process to use for testing purposes.

To set up addressables hosting:

  1. Build the AddressablesDemoScene and ensure that it works as expected.
  2. Select File > Build Profiles and on the Scene List tab, ensure that the AddressablesDemoScene is included in the build.
  3. Ensure that you have a writable remote storage location.
  4. In the Addressables Groups window, select Profile > Manage Profiles and create a new profile.
  5. Set the Remote paths to the following:
  6. Right-click the new profile and select Set Active.
  7. Inspect the DLC_WwiseData_Windows group asset and set Build & Load Paths to Remote.
  8. From the menu bar, select Window > Asset Management > Addressables > Settings and select Build Remote Catalog. Set the Build & Load Paths to Remote.
  9. Rebuild your addressable assets using the Wwise Build Script. The new addressable AssetBundles are created in {Unity Project Path}\ServerData.
  10. Rebuild the AddressablesDemoScene and upload the generated assets to the remote load path.
  11. Run the AddressablesDemoScene and confirm that the sounds play.

Addressablesアセットをアップデートする

今度は、Addressablesを使ってDlcAssetHighImpactサウンドをアップデートします。

まず最初に、Wwiseで、サウンドファイルimp_axe_stone_highのピッチ値を調整して、変化がはっきりと分かるようにします。次に、SoundBankを再生成します。

さらに、Addressables Groupsウィンドウで、 Build >Update a previous build を選択します。選択ウィンドウが開くので、AddressableAssetsData/Windows 内の、addressables_content_state.bin ファイルを選択します。

最後に、ビルドされたゲームをもう一度実行します(リビルドはしません)。開いたときに、Addressables Hostingウィンドウにアップデートカタログのリクエストが表示されるはずです。

そして、左ボタンを押すと、サウンドエフェクトが新しいピッチ高さで聞こえるはずです。

Addressablesカタログや、開発サイクルの予定について、さらに詳しく知るには、 公式ドキュメンテーション を確認してください。

注記: このチュートリアルで提供するスクリプトは、Addressablesを使ったアセットのロードをテストするための、最低限のものです。 実際にプロジェクトにアセットをロードする際は、よりロバストなソリューションが必要になると考えられます。 さらに質の高い例が、 Unity Addressables Sample レポジトリにいくつかあります。
Definition: AkWwiseAcousticTexture.cs:21
Definition: AkWwiseAcousticTexture.cs:21

このページはお役に立ちましたか?

サポートは必要ですか?

ご質問や問題、ご不明点はございますか?お気軽にお問い合わせください。

サポートページをご確認ください

あなたのプロジェクトについて教えてください。ご不明な点はありませんか。

プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。

Wwiseからはじめよう