using MoreMountains.Tools; using UnityEngine; #if (MM_TEXTMESHPRO || MM_UGUI2) using TMPro; #endif #if MM_UI namespace MoreMountains.Feel { /// /// A small script used to power the FeelMMSoundManagerPlaylistManager demo scene /// [AddComponentMenu("")] 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; #if (MM_TEXTMESHPRO || MM_UGUI2) /// 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; #endif /// /// 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); #if (MM_TEXTMESHPRO || MM_UGUI2) SongDuration.text = MMTime.FloatToTimeString(PlaylistManager.CurrentTime, false, true, true, false) + " / " + MMTime.FloatToTimeString(PlaylistManager.CurrentClipDuration, false, true, true, false); #endif } } /// /// Updates the song name display /// protected virtual void UpdateSongName() { int displayIndex = PlaylistManager.CurrentSongIndex + 1; #if (MM_TEXTMESHPRO || MM_UGUI2) SongName.text = displayIndex + ". " + PlaylistManager.CurrentSongName; #endif } /// /// 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); } } } #endif