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. 14
      Assets/Fungus/Audio/Scripts/MusicController.cs

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

@ -10,12 +10,16 @@ namespace Fungus
{
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()
{
MusicController musicController = MusicController.GetInstance();
if (musicController != null)
{
musicController.PlayMusic(musicClip);
float startTime = Mathf.Max (0, atTime);
musicController.PlayMusic(musicClip, startTime);
}
Continue();

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

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

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

@ -39,10 +39,12 @@ namespace Fungus
* Plays game music using an audio clip.
* One music clip may be played at a time.
* @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.time = atTime; // May be inaccurate if the audio source is compressed http://docs.unity3d.com/ScriptReference/AudioSource-time.html BK
audio.Play();
}
@ -53,13 +55,13 @@ namespace Fungus
{
audio.Stop();
}
/**
* Fades the game music volume to required level over a period of time.
* @param volume The new music volume value [0..1]
* @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);
}
@ -74,5 +76,11 @@ namespace Fungus
{
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