FSoundCueEditor::~FSoundCueEditor() { // Stop any playing sound cues when the cue editor closes UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if (PreviewComp && PreviewComp->IsPlaying()) { Stop(); } GEditor->UnregisterForUndo( this ); }
void FSoundCueEditor::TogglePlayback() { UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if ( PreviewComp && PreviewComp->IsPlaying() ) { Stop(); } else { PlayCue(); } }
void AShooterProjectile::DisableAndDestroy() { UAudioComponent* ProjAudioComp = FindComponentByClass<UAudioComponent>(); if (ProjAudioComp && ProjAudioComp->IsPlaying()) { ProjAudioComp->FadeOut(0.1f, 0.f); } MovementComp->StopMovementImmediately(); // give clients some time to show explosion SetLifeSpan( 2.0f ); }
bool FAssetTypeActions_SoundBase::IsSoundPlaying(TArray<TWeakObjectPtr<USoundBase>> Objects) const { UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if (PreviewComp) { for (TWeakObjectPtr<USoundBase> SoundItem : Objects) { if (PreviewComp->Sound == SoundItem && PreviewComp->IsPlaying()) { return true; } } } return false; }
void FAssetTypeActions_SoundBase::AssetsActivated( const TArray<UObject*>& InObjects, EAssetTypeActivationMethod::Type ActivationType ) { if (ActivationType == EAssetTypeActivationMethod::Previewed) { USoundBase* TargetSound = NULL; for (auto ObjIt = InObjects.CreateConstIterator(); ObjIt; ++ObjIt) { TargetSound = Cast<USoundBase>(*ObjIt); if ( TargetSound ) { // Only target the first valid sound cue break; } } UAudioComponent* PreviewComp = GEditor->GetPreviewAudioComponent(); if ( PreviewComp && PreviewComp->IsPlaying() ) { // Already previewing a sound, if it is the target cue then stop it, otherwise play the new one if ( !TargetSound || PreviewComp->Sound == TargetSound ) { StopSound(); } else { PlaySound(TargetSound); } } else { // Not already playing, play the target sound cue if it exists PlaySound(TargetSound); } } else { FAssetTypeActions_Base::AssetsActivated(InObjects, ActivationType); } }
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; } }
void FSoundCueGraphConnectionDrawingPolicy::BuildAudioFlowRoadmap() { UAudioComponent* PreviewAudioComponent = GEditor->GetPreviewAudioComponent(); FAudioDevice* AudioDevice = PreviewAudioComponent ? PreviewAudioComponent->GetAudioDevice() : nullptr; if (AudioDevice) { USoundCueGraph* SoundCueGraph = CastChecked<USoundCueGraph>(GraphObj); USoundCue* SoundCue = SoundCueGraph->GetSoundCue(); if (PreviewAudioComponent && PreviewAudioComponent->IsPlaying() && PreviewAudioComponent->Sound == SoundCue) { TArray<FWaveInstance*> WaveInstances; const int32 FirstActiveIndex = AudioDevice->GetSortedActiveWaveInstances(WaveInstances, ESortedActiveWaveGetType::QueryOnly); // Run through the active instances and cull out anything that isn't related to this graph if (FirstActiveIndex > 0) { WaveInstances.RemoveAt(0, FirstActiveIndex + 1); } for (int32 WaveIndex = WaveInstances.Num() - 1; WaveIndex >= 0 ; --WaveIndex) { UAudioComponent* WaveInstanceAudioComponent = WaveInstances[WaveIndex]->ActiveSound->AudioComponent.Get(); if (WaveInstanceAudioComponent != PreviewAudioComponent) { WaveInstances.RemoveAtSwap(WaveIndex); } } for (int32 WaveIndex = 0; WaveIndex < WaveInstances.Num(); ++WaveIndex) { TArray<USoundNode*> PathToWaveInstance; if (SoundCue->FindPathToNode(WaveInstances[WaveIndex]->WaveInstanceHash, PathToWaveInstance)) { TArray<USoundCueGraphNode_Root*> RootNode; TArray<UEdGraphNode*> GraphNodes; SoundCueGraph->GetNodesOfClass<USoundCueGraphNode_Root>(RootNode); check(RootNode.Num() == 1); GraphNodes.Add(RootNode[0]); TArray<double> NodeTimes; NodeTimes.Add(FApp::GetCurrentTime()); // Time for the root node for (int32 i = 0; i < PathToWaveInstance.Num(); ++i) { const double ObservationTime = FApp::GetCurrentTime() + 1.f; NodeTimes.Add(ObservationTime); GraphNodes.Add(PathToWaveInstance[i]->GraphNode); } // Record the unique node->node pairings, keeping only the most recent times for each pairing for (int32 i = GraphNodes.Num() - 1; i >= 1; --i) { UEdGraphNode* CurNode = GraphNodes[i]; double CurNodeTime = NodeTimes[i]; UEdGraphNode* NextNode = GraphNodes[i-1]; double NextNodeTime = NodeTimes[i-1]; FExecPairingMap& Predecessors = PredecessorNodes.FindOrAdd(NextNode); // Update the timings if this is a more recent pairing FTimePair& Timings = Predecessors.FindOrAdd(CurNode); if (Timings.ThisExecTime < NextNodeTime) { Timings.PredExecTime = CurNodeTime; Timings.ThisExecTime = NextNodeTime; } } } } } } }