バージョン

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

この例では、一部のアセット(例えば新アイテムやキャラクターなど)をほかと分けて、それ専用のDLCアセットバンドルとしてAddressablesを使ってパッケージングしたい、という簡単な状況に対応します。

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

まだプロジェクトにWwise Unity Addressablesパッケージを設定していない場合は、 Wwise Unity Addressablesパッケージをインストールする に従ってください。

The official repository for the Addressables Demo Scene used in this tutorial is https://github.com/audiokinetic/WwiseUnityAddressablesDemoScene. The demo scene uses assets that are found in the WwiseDemoScene so it must be installed first through the Audiokinetic Launcher.

手順:

  1. Install the latest Demo Game using the Audiokinetic Launcher.
  2. Clone the Wwise Unity Addressables demo scene to your computer.
  3. Open the WwiseDemoScene in Unity.
  4. In the Unity Package Manager, add the Wwise Unity Addressables package to the project as detailed in section Wwise Addressables Packageを、Unity Package ManagerとGitHubでインストールする.
  5. Finally, add the Wwise Unity Addressables Demo Scene package with the Add package from disk option in the Package Manager.
注記: このパッケージを Add package from git URL を使って追加してしまうと、パッケージ内にあるシーンが開けなくなるので、このインストール方式は避けてください。

始めてみよう

このチュートリアル用に、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グループに移します。
注記:
  • We made sure to include the strings WwiseData and the platform name Windows in the platform specific group name, so that it will be properly handled by the BuildWwiseData script when building Addressables.
  • To save your group modifications, run the Assets > Wwise > Addressables > Serialize addressable asset metadata action once with the Use Sample Metadata Preserver setting enabled.

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

次に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バンクのアンロード
  • AkSoundEngine.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のホスティングを設定する

次に、Unityの組込みホスティングサービスを私たちのAddressable DLCアセットに利用できるように、Unityを設定します。これを使えば、プレイヤーをリビルドしなくても、Addressablesを使ったアセットのアップデートをテストできます。

まず最初に、AddressablesDemoSceneをビルドして、期待通りの動きをするかを確認します。 Buildウィンドウで、 Add open scenes ボタンを使ってAddressablesDemoSceneを追加して、ビルドするシーンとして選択します。

次に、Addressables Hostingを設定するために、Toolsメニューからアクセスします。

次にLocal Hostingサービスを作成して、Enableチェックボックスを選択してそれを有効にします。

Addressables Profilesウィンドウを開くために、メニューで選択し(Profile > Manage Profiles)、Editor Hostedという新プロファイルを作成します。

LocalRemoteを設定します。次に、各Pathを以下のように設定します:

  • Local.BuildPath : HostedData/[BuildTarget]
  • Local.LoadPath : http://[PrivateIpAddress]:[HostingServicePort]
  • Remote.BuildPath : HostedData/[BuildTarget]
  • Remote.LoadPath : http://[PrivateIpAddress]:[HostingServicePort]

次に、このプロファイルを使えるように、 Editor Hosted を右クリックして Set Active を選択します。

注記: Addressablesホスティングサービスの詳細は、 公式ドキュメンテーション を参照してください。

DLC_WwiseData_Windowsグループアセットを確認し、そのBuild & Load Pathsが更新されていることを確認します。

Addressable Asset Settingsを開いてBuild Remote Catalogを有効にします。Build & Load PathsをLocalに設定します。

あなたのAddressableアセットを、Wwise Build Scriptを使ってリビルドします。新しいAdressable AssetBundleが、 <Unity Project Path>\HostedData 内に作成されるはずです。

次に、AddressablesDemoSceneをリビルドして、あなたのアセットに正しく対応することをテストします。

Addressables Hostingウィンドウを開き、ゲームを実行しながら、入ってくるリクエストを確認します。ボタンを最初に押したときに、ウィンドウの下にあるイベントログに、リクエストが表示されるはずです。

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からはじめよう