mirror of
https://github.com/appen-isen/jeu-sans-image.git
synced 2026-03-18 21:50:42 +01:00
44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LoopablePlaylist : ILoopableSound
|
|
{
|
|
[SerializeField] List<AudioClip> playlist;
|
|
Coroutine playlistCoroutine = null;
|
|
|
|
public override void PlayLoopableSound()
|
|
{
|
|
base.PlayLoopableSound();
|
|
|
|
if (playlist.Count == 0)
|
|
{
|
|
Debug.LogWarning("Playlist is empty");
|
|
return;
|
|
}
|
|
source.loop = false;
|
|
playlistCoroutine = StartCoroutine(PlaylistCoroutine());
|
|
source.clip = playlist[0];
|
|
source.Play();
|
|
}
|
|
|
|
public override void StopLoopableSound()
|
|
{
|
|
StopCoroutine(playlistCoroutine);
|
|
source.Stop();
|
|
base.StopLoopableSound();
|
|
}
|
|
|
|
protected IEnumerator PlaylistCoroutine()
|
|
{
|
|
int playlistIndex = 0;
|
|
while (true)
|
|
{
|
|
source.clip = playlist[playlistIndex];
|
|
source.Play();
|
|
yield return new WaitForSeconds(playlist[playlistIndex].length);
|
|
playlistIndex = (playlistIndex + 1) % playlist.Count;
|
|
}
|
|
}
|
|
}
|