using System.Collections; using System.Collections.Generic; using MoreMountains.Tools; using TMPro; using UnityEngine; namespace MoreMountains.Feel { /// /// A small script used to power the FeelMMSoundManagerPlaylistManager demo scene /// public class PlaylistDemo : MonoBehaviour { /// the playlist manager to read data on public MMSMPlaylistManager PlaylistManager; /// a progress bar meant to display the progress of the song currently playing public MMProgressBar ProgressBar; /// the name of the song currently playing public TMP_Text SongName; /// a text displaying the current progress of the song in minutes/seconds public TMP_Text SongDuration; /// /// On Update, updates the progress bar and song duration counter /// protected virtual void Update() { if (PlaylistManager.CurrentClipDuration == 0f) { ProgressBar.SetBar(0f, 0f, 1f); } else { ProgressBar.SetBar(PlaylistManager.CurrentTime, 0f, PlaylistManager.CurrentClipDuration); SongDuration.text = MMTime.FloatToTimeString(PlaylistManager.CurrentTime, false, true, true, false) + " / " + MMTime.FloatToTimeString(PlaylistManager.CurrentClipDuration, false, true, true, false); } } /// /// Updates the song name display /// protected virtual void UpdateSongName() { int displayIndex = PlaylistManager.CurrentSongIndex + 1; SongName.text = displayIndex + ". " + PlaylistManager.CurrentSongName; } /// /// When a new song starts to play, we update its name /// /// protected virtual void OnPlayEvent(int channel) { UpdateSongName(); } /// /// Starts listening for events /// protected virtual void OnEnable() { MMPlaylistNewSongStartedEvent.Register(OnPlayEvent); } /// /// Stops listening for events /// protected virtual void OnDisable() { MMPlaylistNewSongStartedEvent.Unregister(OnPlayEvent); } } }