架构大更
This commit is contained in:
@@ -3,81 +3,84 @@ using UnityEngine;
|
||||
#if MM_UGUI2
|
||||
using TMPro;
|
||||
#endif
|
||||
|
||||
#if MM_UI
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
/// <summary>
|
||||
/// A small script used to power the FeelMMSoundManagerPlaylistManager demo scene
|
||||
/// A small script used to power the FeelMMSoundManagerPlaylistManager demo scene
|
||||
/// </summary>
|
||||
[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_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
|
||||
public class PlaylistDemo : MonoBehaviour
|
||||
{
|
||||
/// the playlist manager to read data on
|
||||
public MMSMPlaylistManager PlaylistManager;
|
||||
|
||||
/// <summary>
|
||||
/// On Update, updates the progress bar and song duration counter
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (PlaylistManager.CurrentClipDuration == 0f)
|
||||
{
|
||||
ProgressBar.SetBar(0f, 0f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgressBar.SetBar(PlaylistManager.CurrentTime, 0f, PlaylistManager.CurrentClipDuration);
|
||||
#if MM_UGUI2
|
||||
SongDuration.text = MMTime.FloatToTimeString(PlaylistManager.CurrentTime, false, true, true, false)
|
||||
+ " / "
|
||||
+ MMTime.FloatToTimeString(PlaylistManager.CurrentClipDuration, false, true, true, false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/// a progress bar meant to display the progress of the song currently playing
|
||||
public MMProgressBar ProgressBar;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the song name display
|
||||
/// </summary>
|
||||
protected virtual void UpdateSongName()
|
||||
{
|
||||
int displayIndex = PlaylistManager.CurrentSongIndex + 1;
|
||||
#if MM_UGUI2
|
||||
SongName.text = displayIndex + ". " + PlaylistManager.CurrentSongName;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a new song starts to play, we update its name
|
||||
/// </summary>
|
||||
/// <param name="channel"></param>
|
||||
protected virtual void OnPlayEvent(int channel)
|
||||
{
|
||||
UpdateSongName();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts listening for events
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
MMPlaylistNewSongStartedEvent.Register(OnPlayEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops listening for events
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
MMPlaylistNewSongStartedEvent.Unregister(OnPlayEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// On Update, updates the progress bar and song duration counter
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (PlaylistManager.CurrentClipDuration == 0f)
|
||||
{
|
||||
ProgressBar.SetBar(0f, 0f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgressBar.SetBar(PlaylistManager.CurrentTime, 0f, PlaylistManager.CurrentClipDuration);
|
||||
#if MM_UGUI2
|
||||
SongDuration.text = MMTime.FloatToTimeString(PlaylistManager.CurrentTime)
|
||||
+ " / "
|
||||
+ MMTime.FloatToTimeString(PlaylistManager.CurrentClipDuration);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts listening for events
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
MMPlaylistNewSongStartedEvent.Register(OnPlayEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops listening for events
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
MMPlaylistNewSongStartedEvent.Unregister(OnPlayEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the song name display
|
||||
/// </summary>
|
||||
protected virtual void UpdateSongName()
|
||||
{
|
||||
var displayIndex = PlaylistManager.CurrentSongIndex + 1;
|
||||
#if MM_UGUI2
|
||||
SongName.text = displayIndex + ". " + PlaylistManager.CurrentSongName;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a new song starts to play, we update its name
|
||||
/// </summary>
|
||||
/// <param name="channel"></param>
|
||||
protected virtual void OnPlayEvent(int channel)
|
||||
{
|
||||
UpdateSongName();
|
||||
}
|
||||
#if 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
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user