AkAssetFactories.cpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 "AkAssetFactories.h"
  16. #include "AkAcousticTexture.h"
  17. #include "AkAudioBank.h"
  18. #include "AkAudioDevice.h"
  19. #include "AkAudioEvent.h"
  20. #include "AkAuxBus.h"
  21. #include "AkRtpc.h"
  22. #include "AkSettings.h"
  23. #include "AkSettingsPerUser.h"
  24. #include "AkStateValue.h"
  25. #include "AkSwitchValue.h"
  26. #include "AkTrigger.h"
  27. #include "AkEffectShareSet.h"
  28. #include "AssetManagement/AkAssetDatabase.h"
  29. #include "AssetToolsModule.h"
  30. struct AkAssetFactory_Helper
  31. {
  32. template<typename AkAssetType = UAkAudioType>
  33. static UObject* FactoryCreateNew(UClass* Class, UObject* InParent, const FName& Name, EObjectFlags Flags, FGuid AssetID = FGuid{}, uint32 ShortID = AK_INVALID_UNIQUE_ID, FString WwiseObjectName = "")
  34. {
  35. auto ContainingPath = InParent->GetName();
  36. auto NewWwiseObject = NewObject<AkAssetType>(InParent, Name, Flags);
  37. FWwiseObjectInfo* Info = NewWwiseObject->GetInfoMutable();
  38. Info->WwiseGuid = AssetID;
  39. if (WwiseObjectName.IsEmpty())
  40. {
  41. Info->WwiseName = Name;
  42. }
  43. else
  44. {
  45. Info->WwiseName = FName(WwiseObjectName);
  46. }
  47. if (ShortID == AK_INVALID_UNIQUE_ID)
  48. {
  49. Info->WwiseShortId = FAkAudioDevice::GetShortID(nullptr, Name.ToString());
  50. }
  51. else
  52. {
  53. Info->WwiseShortId = ShortID;
  54. }
  55. NewWwiseObject->MarkPackageDirty();
  56. if(NewWwiseObject->bAutoLoad)
  57. {
  58. NewWwiseObject->LoadData();
  59. }
  60. return NewWwiseObject;
  61. }
  62. template<typename AkAssetType = UAkGroupValue>
  63. static UObject* FactoryCreateNewGroupValue(UClass* Class, UObject* InParent, const FName& Name, EObjectFlags Flags, FGuid AssetID = FGuid{}, uint32 ShortID = AK_INVALID_UNIQUE_ID, FString WwiseObjectName = "")
  64. {
  65. auto ContainingPath = InParent->GetName();
  66. AkAssetType* NewStateValue = NewObject<AkAssetType>(InParent, Name, Flags);
  67. FWwiseGroupValueInfo* Info = static_cast<FWwiseGroupValueInfo*>(NewStateValue->GetInfoMutable());
  68. Info->WwiseGuid = AssetID;
  69. FString StringName = Name.ToString();
  70. FString ValueName = StringName;
  71. FString GroupName;
  72. if (StringName.Contains(TEXT("-")))
  73. {
  74. StringName.Split(TEXT("-"), &GroupName, &ValueName);
  75. }
  76. if (WwiseObjectName.IsEmpty() && ValueName.IsEmpty())
  77. {
  78. Info->WwiseName = FName(StringName);
  79. }
  80. else if (WwiseObjectName.IsEmpty())
  81. {
  82. Info->WwiseName = FName(ValueName);
  83. }
  84. else
  85. {
  86. Info->WwiseName = FName(WwiseObjectName);
  87. }
  88. if (ShortID == AK_INVALID_UNIQUE_ID)
  89. {
  90. Info->WwiseShortId = FAkAudioDevice::GetShortID(nullptr, Info->WwiseName.ToString());
  91. }
  92. else
  93. {
  94. Info->WwiseShortId = ShortID;
  95. }
  96. if (!GroupName.IsEmpty())
  97. {
  98. Info->GroupShortId = FAkAudioDevice::GetShortID(nullptr, GroupName);
  99. }
  100. else
  101. {
  102. Info->GroupShortId = AK_INVALID_UNIQUE_ID;
  103. UE_LOG(LogAkAudio, Warning, TEXT("FactoryCreateNewGroupValue: New Group Value asset '%s' in '%s' will have an invalid group ID, please set the group ID manually."), *StringName, *InParent->GetPathName());
  104. }
  105. NewStateValue->MarkPackageDirty();
  106. if(NewStateValue->bAutoLoad)
  107. {
  108. NewStateValue->LoadData();
  109. }
  110. return NewStateValue;
  111. }
  112. template<typename AkAssetType>
  113. static bool CanCreateNew()
  114. {
  115. const UAkSettings* AkSettings = GetDefault<UAkSettings>();
  116. if (AkSettings)
  117. {
  118. return true;
  119. }
  120. return false;
  121. }
  122. private:
  123. static FString ConvertAssetPathToWwisePath(FString ContainingPath, const FString& AssetName, const FString& BasePath)
  124. {
  125. ContainingPath.RemoveFromStart(BasePath, ESearchCase::IgnoreCase);
  126. ContainingPath.RemoveFromEnd(FString("/") + AssetName);
  127. return ContainingPath.Replace(TEXT("/"), TEXT("\\")).Replace(TEXT("_"), TEXT(" "));
  128. }
  129. };
  130. //////////////////////////////////////////////////////////////////////////
  131. // UAkAcousticTextureFactory
  132. UAkAcousticTextureFactory::UAkAcousticTextureFactory(const class FObjectInitializer& ObjectInitializer)
  133. : Super(ObjectInitializer)
  134. {
  135. SupportedClass = UAkAcousticTexture::StaticClass();
  136. bCreateNew = bEditorImport = bEditAfterNew = true;
  137. }
  138. UObject* UAkAcousticTextureFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  139. {
  140. return AkAssetFactory_Helper::FactoryCreateNew<UAkAcousticTexture>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  141. }
  142. bool UAkAcousticTextureFactory::CanCreateNew() const
  143. {
  144. return AkAssetFactory_Helper::CanCreateNew<UAkAcousticTexture>();
  145. }
  146. //////////////////////////////////////////////////////////////////////////
  147. // UAkAudioEventFactory
  148. UAkAudioEventFactory::UAkAudioEventFactory(const class FObjectInitializer& ObjectInitializer)
  149. : Super(ObjectInitializer)
  150. {
  151. SupportedClass = UAkAudioEvent::StaticClass();
  152. bCreateNew = bEditorImport = bEditAfterNew = true;
  153. }
  154. UObject* UAkAudioEventFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  155. {
  156. return AkAssetFactory_Helper::FactoryCreateNew<UAkAudioEvent>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  157. }
  158. bool UAkAudioEventFactory::CanCreateNew() const
  159. {
  160. return AkAssetFactory_Helper::CanCreateNew<UAkAudioEvent>();
  161. }
  162. //////////////////////////////////////////////////////////////////////////
  163. // UAkAuxBusFactory
  164. UAkAuxBusFactory::UAkAuxBusFactory(const class FObjectInitializer& ObjectInitializer)
  165. : Super(ObjectInitializer)
  166. {
  167. SupportedClass = UAkAuxBus::StaticClass();
  168. bCreateNew = bEditorImport = bEditAfterNew = true;
  169. }
  170. UObject* UAkAuxBusFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  171. {
  172. return AkAssetFactory_Helper::FactoryCreateNew<UAkAuxBus>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  173. }
  174. bool UAkAuxBusFactory::CanCreateNew() const
  175. {
  176. return AkAssetFactory_Helper::CanCreateNew<UAkAuxBus>();
  177. }
  178. //////////////////////////////////////////////////////////////////////////
  179. // UAkRtpcFactory
  180. UAkRtpcFactory::UAkRtpcFactory(const class FObjectInitializer& ObjectInitializer)
  181. : Super(ObjectInitializer)
  182. {
  183. SupportedClass = UAkRtpc::StaticClass();
  184. bCreateNew = bEditorImport = bEditAfterNew = true;
  185. }
  186. UObject* UAkRtpcFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  187. {
  188. return AkAssetFactory_Helper::FactoryCreateNew<UAkRtpc>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  189. }
  190. bool UAkRtpcFactory::CanCreateNew() const
  191. {
  192. return AkAssetFactory_Helper::CanCreateNew<UAkRtpc>();
  193. }
  194. //////////////////////////////////////////////////////////////////////////
  195. // UAkTriggerFactory
  196. UAkTriggerFactory::UAkTriggerFactory(const class FObjectInitializer& ObjectInitializer)
  197. : Super(ObjectInitializer)
  198. {
  199. SupportedClass = UAkTrigger::StaticClass();
  200. bCreateNew = bEditorImport = bEditAfterNew = true;
  201. }
  202. UObject* UAkTriggerFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  203. {
  204. return AkAssetFactory_Helper::FactoryCreateNew<UAkTrigger>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  205. }
  206. bool UAkTriggerFactory::CanCreateNew() const
  207. {
  208. return AkAssetFactory_Helper::CanCreateNew<UAkTrigger>();
  209. }
  210. //////////////////////////////////////////////////////////////////////////
  211. // UAkStateValueFactory
  212. UAkStateValueFactory::UAkStateValueFactory(const class FObjectInitializer& ObjectInitializer)
  213. : Super(ObjectInitializer)
  214. {
  215. SupportedClass = UAkStateValue::StaticClass();
  216. bCreateNew = bEditorImport = bEditAfterNew = true;
  217. }
  218. UObject* UAkStateValueFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  219. {
  220. return AkAssetFactory_Helper::FactoryCreateNewGroupValue<UAkStateValue>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  221. }
  222. //////////////////////////////////////////////////////////////////////////
  223. // UAkSwitchValueFactory
  224. UAkSwitchValueFactory::UAkSwitchValueFactory(const class FObjectInitializer& ObjectInitializer)
  225. : Super(ObjectInitializer)
  226. {
  227. SupportedClass = UAkSwitchValue::StaticClass();
  228. bCreateNew = bEditorImport = bEditAfterNew = true;
  229. }
  230. UObject* UAkSwitchValueFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  231. {
  232. return AkAssetFactory_Helper::FactoryCreateNewGroupValue<UAkSwitchValue>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  233. }
  234. //////////////////////////////////////////////////////////////////////////
  235. // UAkEffectShareSetFactory
  236. UAkEffectShareSetFactory::UAkEffectShareSetFactory(const class FObjectInitializer& ObjectInitializer)
  237. : Super(ObjectInitializer)
  238. {
  239. SupportedClass = UAkEffectShareSet::StaticClass();
  240. bCreateNew = bEditorImport = bEditAfterNew = true;
  241. }
  242. UObject* UAkEffectShareSetFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
  243. {
  244. return AkAssetFactory_Helper::FactoryCreateNew<UAkEffectShareSet>(Class, InParent, Name, Flags, AssetID, ShortID, WwiseObjectName);
  245. }