ActorFactoryAkAmbientSound.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /*=============================================================================
  16. ActorFactoryAkAmbientSound.cpp:
  17. =============================================================================*/
  18. #include "Factories/ActorFactoryAkAmbientSound.h"
  19. #include "AkAmbientSound.h"
  20. #include "AkAudioEvent.h"
  21. #include "AkComponent.h"
  22. #include "AssetRegistry/AssetData.h"
  23. #include "Editor/EditorEngine.h"
  24. #define LOCTEXT_NAMESPACE "ActorFactoryAkAmbientSound"
  25. /*-----------------------------------------------------------------------------
  26. UActorFactoryAkAmbientSound
  27. -----------------------------------------------------------------------------*/
  28. UActorFactoryAkAmbientSound::UActorFactoryAkAmbientSound(const class FObjectInitializer& ObjectInitializer)
  29. : Super(ObjectInitializer)
  30. {
  31. // Property initialization
  32. DisplayName = LOCTEXT("AkAmbientSoundName", "AkAmbientSound");
  33. NewActorClass = AAkAmbientSound::StaticClass();
  34. bShowInEditorQuickMenu = true;
  35. }
  36. bool UActorFactoryAkAmbientSound::CanCreateActorFrom( const FAssetData& AssetData, FText& OutErrorMsg )
  37. {
  38. //We allow creating AAmbientSounds without an existing sound asset
  39. if ( UActorFactory::CanCreateActorFrom( AssetData, OutErrorMsg ) )
  40. {
  41. return true;
  42. }
  43. if ( AssetData.IsValid() && !AssetData.GetClass()->IsChildOf( UAkAudioEvent::StaticClass() ) )
  44. {
  45. OutErrorMsg = NSLOCTEXT("CanCreateActor", "NoSoundAsset", "A valid sound asset must be specified.");
  46. return false;
  47. }
  48. return true;
  49. }
  50. void UActorFactoryAkAmbientSound::PostSpawnActor( UObject* Asset, AActor* NewActor )
  51. {
  52. UAkAudioEvent* AmbientSound = Cast<UAkAudioEvent>( Asset );
  53. if ( AmbientSound != NULL )
  54. {
  55. AAkAmbientSound* NewSound = CastChecked<AAkAmbientSound>( NewActor );
  56. FActorLabelUtilities::SetActorLabelUnique(NewSound, AmbientSound->EventInfo.WwiseName.ToString());
  57. NewSound->AkComponent->AkAudioEvent = AmbientSound;
  58. if (AmbientSound->bAutoLoad)
  59. {
  60. AmbientSound->LoadData();
  61. }
  62. }
  63. }
  64. UObject* UActorFactoryAkAmbientSound::GetAssetFromActorInstance(AActor* Instance)
  65. {
  66. check(Instance->IsA(NewActorClass));
  67. AAkAmbientSound* SoundActor = CastChecked<AAkAmbientSound>(Instance);
  68. check(SoundActor->AkComponent->AkAudioEvent);
  69. return SoundActor->AkComponent->AkAudioEvent;
  70. }
  71. void UActorFactoryAkAmbientSound::PostCreateBlueprint( UObject* Asset, AActor* CDO )
  72. {
  73. UAkAudioEvent* AmbientSound = Cast<UAkAudioEvent>( Asset );
  74. if ( AmbientSound != NULL )
  75. {
  76. AAkAmbientSound* NewSound = CastChecked<AAkAmbientSound>( CDO );
  77. NewSound->AkComponent->AkAudioEvent = AmbientSound;
  78. AmbientSound->LoadData();
  79. }
  80. }
  81. #undef LOCTEXT_NAMESPACE