AkUnrealAssetDataHelper.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "AkUnrealAssetDataHelper.h"
  16. #include "AssetRegistry/AssetData.h"
  17. #include "AkAudioEvent.h"
  18. #include "AkAuxBus.h"
  19. #include "AkEffectShareSet.h"
  20. #include "AkGroupValue.h"
  21. #include "AkSettings.h"
  22. #include "AkStateValue.h"
  23. #include "AkSwitchValue.h"
  24. #include "AkTrigger.h"
  25. #include "IAudiokineticTools.h"
  26. #include "PackageTools.h"
  27. #include "Wwise/Metadata/WwiseMetadataStateGroup.h"
  28. #include "Wwise/Metadata/WwiseMetadataSwitchGroup.h"
  29. #include "Wwise/Ref/WwiseAnyRef.h"
  30. #include "Wwise/Ref/WwiseRefType.h"
  31. namespace AkUnrealAssetDataHelper
  32. {
  33. bool IsSameType(const FAssetData& AssetData, EWwiseItemType::Type ItemType)
  34. {
  35. return GetUClassName(ItemType) == GetAssetClassName(AssetData);
  36. }
  37. FName GetUClassName(EWwiseItemType::Type ItemType)
  38. {
  39. UClass* Class = nullptr;
  40. switch (ItemType)
  41. {
  42. case EWwiseItemType::Event:
  43. Class = UAkAudioEvent::StaticClass();
  44. break;
  45. case EWwiseItemType::AuxBus:
  46. Class = UAkAuxBus::StaticClass();
  47. break;
  48. case EWwiseItemType::AcousticTexture:
  49. Class = UAkAcousticTexture::StaticClass();
  50. break;
  51. case EWwiseItemType::State:
  52. Class = UAkStateValue::StaticClass();
  53. break;
  54. case EWwiseItemType::Switch:
  55. Class = UAkSwitchValue::StaticClass();
  56. break;
  57. case EWwiseItemType::GameParameter:
  58. Class = UAkRtpc::StaticClass();
  59. break;
  60. case EWwiseItemType::Trigger:
  61. Class = UAkTrigger::StaticClass();
  62. break;
  63. case EWwiseItemType::EffectShareSet:
  64. Class = UAkEffectShareSet::StaticClass();
  65. break;
  66. }
  67. if (Class)
  68. {
  69. #if UE_5_1_OR_LATER
  70. return Class->GetClassPathName().GetAssetName();
  71. #else
  72. return Class->GetFName();
  73. #endif
  74. }
  75. return FName();
  76. }
  77. FName GetAssetClassName(const FAssetData& AssetData)
  78. {
  79. #if UE_5_1_OR_LATER
  80. return AssetData.AssetClassPath.GetAssetName();
  81. #else
  82. return AssetData.AssetClass;
  83. #endif
  84. }
  85. bool IsAssetAkAudioType(const FAssetData& AssetData)
  86. {
  87. auto Value = AssetData.TagsAndValues.FindTag(FName("WwiseGuid"));
  88. return Value.IsSet();
  89. }
  90. bool IsAssetTransient(const FAssetData& AssetData)
  91. {
  92. return AssetData.PackagePath.ToString() == UPackageTools::SanitizePackageName(GetTransientPackage()->GetPathName());
  93. }
  94. void SetAssetClassName(FAssetData& AssetData, UClass* Class)
  95. {
  96. #if UE_5_1_OR_LATER
  97. AssetData.AssetClassPath = Class->GetClassPathName();
  98. #else
  99. AssetData.AssetClass = Class->GetFName();
  100. #endif
  101. }
  102. FString GetAssetDefaultPackagePath(const FAssetData& AssetData)
  103. {
  104. if (auto AkAudioAsset = Cast<UAkAudioType>(AssetData.GetAsset()))
  105. {
  106. return AkAudioAsset->GetAssetDefaultPackagePath().ToString();
  107. }
  108. return {};
  109. }
  110. FString GetAssetDefaultPackagePath(const FWwiseAnyRef* WwiseRef)
  111. {
  112. auto AkSettings = GetMutableDefault<UAkSettings>();
  113. if (!AkSettings)
  114. {
  115. UE_LOG(LogAudiokineticTools, Error, TEXT("Could not fetch AkSettings"));
  116. return {};
  117. }
  118. auto WwiseRefType = WwiseRef->GetType();
  119. const FString DefaultPath = AkSettings->DefaultAssetCreationPath;
  120. switch (WwiseRefType)
  121. {
  122. case EWwiseRefType::AcousticTexture:
  123. return DefaultPath / "VirtualAcoustics";
  124. case EWwiseRefType::AuxBus:
  125. return DefaultPath / "AuxBusses/";
  126. case EWwiseRefType::Event:
  127. return DefaultPath / "Events/";
  128. case EWwiseRefType::GameParameter:
  129. return DefaultPath / "GameParameters/";
  130. case EWwiseRefType::PluginShareSet:
  131. return DefaultPath / "Sharesets/";
  132. case EWwiseRefType::Switch:
  133. {
  134. FString GroupName = WwiseRef->GetSwitchGroup()->Name.ToString();
  135. return DefaultPath / "Switches/" / GroupName;
  136. }
  137. case EWwiseRefType::State:
  138. {
  139. FString GroupName = WwiseRef->GetStateGroup()->Name.ToString();
  140. return DefaultPath / "States/" / GroupName;
  141. }
  142. case EWwiseRefType::Trigger:
  143. return DefaultPath / "Triggers/";
  144. default:
  145. return {};
  146. }
  147. }
  148. FName GetAssetDefaultName(const FAssetData& AssetData)
  149. {
  150. if (auto AkAudioAsset = Cast<UAkAudioType>(AssetData.GetAsset()))
  151. {
  152. return AkAudioAsset->GetAssetDefaultName();
  153. }
  154. return {};
  155. }
  156. FName GetAssetDefaultName(const FWwiseAnyRef* WwiseRef)
  157. {
  158. EWwiseRefType WwiseRefType = WwiseRef->GetType();
  159. FName WwiseName = WwiseRef->GetName();
  160. FNameBuilder DefaultName;
  161. switch (WwiseRefType)
  162. {
  163. case EWwiseRefType::AcousticTexture:
  164. case EWwiseRefType::AuxBus:
  165. case EWwiseRefType::Event:
  166. case EWwiseRefType::GameParameter:
  167. case EWwiseRefType::PluginShareSet:
  168. case EWwiseRefType::Trigger:
  169. return WwiseName;
  170. case EWwiseRefType::Switch:
  171. {
  172. FString GroupName = WwiseRef->GetSwitchGroup()->Name.ToString();
  173. DefaultName << GroupName << TEXT("-") << WwiseName;
  174. #if UE_5_0_OR_LATER
  175. return FName(DefaultName.ToView());
  176. #else
  177. return FName(DefaultName.ToString());
  178. #endif
  179. }
  180. case EWwiseRefType::State:
  181. {
  182. FString GroupName = WwiseRef->GetStateGroup()->Name.ToString();
  183. DefaultName << GroupName << TEXT("-") << WwiseName;
  184. #if UE_5_0_OR_LATER
  185. return FName(DefaultName.ToView());
  186. #else
  187. return FName(DefaultName.ToString());
  188. #endif
  189. }
  190. default:
  191. return {};
  192. }
  193. }
  194. }