Update Music System to Be Responsive
This commit is contained in:
		
							parent
							
								
									10938d7b8d
								
							
						
					
					
						commit
						75fc2e0aca
					
				
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Combat_start__808s_.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Combat_start__808s_.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Drums.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Drums.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Guitar.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Guitar.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Hats_and_clap.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Hats_and_clap.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Sound_effect.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/Sound_effect.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/combat_Continuous.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/Audio/Music/Combat_track_1/combat_Continuous.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/FirstPerson/Blueprints/BP_MainCharacter.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/FirstPerson/Blueprints/BP_MainCharacter.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							@ -20,43 +20,67 @@ UCombatAudioAutomation::UCombatAudioAutomation()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void UCombatAudioAutomation::InCombat()
 | 
					void UCombatAudioAutomation::InCombat()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (bInCombat) return;
 | 
				
			||||||
	bInCombat = true;
 | 
						bInCombat = true;
 | 
				
			||||||
 | 
						StopTracks();
 | 
				
			||||||
 | 
						AudioTrackQueue.Empty();
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::CombatStart);
 | 
						AudioTrackQueue.Enqueue(EAudioTrack::CombatStart);
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::CombatContinuous);
 | 
						AudioTrackQueue.Enqueue(EAudioTrack::CombatContinuous);
 | 
				
			||||||
 | 
						AudioSync();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UCombatAudioAutomation::OutOfCombat()
 | 
					void UCombatAudioAutomation::OutOfCombat()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	bInCombat = false;
 | 
						bInCombat = false;
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::StopCombat);
 | 
						StopTracks();
 | 
				
			||||||
 | 
						if (bBeingInvestigated)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							Investigated();
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (bInRestrictedArea) InRestrictedArea();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UCombatAudioAutomation::Investigated()
 | 
					void UCombatAudioAutomation::Investigated()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (bBeingInvestigated) return;
 | 
				
			||||||
 | 
						bBeingInvestigated = true;
 | 
				
			||||||
	if (bInCombat) return;
 | 
						if (bInCombat) return;
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::Investigated);
 | 
						if (!bInRestrictedArea) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						StealthTracksAudioComponents[0]->Stop();
 | 
				
			||||||
 | 
						StealthTracksAudioComponents[1]->Stop();
 | 
				
			||||||
 | 
						StealthTracksAudioComponents[2]->Stop();
 | 
				
			||||||
 | 
						InvestigatedTrackAudioComponent->Play();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UCombatAudioAutomation::NotBeingInvestigated()
 | 
					void UCombatAudioAutomation::NotBeingInvestigated()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (bInCombat) return;
 | 
						bBeingInvestigated = false;
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::StopStealth);
 | 
						InvestigatedTrackAudioComponent->Stop();
 | 
				
			||||||
 | 
						if (bInRestrictedArea) InRestrictedArea();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UCombatAudioAutomation::InRestrictedArea()
 | 
					void UCombatAudioAutomation::InRestrictedArea()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (bInCombat) return;
 | 
						if (bInRestrictedArea) return;
 | 
				
			||||||
	bInRestrictedArea = true;
 | 
						bInRestrictedArea = true;
 | 
				
			||||||
 | 
						if (bInCombat) return;
 | 
				
			||||||
 | 
						if (bBeingInvestigated) return;
 | 
				
			||||||
 | 
						AudioTrackQueue.Empty();
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::Stealth1);
 | 
						AudioTrackQueue.Enqueue(EAudioTrack::Stealth1);
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::Stealth2);
 | 
						AudioTrackQueue.Enqueue(EAudioTrack::Stealth2);
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::Stealth3);
 | 
						AudioTrackQueue.Enqueue(EAudioTrack::Stealth3);
 | 
				
			||||||
 | 
						AudioSync();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UCombatAudioAutomation::NotInRestrictedArea()
 | 
					void UCombatAudioAutomation::NotInRestrictedArea()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (bInCombat) return;
 | 
					 | 
				
			||||||
	bInRestrictedArea = false;
 | 
						bInRestrictedArea = false;
 | 
				
			||||||
	AudioTrackQueue.Enqueue(EAudioTrack::StopStealth);
 | 
						if (bInCombat) return;
 | 
				
			||||||
 | 
						StealthTracksAudioComponents[0]->Stop();
 | 
				
			||||||
 | 
						StealthTracksAudioComponents[1]->Stop();
 | 
				
			||||||
 | 
						StealthTracksAudioComponents[2]->Stop();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Called when the game starts
 | 
					// Called when the game starts
 | 
				
			||||||
@ -66,24 +90,22 @@ void UCombatAudioAutomation::BeginPlay()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	for (USoundBase* Track : StealthTracks)
 | 
						for (USoundBase* Track : StealthTracks)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		UAudioComponent* AudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), Track);
 | 
							UAudioComponent* AudioComponent = UGameplayStatics::CreateSound2D(GetWorld(), Track, 1.0f, 1.0f, 0.0f, nullptr, false, false);
 | 
				
			||||||
		AllAudioComponents.Add(AudioComponent);
 | 
							AllAudioComponents.Add(AudioComponent);
 | 
				
			||||||
		StealthTracksAudioComponents.Add(AudioComponent);
 | 
							StealthTracksAudioComponents.Add(AudioComponent);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UAudioComponent* AudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), InvestigatedTrack);
 | 
						UAudioComponent* AudioComponent = UGameplayStatics::CreateSound2D(GetWorld(), InvestigatedTrack, 1.0f, 1.0f, 0.0f, nullptr, false, false);
 | 
				
			||||||
	AllAudioComponents.Add(AudioComponent);
 | 
						AllAudioComponents.Add(AudioComponent);
 | 
				
			||||||
	InvestigatedTrackAudioComponent = AudioComponent;
 | 
						InvestigatedTrackAudioComponent = AudioComponent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), CombatStartTrack);
 | 
						AudioComponent = UGameplayStatics::CreateSound2D(GetWorld(), CombatStartTrack, 1.0f, 1.0f, 0.0f, nullptr, false, false);
 | 
				
			||||||
	AllAudioComponents.Add(AudioComponent);
 | 
						AllAudioComponents.Add(AudioComponent);
 | 
				
			||||||
	CombatStartTrackAudioComponent = AudioComponent;
 | 
						CombatStartTrackAudioComponent = AudioComponent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), CombatContinuousTrack);
 | 
						AudioComponent = UGameplayStatics::CreateSound2D(GetWorld(), CombatContinuousTrack, 1.0f, 1.0f, 0.0f, nullptr, false, false);
 | 
				
			||||||
	AllAudioComponents.Add(AudioComponent);
 | 
						AllAudioComponents.Add(AudioComponent);
 | 
				
			||||||
	CombatContinuousTrackAudioComponent = AudioComponent;
 | 
						CombatContinuousTrackAudioComponent = AudioComponent;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	GetWorld()->GetTimerManager().SetTimer(AudioSyncTimer, this, &UCombatAudioAutomation::PlayQueued, 5.33333f, true, 1.0f);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -91,10 +113,10 @@ void UCombatAudioAutomation::PlayQueued()
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	if (AudioTrackQueue.IsEmpty()) return;
 | 
						if (AudioTrackQueue.IsEmpty()) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	EAudioTrack AudioTrack;
 | 
						EAudioTrack Track;
 | 
				
			||||||
	AudioTrackQueue.Dequeue(AudioTrack);
 | 
						AudioTrackQueue.Dequeue(Track);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (AudioTrack)
 | 
						switch (Track)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	case EAudioTrack::Stealth1:
 | 
						case EAudioTrack::Stealth1:
 | 
				
			||||||
		StealthTracksAudioComponents[0]->Play();
 | 
							StealthTracksAudioComponents[0]->Play();
 | 
				
			||||||
@ -105,12 +127,6 @@ void UCombatAudioAutomation::PlayQueued()
 | 
				
			|||||||
	case EAudioTrack::Stealth3:
 | 
						case EAudioTrack::Stealth3:
 | 
				
			||||||
		StealthTracksAudioComponents[2]->Play();
 | 
							StealthTracksAudioComponents[2]->Play();
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case EAudioTrack::Investigated:
 | 
					 | 
				
			||||||
		StealthTracksAudioComponents[0]->Stop();
 | 
					 | 
				
			||||||
		StealthTracksAudioComponents[1]->Stop();
 | 
					 | 
				
			||||||
		StealthTracksAudioComponents[2]->Stop();
 | 
					 | 
				
			||||||
		InvestigatedTrackAudioComponent->Play();
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case EAudioTrack::CombatStart:
 | 
						case EAudioTrack::CombatStart:
 | 
				
			||||||
		CombatStartTrackAudioComponent->Play();
 | 
							CombatStartTrackAudioComponent->Play();
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
@ -118,21 +134,6 @@ void UCombatAudioAutomation::PlayQueued()
 | 
				
			|||||||
		CombatStartTrackAudioComponent->Stop();
 | 
							CombatStartTrackAudioComponent->Stop();
 | 
				
			||||||
		CombatContinuousTrackAudioComponent->Play();
 | 
							CombatContinuousTrackAudioComponent->Play();
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case EAudioTrack::StopStealth:
 | 
					 | 
				
			||||||
		for (UAudioComponent* AudioComponent : StealthTracksAudioComponents)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			AudioComponent->Stop();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case EAudioTrack::StopInvestigated:
 | 
					 | 
				
			||||||
		InvestigatedTrackAudioComponent->Stop();
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case EAudioTrack::StopCombat:
 | 
					 | 
				
			||||||
		CombatStartTrackAudioComponent->Stop();
 | 
					 | 
				
			||||||
		CombatContinuousTrackAudioComponent->Stop();
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -150,3 +151,12 @@ void UCombatAudioAutomation::StopTracks()
 | 
				
			|||||||
		AudioComponent->Stop();
 | 
							AudioComponent->Stop();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void UCombatAudioAutomation::AudioSync()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (GetWorld()->GetTimerManager().IsTimerActive(AudioSyncTimer))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							GetWorld()->GetTimerManager().ClearTimer(AudioSyncTimer);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						GetWorld()->GetTimerManager().SetTimer(AudioSyncTimer, this, &UCombatAudioAutomation::PlayQueued, 5.33333f, true, 0.2f);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -12,12 +12,8 @@ enum class EAudioTrack : uint8
 | 
				
			|||||||
	Stealth1,
 | 
						Stealth1,
 | 
				
			||||||
	Stealth2,
 | 
						Stealth2,
 | 
				
			||||||
	Stealth3,
 | 
						Stealth3,
 | 
				
			||||||
	Investigated,
 | 
					 | 
				
			||||||
	CombatStart,
 | 
						CombatStart,
 | 
				
			||||||
	CombatContinuous,
 | 
						CombatContinuous
 | 
				
			||||||
	StopStealth,
 | 
					 | 
				
			||||||
	StopInvestigated,
 | 
					 | 
				
			||||||
	StopCombat,
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
 | 
					UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
 | 
				
			||||||
@ -72,9 +68,11 @@ private:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	bool bInCombat = false;
 | 
						bool bInCombat = false;
 | 
				
			||||||
	bool bInRestrictedArea = false;
 | 
						bool bInRestrictedArea = false;
 | 
				
			||||||
 | 
						bool bBeingInvestigated = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void StopTracks();
 | 
						void StopTracks();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UPROPERTY()
 | 
						UPROPERTY()
 | 
				
			||||||
	FTimerHandle AudioSyncTimer;
 | 
						FTimerHandle AudioSyncTimer;
 | 
				
			||||||
 | 
						void AudioSync();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -97,7 +97,7 @@ void AEndlessVendettaCharacter::IncrementBeingInvestigatedCount()
 | 
				
			|||||||
void AEndlessVendettaCharacter::DecrementBeingInvestigatedCount()
 | 
					void AEndlessVendettaCharacter::DecrementBeingInvestigatedCount()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	BeingInvestigatedCount--;
 | 
						BeingInvestigatedCount--;
 | 
				
			||||||
	if (BeingInvestigatedCount <= 0)
 | 
						if (BeingInvestigatedCount <= 0 && bIsBeingInvestigated)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		bIsBeingInvestigated = false;
 | 
							bIsBeingInvestigated = false;
 | 
				
			||||||
		Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->NotBeingInvestigated();
 | 
							Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->NotBeingInvestigated();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user