Skip to content

Commit

Permalink
fix(bgm-test): change name object and set default volume
Browse files Browse the repository at this point in the history
  • Loading branch information
Long18 committed Jan 30, 2024
1 parent af7ba59 commit 9e12191
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Assets/Prefabs/Audio/SoundEmitter.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ AudioSource:
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Volume: 0
m_Pitch: 1
Loop: 0
Mute: 0
Expand Down
5 changes: 2 additions & 3 deletions Assets/Scripts/System/Audio/Emitters/AudioEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Long18.System.Audio.Emitters
public class AudioEmitter : MonoBehaviour
{
public event UnityAction<AudioEmitterValue> OnFinishedPlaying;
private const float DEFAULT_VOLUME = 3f;
private const float FADE_VOLUME_DURATION = 2f;
private const float DEFAULT_VOLUME = 1f;
private const float FADE_VOLUME_DURATION = 3f;

[SerializeField] private AudioSource _audioSource;

Expand All @@ -23,7 +23,6 @@ public void PlayAudioClip(AudioClip clip, bool hasLoop)

_audioSource.clip = clip;
// TODO: Create volume config
_audioSource.volume = DEFAULT_VOLUME;
_audioSource.loop = hasLoop;
_audioSource.time = 0f;
_audioSource.Play();
Expand Down
48 changes: 17 additions & 31 deletions Assets/Test/RunTime/Audio/AudioEmitterPoolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ namespace Long18.Test.RunTime.Audio
public class AudioEmitterPoolTest
{
private const string AUDIO_TEST_SCENE_PATH = "Assets/Scenes/WIP/AudioTestScene.unity";
private const string MUSIC_EVENT_CHANNEL_PATH = "Assets/Events/Audio/PlayMusicChannel.asset";
private const string BGM_EVENT_CHANNEL_PATH = "Assets/Events/Audio/PlayBGMChannel.asset";

private const float TIME_TO_WAIT = 5.01f;

private PlayBgmOnSceneStart _objectTriggerBgm;
private List<BgmCueSO> _bgmCue;
private AudioCueEventChannelSO _musicEvent;
private AudioCueEventChannelSO _bgmEvent;

[UnitySetUp]
public IEnumerator OneTimeSetup()
Expand All @@ -39,55 +40,40 @@ public IEnumerator OneTimeSetup()
_bgmCue.Add(audio);
}

_musicEvent = AssetDatabase.LoadAssetAtPath<AudioCueEventChannelSO>(MUSIC_EVENT_CHANNEL_PATH);
_bgmEvent = AssetDatabase.LoadAssetAtPath<AudioCueEventChannelSO>(BGM_EVENT_CHANNEL_PATH);

Assert.NotNull(_musicEvent, $"Event not null");
Assert.NotNull(_bgmEvent, $"Event bgm not null");

yield return EditorSceneManager.LoadSceneInPlayMode(AUDIO_TEST_SCENE_PATH,
new LoadSceneParameters(LoadSceneMode.Single));

AudioManager audioManager = Object.FindObjectOfType<AudioManager>();

Assert.NotNull(audioManager, $"Object {audioManager.name} is not null");

_objectTriggerBgm = Object.FindObjectOfType<PlayBgmOnSceneStart>();
_objectTriggerBgm.gameObject.SetActive(false);
}

[UnityTest]
public IEnumerator PlayBGM_ShouldPlayAudio_ReturnFalseIfFirstIsDeactivated()
{
_musicEvent.PlayAudio(_bgmCue[0]);

var time = 0f;
while (true)
{
time += Time.deltaTime;

if (time >= TIME_TO_WAIT)
{
_musicEvent.PlayAudio(_bgmCue[1]);
break;
}
_objectTriggerBgm.gameObject.SetActive(true);

yield return null;
}
_bgmEvent.PlayAudio(_bgmCue[0]);

time = 0f;
yield return new WaitForSeconds(TIME_TO_WAIT);

while (true)
{
time += Time.deltaTime;
if (time >= TIME_TO_WAIT)
_bgmEvent.PlayAudio(_bgmCue[1]);

{
AudioEmitter[] emitters = Object.FindObjectsOfType<AudioEmitter>();
yield return new WaitForSeconds(TIME_TO_WAIT);

bool isAnyDeactivated = emitters.Any(emitter => !emitter.gameObject.activeSelf);
AudioEmitter[] emitters = Object.FindObjectsOfType<AudioEmitter>();

Assert.IsFalse(isAnyDeactivated, "At least one AudioEmitter should be deactivated");
break;
}
bool isAnyDeactivated = emitters.Any(emitter => !emitter.gameObject.activeSelf);

yield return null;
}
Assert.IsFalse(isAnyDeactivated, "At least one AudioEmitter should be deactivated");
}

}
}

0 comments on commit 9e12191

Please sign in to comment.