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()
 | 
			
		||||
{
 | 
			
		||||
	if (bInCombat) return;
 | 
			
		||||
	bInCombat = true;
 | 
			
		||||
	StopTracks();
 | 
			
		||||
	AudioTrackQueue.Empty();
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::CombatStart);
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::CombatContinuous);
 | 
			
		||||
	AudioSync();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UCombatAudioAutomation::OutOfCombat()
 | 
			
		||||
{
 | 
			
		||||
	bInCombat = false;
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::StopCombat);
 | 
			
		||||
	StopTracks();
 | 
			
		||||
	if (bBeingInvestigated)
 | 
			
		||||
	{
 | 
			
		||||
		Investigated();
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	if (bInRestrictedArea) InRestrictedArea();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UCombatAudioAutomation::Investigated()
 | 
			
		||||
{
 | 
			
		||||
	if (bBeingInvestigated) return;
 | 
			
		||||
	bBeingInvestigated = true;
 | 
			
		||||
	if (bInCombat) return;
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::Investigated);
 | 
			
		||||
	if (!bInRestrictedArea) return;
 | 
			
		||||
 | 
			
		||||
	StealthTracksAudioComponents[0]->Stop();
 | 
			
		||||
	StealthTracksAudioComponents[1]->Stop();
 | 
			
		||||
	StealthTracksAudioComponents[2]->Stop();
 | 
			
		||||
	InvestigatedTrackAudioComponent->Play();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UCombatAudioAutomation::NotBeingInvestigated()
 | 
			
		||||
{
 | 
			
		||||
	if (bInCombat) return;
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::StopStealth);
 | 
			
		||||
	bBeingInvestigated = false;
 | 
			
		||||
	InvestigatedTrackAudioComponent->Stop();
 | 
			
		||||
	if (bInRestrictedArea) InRestrictedArea();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UCombatAudioAutomation::InRestrictedArea()
 | 
			
		||||
{
 | 
			
		||||
	if (bInCombat) return;
 | 
			
		||||
	if (bInRestrictedArea) return;
 | 
			
		||||
	bInRestrictedArea = true;
 | 
			
		||||
	if (bInCombat) return;
 | 
			
		||||
	if (bBeingInvestigated) return;
 | 
			
		||||
	AudioTrackQueue.Empty();
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::Stealth1);
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::Stealth2);
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::Stealth3);
 | 
			
		||||
	AudioSync();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UCombatAudioAutomation::NotInRestrictedArea()
 | 
			
		||||
{
 | 
			
		||||
	if (bInCombat) return;
 | 
			
		||||
	bInRestrictedArea = false;
 | 
			
		||||
	AudioTrackQueue.Enqueue(EAudioTrack::StopStealth);
 | 
			
		||||
	if (bInCombat) return;
 | 
			
		||||
	StealthTracksAudioComponents[0]->Stop();
 | 
			
		||||
	StealthTracksAudioComponents[1]->Stop();
 | 
			
		||||
	StealthTracksAudioComponents[2]->Stop();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Called when the game starts
 | 
			
		||||
@ -66,24 +90,22 @@ void UCombatAudioAutomation::BeginPlay()
 | 
			
		||||
 | 
			
		||||
	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);
 | 
			
		||||
		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);
 | 
			
		||||
	InvestigatedTrackAudioComponent = AudioComponent;
 | 
			
		||||
 | 
			
		||||
	AudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), CombatStartTrack);
 | 
			
		||||
	AudioComponent = UGameplayStatics::CreateSound2D(GetWorld(), CombatStartTrack, 1.0f, 1.0f, 0.0f, nullptr, false, false);
 | 
			
		||||
	AllAudioComponents.Add(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);
 | 
			
		||||
	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;
 | 
			
		||||
 | 
			
		||||
	EAudioTrack AudioTrack;
 | 
			
		||||
	AudioTrackQueue.Dequeue(AudioTrack);
 | 
			
		||||
	EAudioTrack Track;
 | 
			
		||||
	AudioTrackQueue.Dequeue(Track);
 | 
			
		||||
 | 
			
		||||
	switch (AudioTrack)
 | 
			
		||||
	switch (Track)
 | 
			
		||||
	{
 | 
			
		||||
	case EAudioTrack::Stealth1:
 | 
			
		||||
		StealthTracksAudioComponents[0]->Play();
 | 
			
		||||
@ -105,12 +127,6 @@ void UCombatAudioAutomation::PlayQueued()
 | 
			
		||||
	case EAudioTrack::Stealth3:
 | 
			
		||||
		StealthTracksAudioComponents[2]->Play();
 | 
			
		||||
		break;
 | 
			
		||||
	case EAudioTrack::Investigated:
 | 
			
		||||
		StealthTracksAudioComponents[0]->Stop();
 | 
			
		||||
		StealthTracksAudioComponents[1]->Stop();
 | 
			
		||||
		StealthTracksAudioComponents[2]->Stop();
 | 
			
		||||
		InvestigatedTrackAudioComponent->Play();
 | 
			
		||||
		break;
 | 
			
		||||
	case EAudioTrack::CombatStart:
 | 
			
		||||
		CombatStartTrackAudioComponent->Play();
 | 
			
		||||
		break;
 | 
			
		||||
@ -118,21 +134,6 @@ void UCombatAudioAutomation::PlayQueued()
 | 
			
		||||
		CombatStartTrackAudioComponent->Stop();
 | 
			
		||||
		CombatContinuousTrackAudioComponent->Play();
 | 
			
		||||
		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();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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,
 | 
			
		||||
	Stealth2,
 | 
			
		||||
	Stealth3,
 | 
			
		||||
	Investigated,
 | 
			
		||||
	CombatStart,
 | 
			
		||||
	CombatContinuous,
 | 
			
		||||
	StopStealth,
 | 
			
		||||
	StopInvestigated,
 | 
			
		||||
	StopCombat,
 | 
			
		||||
	CombatContinuous
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
 | 
			
		||||
@ -72,9 +68,11 @@ private:
 | 
			
		||||
 | 
			
		||||
	bool bInCombat = false;
 | 
			
		||||
	bool bInRestrictedArea = false;
 | 
			
		||||
	bool bBeingInvestigated = false;
 | 
			
		||||
 | 
			
		||||
	void StopTracks();
 | 
			
		||||
 | 
			
		||||
	UPROPERTY()
 | 
			
		||||
	FTimerHandle AudioSyncTimer;
 | 
			
		||||
	void AudioSync();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -97,7 +97,7 @@ void AEndlessVendettaCharacter::IncrementBeingInvestigatedCount()
 | 
			
		||||
void AEndlessVendettaCharacter::DecrementBeingInvestigatedCount()
 | 
			
		||||
{
 | 
			
		||||
	BeingInvestigatedCount--;
 | 
			
		||||
	if (BeingInvestigatedCount <= 0)
 | 
			
		||||
	if (BeingInvestigatedCount <= 0 && bIsBeingInvestigated)
 | 
			
		||||
	{
 | 
			
		||||
		bIsBeingInvestigated = false;
 | 
			
		||||
		Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->NotBeingInvestigated();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user