You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
5.0 KiB
168 lines
5.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
public class MusicManager : MonoBehaviour
|
|
{
|
|
public enum Track
|
|
{
|
|
None,
|
|
Cozy,
|
|
CozyPlusTrash,
|
|
Building,
|
|
TurnAround,
|
|
TurnAroundPlusJeremyLives,
|
|
FinaleBuildUp,
|
|
}
|
|
|
|
private Track currentTrack = Track.None;
|
|
private List<AudioSource> currentlyPlaying = new();
|
|
|
|
[SerializeField]
|
|
private AudioSource _CozySource;
|
|
|
|
[FormerlySerializedAs("_TrashSource")]
|
|
[SerializeField]
|
|
private AudioSource _AdditiveTrashSource;
|
|
|
|
[FormerlySerializedAs("_AdditiveBuildingSource")]
|
|
[SerializeField]
|
|
private AudioSource _BuildingSource;
|
|
|
|
[SerializeField]
|
|
private AudioSource _TurnAroundSource;
|
|
|
|
[SerializeField]
|
|
private AudioSource _AdditiveJeremyLivesSource;
|
|
|
|
[SerializeField]
|
|
private AudioSource _FinaleBuildUpSource;
|
|
|
|
public void PlayMusicCozy()
|
|
{
|
|
currentTrack = Track.Cozy;
|
|
}
|
|
|
|
public void PlayMusicCozyPlusTrash()
|
|
{
|
|
currentTrack = Track.CozyPlusTrash;
|
|
}
|
|
|
|
public void PlayMusicBuilding()
|
|
{
|
|
currentTrack = Track.Building;
|
|
}
|
|
|
|
public void PlayMusicTurnAround()
|
|
{
|
|
currentTrack = Track.TurnAround;
|
|
}
|
|
|
|
public void PlayMusicTurnAroundPlusJeremyLives()
|
|
{
|
|
currentTrack = Track.TurnAroundPlusJeremyLives;
|
|
}
|
|
|
|
public void PlayMusicFinaleBuildUp()
|
|
{
|
|
currentTrack = Track.FinaleBuildUp;
|
|
}
|
|
|
|
|
|
public void PlayMusic(Track track)
|
|
{
|
|
currentTrack = track;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var fadeMultiplier = 0.2f;
|
|
|
|
if (currentTrack is Track.CozyPlusTrash or Track.Cozy)
|
|
{
|
|
if (!_AdditiveTrashSource.isPlaying)
|
|
_AdditiveTrashSource.Play();
|
|
|
|
if(!_CozySource.isPlaying)
|
|
_CozySource.Play();
|
|
}
|
|
else
|
|
{
|
|
if (_AdditiveTrashSource.volume == 0 && _AdditiveTrashSource.isPlaying)
|
|
_AdditiveTrashSource.Stop();
|
|
|
|
if (_CozySource.volume == 0 && _CozySource.isPlaying)
|
|
_CozySource.Stop();
|
|
}
|
|
|
|
_AdditiveTrashSource.volume = currentTrack == Track.CozyPlusTrash ?
|
|
Mathf.Clamp(_AdditiveTrashSource.volume + (fadeMultiplier * Time.deltaTime), 0, 1) :
|
|
Mathf.Clamp(_AdditiveTrashSource.volume - (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
|
|
_CozySource.volume = currentTrack is Track.CozyPlusTrash or Track.Cozy ?
|
|
Mathf.Clamp(_CozySource.volume + (fadeMultiplier * Time.deltaTime), 0, 1) :
|
|
Mathf.Clamp(_CozySource.volume - (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
|
|
|
|
if(currentTrack == Track.Building)
|
|
{
|
|
if (!_BuildingSource.isPlaying)
|
|
_BuildingSource.Play();
|
|
|
|
_BuildingSource.volume = Mathf.Clamp(_BuildingSource.volume + (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
}
|
|
else
|
|
{
|
|
_BuildingSource.volume = Mathf.Clamp(_BuildingSource.volume - (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
if (_BuildingSource.volume == 0 && _BuildingSource.isPlaying)
|
|
_BuildingSource.Stop();
|
|
}
|
|
|
|
|
|
if (currentTrack == Track.TurnAround)
|
|
{
|
|
if (!_TurnAroundSource.isPlaying)
|
|
_TurnAroundSource.Play();
|
|
|
|
_TurnAroundSource.volume = Mathf.Clamp(_TurnAroundSource.volume + (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
}
|
|
else
|
|
{
|
|
_TurnAroundSource.volume = Mathf.Clamp(_TurnAroundSource.volume - (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
if (_TurnAroundSource.volume == 0 && _TurnAroundSource.isPlaying)
|
|
_TurnAroundSource.Stop();
|
|
}
|
|
|
|
if(currentTrack == Track.TurnAroundPlusJeremyLives)
|
|
{
|
|
if (!_AdditiveJeremyLivesSource.isPlaying)
|
|
_AdditiveJeremyLivesSource.Play();
|
|
|
|
_AdditiveJeremyLivesSource.volume = Mathf.Clamp(_AdditiveJeremyLivesSource.volume + (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
}
|
|
else
|
|
{
|
|
_AdditiveJeremyLivesSource.volume = Mathf.Clamp(_AdditiveJeremyLivesSource.volume - (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
if (_AdditiveJeremyLivesSource.volume == 0 && _AdditiveJeremyLivesSource.isPlaying)
|
|
_AdditiveJeremyLivesSource.Stop();
|
|
}
|
|
|
|
|
|
if(currentTrack == Track.FinaleBuildUp)
|
|
{
|
|
if (!_FinaleBuildUpSource.isPlaying)
|
|
_FinaleBuildUpSource.Play();
|
|
|
|
_FinaleBuildUpSource.volume = Mathf.Clamp(_FinaleBuildUpSource.volume + (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
}
|
|
else
|
|
{
|
|
_FinaleBuildUpSource.volume = Mathf.Clamp(_FinaleBuildUpSource.volume - (fadeMultiplier * Time.deltaTime), 0, 1);
|
|
if (_FinaleBuildUpSource.volume == 0 && _FinaleBuildUpSource.isPlaying)
|
|
_FinaleBuildUpSource.Stop();
|
|
}
|
|
|
|
}
|
|
}
|