어드레서블 Wwise 에셋으로 작업할 때 WwiseAddressableBank 에셋을 최신 상태로 유지하는 가장 쉬운 방법은 생성된 Soundbank 폴더를 삭제하고 Soundbank를 재생성하는 것입니다. 어드레서블 에셋을 삭제하면 에셋이 삭제될 때 어드레서블 그룹의 내용이 지워지므로 에셋을 다시 가져올 때 상위 그룹과 레이블이 손실됩니다. Wwise Unity Addressables 패키지에 포함된 이 샘플 스크립트는 상위 그룹 및 레이블과 같은 어드레서블 에셋 메타데이터를 보존하는 기능을 제공합니다.
손실된 그룹 및 레이블을 복원하는 데 도움이 되도록 활성화할 수 있는 설정을 추가했습니다. Unity Project Setting-Wwise Addressables에서 찾을 수 있습니다.. 활성화되면 메타데이터의 대상 폴더를 지정할 수 있습니다. 이 폴더는 Unity 프로젝트의 에셋 폴더 내에 있어야 합니다.
이 두 가지 메커니즘을 통해 에셋 메타데이터는 정리를 수행하기 전에 직렬화(serialized)할 수 있으며 사운드뱅크를 생성한 후 에셋을 다시 가져올 때 에셋에 다시 적용됩니다.
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
namespace AK.Wwise.Unity.WwiseAddressables
{
[InitializeOnLoad]
class WwiseAddressableAssetMetadataPreserver
{
static WwiseAddressableAssetMetadataPreserver()
{
if (AkAddressablesEditorSettings.Instance.UseSampleMetadataPreserver)
{
BindMetadataDelegate();
}
}
public static void BindMetadataDelegate()
{
WwiseBankPostProcess.GetAssetMetadataDelegate += GetMetadata;
}
public static void UnbindMetaDataDelegate()
{
WwiseBankPostProcess.GetAssetMetadataDelegate -= GetMetadata;
}
[UnityEditor.MenuItem("Assets/Wwise/Addressables/Serialize addressable asset metadata")]
public static void PreserveAllWwiseAssetMetadata()
{
AddressableAssetSettings addressableSettings = AddressableAssetSettingsDefaultObject.Settings;
foreach (AddressableAssetGroup group in addressableSettings.groups)
{
foreach (AddressableAssetEntry assetEntry in group.entries)
{
if (assetEntry.MainAsset)
{
if (assetEntry.MainAsset.GetType().IsSubclassOf(typeof(WwiseAsset)))
{
CreateMetadataAsset(assetEntry.AssetPath, assetEntry.labels, group.name);
}
}
}
}
}
[UnityEditor.MenuItem("Assets/Wwise/Addressables/Preserve addressable asset metadata", true)]
public static bool ValidatePreserveAllWwiseAssetMetadata()
{
return AkAddressablesEditorSettings.Instance.UseSampleMetadataPreserver;
}
public static void CreateMetadataAsset(string assetPath, HashSet<string> assetLabels, string groupName)
{
string soundbankPath = assetPath.Replace(AkAssetUtilities.GetSoundbanksPath(), "");
var splitBankPath = soundbankPath.Split('/');
AddressableMetadata metaDataAsset = ScriptableObject.CreateInstance<AddressableMetadata>();
metaDataAsset.labels = new List<string>(assetLabels);
metaDataAsset.groupName = groupName;
var rootPath = AkAddressablesEditorSettings.Instance.MetadataPath;
if (!Directory.Exists(Path.Combine(Application.dataPath, rootPath)))
{
UnityEditor.AssetDatabase.CreateFolder("Assets", rootPath);
}
for (int i = 1; i < splitBankPath.Length - 1; i++)
{
if (!Directory.Exists(Path.Combine(Application.dataPath, Path.Combine(rootPath, splitBankPath[i]))))
{
AssetDatabase.CreateFolder(Path.Combine("Assets", rootPath), splitBankPath[i]);
}
rootPath = Path.Combine(rootPath, splitBankPath[i]);
}
string assetMetadataPath = Path.Combine("Assets", rootPath, Path.GetFileNameWithoutExtension(assetPath) + ".asset");
AddressableMetadata oldAsset = AssetDatabase.LoadAssetAtPath<AddressableMetadata>(assetMetadataPath);
if (oldAsset)
{
if (!metaDataAsset.IsDifferent(oldAsset))
{
return;
}
}
UnityEditor.AssetDatabase.CreateAsset(metaDataAsset, assetMetadataPath);
}
public static AddressableMetadata FindMetadataAsset(string assetName, string platformName, string languageName)
{
string MetadataAssetPath;
if (languageName !="SFX")
{
MetadataAssetPath = Path.Combine("Assets", AkAddressablesEditorSettings.Instance.MetadataPath, platformName, languageName, Path.GetFileNameWithoutExtension(assetName) + ".asset");
}
else
{
MetadataAssetPath = Path.Combine("Assets", AkAddressablesEditorSettings.Instance.MetadataPath, platformName, Path.GetFileNameWithoutExtension(assetName) + ".asset");
}
return AssetDatabase.LoadAssetAtPath<AddressableMetadata>(MetadataAssetPath);
}
public static bool GetMetadata(string assetName, string platformName, string languageName, ref AddressableMetadata metaData )
{
AddressableMetadata asset = FindMetadataAsset(assetName, platformName, languageName);
if ( asset )
{
metaData = asset;
return true;
}
return false;
}
}
}
#endif