Commit 367bb7f2 authored by Tommé Nöll's avatar Tommé Nöll
Browse files

Merge branch 'tomme'

parents 1bde28e2 d0599b57
......@@ -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[1 - current].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)
{
......@@ -86,6 +95,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
......
......@@ -20,4 +20,11 @@ public class MusicObject : ScriptableObject {
public bool isLoop = false;
[Tooltip("The non-looped version if this song is looped (required), the looped version otherwise (optional).")]
public MusicObject loopCounterpiece;
public MusicObject() {}
public MusicObject(AudioClip clip)
{
this.clip = clip;
isLoop = false;
}
}
......@@ -54,6 +54,8 @@ public class BossAI : MonoBehaviour
//CameraShake der MainCamera
public CameraShake cameraShake;
private BackgroundMusic bgMusic;
//Events, die während des Phasenwechsels screen shake den Bildschirm schwarz und wieder sichtbar machen
public UnityEvent screenShake;
public UnityEvent fadeToBlack;
......@@ -71,7 +73,8 @@ public class BossAI : MonoBehaviour
[SerializeField] private AudioSource audioSource;
[SerializeField] private SoundVolume soundVolumeHit;
[SerializeField] private SoundVolume soundVolumeScream1;
[SerializeField] private SoundVolume soundVolumeScream2;
[SerializeField] private SoundVolume soundVolumeScream2;
[SerializeField] private AudioClip[] music;
private void Awake()
{
......@@ -79,6 +82,7 @@ public class BossAI : MonoBehaviour
health = bossHealth.healthPoints;
player = GameObject.FindGameObjectWithTag("Player");
bgMusic = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<BackgroundMusic>();
shootingPoint = transform.position + horizontalOffset * Vector3.right + verticalOffset * Vector3.up;
......@@ -160,10 +164,12 @@ public class BossAI : MonoBehaviour
if(health == 3)
{
audioSource.PlayOneShot(soundVolumeScream1.clip, soundVolumeScream1.volume);
bgMusic.TransitionTo(new MusicObject(music[1]), 2f);
}
else if(health == 2)
{
audioSource.PlayOneShot(soundVolumeScream2.clip, soundVolumeScream2.volume);
bgMusic.TransitionTo(new MusicObject(music[2]), 2f);
}
yield return new WaitForSeconds(timeBetweenShakeAndFade);
......
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