41 lines
869 B
C#
41 lines
869 B
C#
using Godot;
|
|
using Newlon.Components.Level;
|
|
using System;
|
|
|
|
public partial class MusicTransitioner : AudioStreamPlayer
|
|
{
|
|
private AudioStreamPlaybackInteractive playback;
|
|
private Timer timer;
|
|
|
|
public override void _Ready()
|
|
{
|
|
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
|
|
timer = GetNode<Timer>("Timer");
|
|
}
|
|
|
|
private void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
|
|
{
|
|
if (state == RuntimeLevelData.LevelStates.Game)
|
|
{
|
|
Play();
|
|
playback = (AudioStreamPlaybackInteractive)GetStreamPlayback();
|
|
VolumeLinear = 1;
|
|
}
|
|
else
|
|
{
|
|
var tween = CreateTween();
|
|
tween.TweenProperty(this, "volume_linear", 0, 1);
|
|
tween.TweenCallback(Callable.From(Stop));
|
|
}
|
|
}
|
|
|
|
public void OnHugeWaveApproaching()
|
|
{
|
|
playback.SwitchToClip(1);
|
|
timer.Start();
|
|
}
|
|
public void OnTimerTimeout()
|
|
{
|
|
playback.SwitchToClip(0);
|
|
}
|
|
}
|