// 게임 상태를 따라 트랙을 관리하는것은 잘못 되었습니다. 트랙관리자는 트랙 로드, 트랙의 볼륨설정, 플레이와 정지만을 제공하기 떄문입니다. protected override void Update() { base.Update(); if (track.HasCompleted && State == GameState.Playing) { loopTrack(); } if (CurrentVolume != lastVolume) { Console.WriteLine($"Track Volume: {CurrentVolume}%"); lastVolume = CurrentVolume; } if (track.TrackLoaded && State == GameState.Ready) { track.Stop(); } if (track.TrackLoaded && State == GameState.Playing) { track.Start(); track.VolumeTo(CurrentVolume / 100); } if (track.TrackLoaded && State == GameState.GameOver) { track.Stop(); track.Reset(); } }
private void changeTrack() { var lastTrack = CurrentTrack; var queuedTrack = new DrawableTrack(current.LoadTrack()); queuedTrack.Completed += () => onTrackCompleted(current); CurrentTrack = queuedTrack; // At this point we may potentially be in an async context from tests. This is extremely dangerous but we have to make do for now. // CurrentTrack is immediately updated above for situations where a immediate knowledge about the new track is required, // but the mutation of the hierarchy is scheduled to avoid exceptions. Schedule(() => { lastTrack.VolumeTo(0, 500, Easing.Out).Expire(); if (queuedTrack == CurrentTrack) { AddInternal(queuedTrack); queuedTrack.VolumeTo(0).Then().VolumeTo(1, 300, Easing.Out); } else { // If the track has changed since the call to changeTrack, it is safe to dispose the // queued track rather than consume it. queuedTrack.Dispose(); } }); }