Browse Source

Set PlayMusic start time (via Ben Keenan)

Renamed SetMusicVolume to SetAudioVolume
master
chrisgregan 10 years ago
parent
commit
ca94bc1c0f
  1. 6
      Assets/Fungus/Audio/Commands/PlayMusic.cs
  2. 2
      Assets/Fungus/Audio/Commands/SetMusicVolume.cs
  3. 12
      Assets/Fungus/Audio/Scripts/MusicController.cs

6
Assets/Fungus/Audio/Commands/PlayMusic.cs

@ -10,12 +10,16 @@ namespace Fungus
{ {
public AudioClip musicClip; public AudioClip musicClip;
[Tooltip("Time to begin playing in seconds. If the audio file is compressed, the time index may be inaccurate.")]
public float atTime;
public override void OnEnter() public override void OnEnter()
{ {
MusicController musicController = MusicController.GetInstance(); MusicController musicController = MusicController.GetInstance();
if (musicController != null) if (musicController != null)
{ {
musicController.PlayMusic(musicClip); float startTime = Mathf.Max (0, atTime);
musicController.PlayMusic(musicClip, startTime);
} }
Continue(); Continue();

2
Assets/Fungus/Audio/Commands/SetMusicVolume.cs

@ -19,7 +19,7 @@ namespace Fungus
MusicController musicController = MusicController.GetInstance(); MusicController musicController = MusicController.GetInstance();
if (musicController != null) if (musicController != null)
{ {
musicController.SetMusicVolume(volume, fadeDuration); musicController.SetAudioVolume(volume, fadeDuration);
} }
Continue(); Continue();

12
Assets/Fungus/Audio/Scripts/MusicController.cs

@ -39,10 +39,12 @@ namespace Fungus
* Plays game music using an audio clip. * Plays game music using an audio clip.
* One music clip may be played at a time. * One music clip may be played at a time.
* @param musicClip The music clip to play * @param musicClip The music clip to play
* @param atTime Time in the music clip to start at
*/ */
public void PlayMusic(AudioClip musicClip) public void PlayMusic(AudioClip musicClip, float atTime = 0)
{ {
audio.clip = musicClip; audio.clip = musicClip;
audio.time = atTime; // May be inaccurate if the audio source is compressed http://docs.unity3d.com/ScriptReference/AudioSource-time.html BK
audio.Play(); audio.Play();
} }
@ -59,7 +61,7 @@ namespace Fungus
* @param volume The new music volume value [0..1] * @param volume The new music volume value [0..1]
* @param duration The length of time in seconds needed to complete the volume change. * @param duration The length of time in seconds needed to complete the volume change.
*/ */
public virtual void SetMusicVolume(float volume, float duration) public virtual void SetAudioVolume(float volume, float duration)
{ {
iTween.AudioTo(gameObject, volume, 1f, duration); iTween.AudioTo(gameObject, volume, 1f, duration);
} }
@ -74,5 +76,11 @@ namespace Fungus
{ {
audio.PlayOneShot(soundClip, volume); audio.PlayOneShot(soundClip, volume);
} }
public virtual void PlaySoundAtTime(AudioClip soundClip, float volume, float atTime)
{
audio.time = atTime; // This may not work BK
audio.PlayOneShot(soundClip, volume);
}
} }
} }
Loading…
Cancel
Save