123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #include "AkAmbientSound.h"
- #include "AkAudioDevice.h"
- #include "AkComponent.h"
- #include "AkAudioEvent.h"
- #include "Wwise/WwiseExternalSourceManager.h"
- AAkAmbientSound::AAkAmbientSound(const class FObjectInitializer& ObjectInitializer) :
- Super(ObjectInitializer)
- {
-
- StopWhenOwnerIsDestroyed = true;
- CurrentlyPlaying = false;
-
- static const FName ComponentName = TEXT("AkAudioComponent0");
- AkComponent = ObjectInitializer.CreateDefaultSubobject<UAkComponent>(this, ComponentName);
-
- AkComponent->StopWhenOwnerDestroyed = StopWhenOwnerIsDestroyed;
- RootComponent = AkComponent;
- AkComponent->AttenuationScalingFactor = 1.f;
-
- SetHidden(true);
- AutoPost = false;
- }
- void AAkAmbientSound::PostLoad()
- {
- Super::PostLoad();
- #if WITH_EDITOR
- if( AkAudioEvent_DEPRECATED )
- {
- AkComponent->AkAudioEvent = AkAudioEvent_DEPRECATED;
- }
- #endif
- }
- void AAkAmbientSound::PostInitializeComponents()
- {
- Super::PostInitializeComponents();
- AkComponent->UpdateAkLateReverbComponentList(AkComponent->GetComponentLocation());
- }
- void AAkAmbientSound::BeginPlay()
- {
- Super::BeginPlay();
- if (AutoPost)
- {
- StartAmbientSound();
- }
- }
- #if WITH_EDITOR
- void AAkAmbientSound::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
- {
- if( AkComponent )
- {
-
- if( IsCurrentlyPlaying() )
- {
- StartPlaying();
- }
- }
- Super::PostEditChangeProperty(PropertyChangedEvent);
- }
- #endif
- void AAkAmbientSound::StartAmbientSound()
- {
- StartPlaying();
- }
- void AAkAmbientSound::StopAmbientSound()
- {
- StopPlaying();
- }
- void AAkAmbientSound::StartPlaying()
- {
- if( !IsCurrentlyPlaying() )
- {
- if (AkComponent->AkAudioEvent)
- {
- AkComponent->AkAudioEvent->PostOnActor(this, nullptr, nullptr, nullptr, (AkCallbackType)0, nullptr, StopWhenOwnerIsDestroyed);
- return;
- }
- FAkAudioDevice* AkAudioDevice = FAkAudioDevice::Get();
- if (AkAudioDevice)
- {
- AkAudioDevice->SetAttenuationScalingFactor(this, AkComponent->AttenuationScalingFactor);
- AkPlayingID pID = AkAudioDevice->PostEventOnActor(AkAudioDevice->GetShortID(AkComponent->AkAudioEvent, AkComponent->EventName), this, 0, NULL, NULL, StopWhenOwnerIsDestroyed, {});
- }
- }
- }
- void AAkAmbientSound::StopPlaying()
- {
- if( IsCurrentlyPlaying() )
- {
-
- AkComponent->Stop();
- }
- }
- bool AAkAmbientSound::IsCurrentlyPlaying()
- {
- return AkComponent != nullptr && AkComponent->HasActiveEvents();
- }
|