You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.0 KiB
56 lines
2.0 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
10 years ago
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Plays looping game music. If any game music is already playing, it is stopped. Game music will continue playing across scene loads.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Audio",
|
||
|
"Play Music",
|
||
|
"Plays looping game music. If any game music is already playing, it is stopped. Game music will continue playing across scene loads.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class PlayMusic : Command
|
||
|
{
|
||
|
[Tooltip("Music sound clip to play")]
|
||
8 years ago
|
[SerializeField] protected AudioClip musicClip;
|
||
8 years ago
|
|
||
|
[Tooltip("Time to begin playing in seconds. If the audio file is compressed, the time index may be inaccurate.")]
|
||
8 years ago
|
[SerializeField] protected float atTime;
|
||
8 years ago
|
|
||
|
[Tooltip("The music will start playing again at end.")]
|
||
8 years ago
|
[SerializeField] protected bool loop = true;
|
||
8 years ago
|
|
||
|
[Tooltip("Length of time to fade out previous playing music.")]
|
||
8 years ago
|
[SerializeField] protected float fadeDuration = 1f;
|
||
8 years ago
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
8 years ago
|
IMusicController musicController = MusicController.GetInstance();
|
||
8 years ago
|
if (musicController != null)
|
||
|
{
|
||
|
float startTime = Mathf.Max(0, atTime);
|
||
|
musicController.PlayMusic(musicClip, loop, fadeDuration, startTime);
|
||
|
}
|
||
|
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
if (musicClip == null)
|
||
|
{
|
||
|
return "Error: No music clip selected";
|
||
|
}
|
||
|
|
||
|
return musicClip.name;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(242, 209, 176, 255);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|