AkAudioEvent.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. #pragma once
  16. #include "AkAudioType.h"
  17. #include "AkGameplayTypes.h"
  18. #include "Wwise/CookedData/WwiseLocalizedEventCookedData.h"
  19. #include "Wwise/Loaded/WwiseLoadedEvent.h"
  20. #if WITH_EDITORONLY_DATA
  21. #include "Wwise/Info/WwiseEventInfo.h"
  22. #endif
  23. #include "AkAudioEvent.generated.h"
  24. class UAkGameObject;
  25. class UAkGroupValue;
  26. class UAkAuxBus;
  27. class UAkAudioBank;
  28. class UAkTrigger;
  29. UCLASS(BlueprintType)
  30. class AKAUDIO_API UAkAudioEvent : public UAkAudioType
  31. {
  32. GENERATED_BODY()
  33. //
  34. // Unreal properties
  35. //
  36. public:
  37. UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "AkAudioEvent")
  38. float MaxAttenuationRadius = .0f;
  39. /** Whether this event is infinite (looping) or finite (duration parameters are valid) */
  40. UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "AkAudioEvent")
  41. bool IsInfinite = false;
  42. /** Minimum duration */
  43. UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "AkAudioEvent")
  44. float MinimumDuration = .0f;
  45. /** Maximum duration */
  46. UPROPERTY(Transient, VisibleAnywhere, BlueprintReadOnly, Category = "AkAudioEvent")
  47. float MaximumDuration = .0f;
  48. #if WITH_EDITORONLY_DATA
  49. UPROPERTY(EditAnywhere, Category = "AkAudioEvent")
  50. FWwiseEventInfo EventInfo;
  51. #endif
  52. UPROPERTY(Transient, VisibleAnywhere, Category = "AkAudioEvent")
  53. FWwiseLocalizedEventCookedData EventCookedData;
  54. UPROPERTY(meta = (DeprecatedProperty, DeprecationMessage = "Used for migration"))
  55. UAkAudioBank* RequiredBank_DEPRECATED = nullptr;
  56. public:
  57. /**
  58. * @brief Posts the Wwise Event on the root component of the specified actor.
  59. *
  60. * @param Actor Actor on which to play the event. This actor gets followed automatically by the Event. If the Actor is left empty,
  61. * the Event will be played as an Ambient sound.
  62. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  63. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  64. * @param bStopWhenAttachedObjectDestroyed Specifies whether the sound should stop playing when the owner of the attach to component
  65. * is destroyed. This parameter modifies the AkComponent itself, you can only have one behavior per actor's root component.
  66. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  67. */
  68. UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category="Audiokinetic|Actor", meta=(AdvancedDisplay="1", AutoCreateRefTerm = "Delegate"))
  69. int32 PostOnActor(const AActor* Actor,
  70. const FOnAkPostEventCallback& Delegate,
  71. UPARAM(meta = (Bitmask, BitmaskEnum = "/Script/AkAudio.EAkCallbackType")) const int32 CallbackMask,
  72. const bool bStopWhenAttachedObjectDestroyed);
  73. /**
  74. * @brief Posts the Wwise Event on the specified component.
  75. *
  76. * @param Component Component on which to play the event.
  77. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  78. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  79. * @param bStopWhenAttachedObjectDestroyed Specifies whether the sound should stop playing when the owner of the attach to component
  80. * is destroyed. This parameter modifies the AkComponent itself, you can only have one behavior per actor's root component.
  81. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  82. */
  83. UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category="Audiokinetic|AkComponent", meta=(AdvancedDisplay="1", AutoCreateRefTerm = "Delegate"))
  84. int32 PostOnComponent(UAkComponent* Component,
  85. const FOnAkPostEventCallback& Delegate,
  86. UPARAM(meta = (Bitmask, BitmaskEnum = "/Script/AkAudio.EAkCallbackType")) const int32 CallbackMask,
  87. const bool bStopWhenAttachedObjectDestroyed);
  88. /**
  89. * @brief Posts the Wwise Event on the specified game object.
  90. *
  91. * @param GameObject Game object on which to play the event.
  92. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  93. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  94. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  95. */
  96. UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category="Audiokinetic|AkGameObject", meta=(AdvancedDisplay="1", AutoCreateRefTerm = "Delegate"))
  97. int32 PostOnGameObject(UAkGameObject* GameObject,
  98. const FOnAkPostEventCallback& Delegate,
  99. UPARAM(meta = (Bitmask, BitmaskEnum = "/Script/AkAudio.EAkCallbackType")) const int32 CallbackMask);
  100. /**
  101. * @brief Posts the Wwise Event on the root component of the specified actor, and waits for the end of the event to continue execution.
  102. *
  103. * Additional calls made while an event is active on a particular actor's root component are ignored.
  104. *
  105. * @param Actor Actor on which to play the event. This actor gets followed automatically by the Event.
  106. * @param bStopWhenAttachedObjectDestroyed Specifies whether the sound should stop playing when the owner of the attach to component is destroyed.
  107. * This parameter modifies the AkComponent itself, you can only have one behavior per actor's root component.
  108. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  109. */
  110. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|Actor", meta = (Latent, LatentInfo = "LatentActionInfo", AdvancedDisplay = "1", bStopWhenAttachedObjectDestroyed="false"))
  111. int32 PostOnActorAndWait(const AActor* Actor,
  112. const bool bStopWhenAttachedObjectDestroyed,
  113. const FLatentActionInfo LatentActionInfo);
  114. /**
  115. * @brief Posts the Wwise Event on the specified component, and waits for the end of the event to continue execution.
  116. *
  117. * Additional calls made while an event is active on a particular component are ignored.
  118. *
  119. * @param Component component on which to play the event. This component gets followed automatically by the Event.
  120. * @param bStopWhenAttachedObjectDestroyed Specifies whether the sound should stop playing when the owner of the attach to component is destroyed.
  121. * This parameter modifies the AkComponent itself, you can only have one behavior per actor's root component.
  122. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  123. */
  124. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|AkComponent", meta = (Latent, LatentInfo = "LatentActionInfo", AdvancedDisplay = "1", bStopWhenAttachedObjectDestroyed="false"))
  125. int32 PostOnComponentAndWait(UAkComponent* Component,
  126. const bool bStopWhenAttachedObjectDestroyed,
  127. const FLatentActionInfo LatentActionInfo);
  128. /**
  129. * @brief Posts the Wwise Event on the specified game object, and waits for the end of the event to continue execution.
  130. *
  131. * Additional calls made while an event is active on a particular game object are ignored.
  132. *
  133. * @param GameObject Game object on which to play the event. This game object gets followed automatically by the Event.
  134. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  135. */
  136. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|AkGameObject", meta = (Latent, LatentInfo = "LatentActionInfo", AdvancedDisplay = "1", bStopWhenAttachedObjectDestroyed="false"))
  137. int32 PostOnGameObjectAndWait(UAkGameObject* GameObject,
  138. const FLatentActionInfo LatentActionInfo);
  139. /**
  140. * @brief Posts a Wwise Event at the specified location.
  141. *
  142. * This is a fire and forget sound, created on a temporary Wwise Game Object. Replication is also not handled at this point.
  143. *
  144. * @param Location Location from which to post the Wwise Event.
  145. * @param Orientation Orientation of the event.
  146. * @param Callback Function that gets called every time the operation defined by CallbackMask is processed.
  147. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  148. * @param WorldContextObject An object having the world we target as context.
  149. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  150. */
  151. UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category="Audiokinetic", meta=(WorldContext="WorldContextObject", AdvancedDisplay = "2"))
  152. int32 PostAtLocation(const FVector Location,
  153. const FRotator Orientation,
  154. const FOnAkPostEventCallback& Callback,
  155. UPARAM(meta = (Bitmask, BitmaskEnum = "/Script/AkAudio.EAkCallbackType")) const int32 CallbackMask,
  156. const UObject* WorldContextObject);
  157. /**
  158. * @brief Executes action on the different playing IDs from this event that were previously posted on the
  159. * Actor's root component.
  160. *
  161. * @param ActionType What action to do.
  162. * @param Actor The actor that initially got some event posted.
  163. * @param PlayingID Use the return value of a Post Event to act only on this specific instance of an event.
  164. * Use 0 for all the posted operations from this event.
  165. * @param TransitionDuration Transition duration in milliseconds.
  166. * @param FadeCurve The interpolation curve of the transition.
  167. * @return AKRESULT for the operation. AK_Success (0) if successful.
  168. */
  169. UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category = "Audiokinetic|Actor", meta=(AdvancedDisplay = "2"))
  170. int32 ExecuteAction(const AkActionOnEventType ActionType,
  171. const AActor* Actor,
  172. const int32 PlayingID = 0,
  173. const int32 TransitionDuration = 0,
  174. const EAkCurveInterpolation FadeCurve = EAkCurveInterpolation::Linear);
  175. public:
  176. /**
  177. * @brief Posts the Wwise Event on the root component of the specified actor.
  178. *
  179. * @param Actor Actor on which to play the event. This actor gets followed automatically by the Event. If the Actor is left empty,
  180. * the Event will be played as an Ambient sound.
  181. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  182. * This version is useful for Blueprint callbacks. This is mutually exclusive with AkCallback and LatentAction.
  183. * @param Callback Function that gets called every time the operation defined by CallbackMask is processed,
  184. * with the Cookie parameter to provide data. This is mutually exclusive with Delegate and LatentAction.
  185. * @param Cookie Parameter provided for AkCallback to provide data.
  186. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  187. * @param LatentAction Function called when the posted event is done playing for latent Blueprint operation.
  188. * This is mutually exclusive with Delegate and Callback.
  189. * @param bStopWhenAttachedObjectDestroyed Specifies whether the sound should stop playing when the owner of the attach
  190. * to component is destroyed. This parameter modifies the AkComponent itself, you can only have one behavior per
  191. * actor's root component.
  192. * @param AudioContext Context in which the Event's sounds are played. Only GamePlayAudio sounds are affected by PIE pause/stop.
  193. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  194. */
  195. AkPlayingID PostOnActor(const AActor* Actor,
  196. const FOnAkPostEventCallback* Delegate,
  197. AkCallbackFunc Callback,
  198. void* Cookie,
  199. const AkCallbackType CallbackMask,
  200. FWaitEndOfEventAction* LatentAction,
  201. const bool bStopWhenAttachedObjectDestroyed,
  202. const EAkAudioContext AudioContext = EAkAudioContext::GameplayAudio);
  203. /**
  204. * @brief Posts the Wwise Event on the specified component.
  205. *
  206. * @param Component Component on which to play the event.
  207. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  208. * This version is useful for Blueprint callbacks. This is mutually exclusive with AkCallback and LatentAction.
  209. * @param Callback Function that gets called every time the operation defined by CallbackMask is processed,
  210. * with the Cookie parameter to provide data. This is mutually exclusive with Delegate and LatentAction.
  211. * @param Cookie Parameter provided for AkCallback to provide data.
  212. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  213. * @param LatentAction Function called when the posted event is done playing for latent Blueprint operation.
  214. * This is mutually exclusive with Delegate and Callback.
  215. * @param bStopWhenAttachedObjectDestroyed Specifies whether the sound should stop playing when the owner of the attach
  216. * to component is destroyed. This parameter modifies the AkComponent itself, you can only have one behavior per
  217. * actor's root component.
  218. * @param AudioContext Context in which the Event's sounds are played. Only GamePlayAudio sounds are affected by PIE pause/stop.
  219. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  220. */
  221. AkPlayingID PostOnComponent(UAkComponent* Component,
  222. const FOnAkPostEventCallback* Delegate,
  223. AkCallbackFunc Callback,
  224. void* Cookie,
  225. const AkCallbackType CallbackMask,
  226. FWaitEndOfEventAction* LatentAction,
  227. const bool bStopWhenAttachedObjectDestroyed,
  228. const EAkAudioContext AudioContext = EAkAudioContext::GameplayAudio);
  229. /**
  230. * @brief Posts a Wwise Event at the specified location.
  231. *
  232. * This is a fire and forget sound, created on a temporary Wwise Game Object. Replication is also not handled at this point.
  233. *
  234. * @param Location Location from which to post the Wwise Event.
  235. * @param Orientation Orientation of the event.
  236. * @param World The world that defines the Location's coordinates.
  237. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  238. * This version is useful for Blueprint callbacks. This is mutually exclusive with AkCallback and LatentAction.
  239. * @param Callback Function that gets called every time the operation defined by CallbackMask is processed,
  240. * with the Cookie parameter to provide data. This is mutually exclusive with Delegate and LatentAction.
  241. * @param Cookie Parameter provided for AkCallback to provide data.
  242. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  243. * @param LatentAction Function called when the posted event is done playing for latent Blueprint operation.
  244. * This is mutually exclusive with Delegate and Callback.
  245. * @param AudioContext Context in which the Event's sounds are played. Only GamePlayAudio sounds are affected by PIE pause/stop.
  246. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  247. */
  248. AkPlayingID PostAtLocation(const FVector& Location, const FRotator& Orientation, const UWorld* World,
  249. const FOnAkPostEventCallback* Delegate,
  250. AkCallbackFunc Callback,
  251. void* Cookie,
  252. const AkCallbackType CallbackMask,
  253. FWaitEndOfEventAction* LatentAction,
  254. const EAkAudioContext AudioContext = EAkAudioContext::GameplayAudio);
  255. /**
  256. * @brief Posts a Wwise Event onto a dummy object.
  257. *
  258. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  259. * This version is useful for Blueprint callbacks. This is mutually exclusive with AkCallback and LatentAction.
  260. * @param Callback Function that gets called every time the operation defined by CallbackMask is processed,
  261. * with the Cookie parameter to provide data. This is mutually exclusive with Delegate and LatentAction.
  262. * @param Cookie Parameter provided for AkCallback to provide data.
  263. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  264. * @param LatentAction Function called when the posted event is done playing for latent Blueprint operation.
  265. * This is mutually exclusive with Delegate and Callback.
  266. * @param AudioContext Context in which the Event's sounds are played. Only GamePlayAudio sounds are affected by PIE pause/stop.
  267. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  268. */
  269. AkPlayingID PostAmbient(
  270. const FOnAkPostEventCallback* Delegate,
  271. AkCallbackFunc Callback,
  272. void* Cookie,
  273. const AkCallbackType CallbackMask,
  274. FWaitEndOfEventAction* LatentAction,
  275. const EAkAudioContext AudioContext = EAkAudioContext::GameplayAudio);
  276. /**
  277. * @brief Posts the Wwise Event on the specified game object.
  278. *
  279. * @param GameObject Game object on which to play the event.
  280. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  281. * This version is useful for Blueprint callbacks. This is mutually exclusive with AkCallback and LatentAction.
  282. * @param Callback Function that gets called every time the operation defined by CallbackMask is processed,
  283. * with the Cookie parameter to provide data. This is mutually exclusive with Delegate and LatentAction.
  284. * @param Cookie Parameter provided for AkCallback to provide data.
  285. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  286. * @param LatentAction Function called when the posted event is done playing for latent Blueprint operation.
  287. * This is mutually exclusive with Delegate and Callback.
  288. * @param AudioContext Context in which the Event's sounds are played. Only GamePlayAudio sounds are affected by PIE pause/stop.
  289. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  290. */
  291. AkPlayingID PostOnGameObject(UAkGameObject* GameObject,
  292. const FOnAkPostEventCallback* Delegate,
  293. AkCallbackFunc Callback,
  294. void* Cookie,
  295. const AkCallbackType CallbackMask,
  296. FWaitEndOfEventAction* LatentAction,
  297. const EAkAudioContext AudioContext = EAkAudioContext::GameplayAudio);
  298. /**
  299. * @brief Posts the Wwise Event on the specified game object ID.
  300. *
  301. * @param GameObjectID Game object's ID on which to play the event.
  302. * @param Delegate Function that gets called every time the operation defined by CallbackMask is processed.
  303. * This version is useful for Blueprint callbacks. This is mutually exclusive with AkCallback and LatentAction.
  304. * @param Callback Function that gets called every time the operation defined by CallbackMask is processed,
  305. * with the Cookie parameter to provide data. This is mutually exclusive with Delegate and LatentAction.
  306. * @param Cookie Parameter provided for AkCallback to provide data.
  307. * @param CallbackMask Bitmask defining all the operations that will call the Callback. See \ref AkCallbackType.
  308. * @param LatentAction Function called when the posted event is done playing for latent Blueprint operation.
  309. * This is mutually exclusive with Delegate and Callback.
  310. * @param AudioContext Context in which the Event's sounds are played. Only GamePlayAudio sounds are affected by PIE pause/stop.
  311. * @return The Playing ID returned by the SoundEngine's PostEvent, or AK_INVALID_PLAYING_ID (0) if invalid.
  312. */
  313. AkPlayingID PostOnGameObjectID(const AkGameObjectID GameObjectID,
  314. const FOnAkPostEventCallback* Delegate,
  315. AkCallbackFunc Callback,
  316. void* Cookie,
  317. const AkCallbackType CallbackMask,
  318. FWaitEndOfEventAction* LatentAction,
  319. const EAkAudioContext AudioContext = EAkAudioContext::GameplayAudio);
  320. private:
  321. template<typename FCreateCallbackPackage>
  322. AkPlayingID PostEvent(const AkGameObjectID GameObjectID,
  323. FCreateCallbackPackage&& CreateCallbackPackage,
  324. const EAkAudioContext AudioContext
  325. );
  326. public:
  327. void Serialize(FArchive& Ar) override;
  328. void BeginDestroy() override;
  329. virtual void LoadData() override {LoadEventData();}
  330. virtual void UnloadData(bool bAsync = false) override {UnloadEventData(bAsync);}
  331. virtual AkUInt32 GetShortID() const override {return EventCookedData.EventId;}
  332. bool IsDataFullyLoaded() const;
  333. bool IsLoaded() const;
  334. #if WITH_EDITOR
  335. // Allow for content browser preview to work, even if asset is not auto-loaded.
  336. // This method will load the content, and register to BeginPIE. When a PIE session
  337. // begins, data will be unloaded, allowing to replicate in-game behaviour more
  338. // closely.
  339. void LoadEventDataForContentBrowserPreview();
  340. private:
  341. void OnBeginPIE(const bool bIsSimulating);
  342. FDelegateHandle OnBeginPIEDelegateHandle;
  343. #endif
  344. #if WITH_EDITORONLY_DATA
  345. public:
  346. virtual void FillInfo() override;
  347. virtual void FillMetadata(FWwiseProjectDatabase* ProjectDatabase) override;
  348. void CookAdditionalFilesOverride(const TCHAR* PackageFilename, const ITargetPlatform* TargetPlatform,
  349. TFunctionRef<void(const TCHAR* Filename, void* Data, int64 Size)> WriteAdditionalFile) override;
  350. virtual FWwiseObjectInfo* GetInfoMutable() override {return &EventInfo;}
  351. virtual FWwiseObjectInfo GetInfo() const override{return EventInfo;}
  352. virtual bool ObjectIsInSoundBanks() override;
  353. #endif
  354. TArray<FWwiseExternalSourceCookedData> GetAllExternalSources() const;
  355. private:
  356. void LoadEventData();
  357. void UnloadEventData(bool bAsync);
  358. FWwiseLoadedEvent LoadedEvent;
  359. };