void USoundEffectManager::PlaySoundEffect(ESoundEffects SFX_To_Play) { UAudioComponent* Audio = NewObject<UAudioComponent>(this); Audio->RegisterComponent(); Audio->OnAudioFinished.Add(AudioFinishDelegate); USoundWave* SoundEffect = EnumToSoundEffect(SFX_To_Play); Audio->Sound = SoundEffect; Audio->Play(); SoundEffectComponents.Add(Audio); }
void USoundEffectManager::PlaySoundEffect_3D(ESoundEffects SFX_To_Play) { UAudioComponent* Audio = NewObject<UAudioComponent>(this); Audio->RegisterComponent(); Audio->AttachTo(GetOwner()->GetRootComponent(),"",EAttachLocation::SnapToTarget,true); Audio->OnAudioFinished.Add(AudioFinishDelegate); USoundWave* SoundEffect = EnumToSoundEffect(SFX_To_Play); Audio->bAllowSpatialization = true; Audio->bOverrideAttenuation = true; Audio->AttenuationOverrides.OmniRadius = 100.f; Audio->AttenuationOverrides.FalloffDistance = 3000.f; Audio->Sound = SoundEffect; Audio->Play(); SoundEffectComponents.Add(Audio); }
void USoundEffectManager::PlaySoundEffect_3D_AtLocation(ESoundEffects SFX_To_Play, FVector Location) { FActorSpawnParameters spawnParams; spawnParams.Owner = GetOwner(); spawnParams.Instigator = GetOwner()->Instigator; AActor* SpawnedObject; SpawnedObject = GetWorld()->SpawnActor<AActor>(SoundPlayer3D, Location, FRotator(0), spawnParams); UAudioComponent* Audio = SpawnedObject->FindComponentByClass<class UAudioComponent>(); Audio->OnAudioFinished.Add(AudioFinishDelegate); USoundWave* SoundEffect = EnumToSoundEffect(SFX_To_Play); Audio->bAllowSpatialization = true; Audio->bOverrideAttenuation = true; Audio->AttenuationOverrides.OmniRadius = 100.f; Audio->AttenuationOverrides.FalloffDistance = 3000.f; Audio->Sound = SoundEffect; Audio->Play(); SoundEffectComponents.Add(Audio); }
void ASafeInteract::Tick(float DeltaTime) { APlayerController* c = GetWorld()->GetFirstPlayerController(); if (!c) return; ACharacterHUD* h = Cast<ACharacterHUD>(c->GetHUD()); if (!h) return; if (EnteringCombination) { if ((this->GetActorLocation() - CharacterReference->GetActorLocation()).Size() > 400.0f) { EnteringCombination = false; Fade = -1.0; } h->DrawSafeString = true; FString string = TestCombination; if (CombinationLength < COMBINATION_LENGTH) { string += "_"; for (int i = 0; i < (COMBINATION_LENGTH - CombinationLength) - 1; i++) { string += " "; } } h->SafeString = string; if (CheckInput()) { UAudioComponent* SpeakerAudio = SafeSpeaker->GetAudioComponent(); UAudioComponent* SpeakerAudio2 = SafeUnlockSpeaker->GetAudioComponent(); if (EnterCombination()) { EnteringCombination = false; h->DrawSafeString = false; h->SafeString = ""; SpeakerAudio2->Play(); IsLocked = false; UnlockSafe(); Fade = -1.0; } else { if (!SpeakerAudio->IsPlaying()) SpeakerAudio->Play(); } } } else { h->DrawSafeString = false; h->SafeString = ""; } if (Fade != 0) { h->BlackBackgroundAlpha = FMath::Clamp(h->BlackBackgroundAlpha + (200 * DeltaTime * Fade), 0.0f, 150.0f); if (h->BlackBackgroundAlpha == 0.0f || h->BlackBackgroundAlpha == 150) Fade = 0; } }