Commit d08aaab3 authored by Tommé Nöll's avatar Tommé Nöll

added fade possibility to backgroundmusic.cs

parent 16d68473
......@@ -14,6 +14,7 @@ public class BackgroundMusic : MonoBehaviour {
private bool inTransition = false;
private int preTransitionSample = 0;
private double lastUpdate = 0;
private float fadePerSecond = -1f;
// Use this for initialization
void Start () {
......@@ -34,10 +35,18 @@ public class BackgroundMusic : MonoBehaviour {
if (AS[current].timeSamples != preTransitionSample)
{
inTransition = false;
AS[other].volume = 1;
fadePerSecond = -1;
Debug.Log("Music transition complete, playing " + AS[current].clip.name +
"\nSample new: " + AS[current].timeSamples + ", Sample old: " + AS[1-current].timeSamples +
"\nCurrent global time: " + AudioSettings.dspTime + ", Last update at " + lastUpdate);
}
if (fadePerSecond >= 0 && AS[1 - current].isPlaying)
{
AS[1 - current].volume -= fadePerSecond * Time.deltaTime;
}
/*else
{
lastUpdate = AudioSettings.dspTime;
......@@ -72,7 +81,7 @@ public class BackgroundMusic : MonoBehaviour {
"\nCurrent Global Time: " + AudioSettings.dspTime);
}
public void TransitionTo(MusicObject target)
public void TransitionTo(MusicObject target, float fadeDuration = -1)
{
if (inTransition)
{
......@@ -87,6 +96,12 @@ public class BackgroundMusic : MonoBehaviour {
inTransition = true;
if (fadeDuration >= 0)
{
fadePerSecond = 1 / fadeDuration;
Play(target, AS[current].clip.samples + (int)(AS[current].clip.frequency * fadeDuration), 0);
}
int iTarget;
for (iTarget = 0; iTarget < currentMusic.targets.Length; iTarget++) //search for TransitionTarget that matches target
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment