From a9c452a5eec0100ed33241ed2a691a41c65f711d Mon Sep 17 00:00:00 2001 From: Jenny Crowe Date: Wed, 9 Mar 2022 21:24:06 -0700 Subject: [PATCH] Editor: Timeline now scales to fit song length --- Assets/Scripts/LevelEditor/Editor.cs | 8 ++++++++ Assets/Scripts/LevelEditor/Timeline/Timeline.cs | 9 +++++++++ Assets/Scripts/Util/Sound.cs | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/LevelEditor/Editor.cs b/Assets/Scripts/LevelEditor/Editor.cs index 437e1c7a..b31df5e8 100644 --- a/Assets/Scripts/LevelEditor/Editor.cs +++ b/Assets/Scripts/LevelEditor/Editor.cs @@ -224,6 +224,8 @@ namespace RhythmHeavenMania.Editor { Conductor.instance.musicSource.clip = await LoadClip(Path.Combine(paths)); changedMusic = true; + + Timeline.FitToSong(); } } ); @@ -349,6 +351,8 @@ namespace RhythmHeavenMania.Editor if (path != String.Empty) { + loadedMusic = false; + using (FileStream zipFile = File.Open(path, FileMode.Open)) { using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Read)) @@ -387,10 +391,14 @@ namespace RhythmHeavenMania.Editor } } + if (!loadedMusic) + Conductor.instance.musicSource.clip = null; + currentRemixPath = path; remixName = Path.GetFileName(path); UpdateEditorStatus(false); CommandManager.instance.Clear(); + Timeline.FitToSong(); } }); } diff --git a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs index c29d74e8..0d68cecc 100644 --- a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs @@ -189,6 +189,15 @@ namespace RhythmHeavenMania.Editor.Track AutoBtnUpdate(); } + public void FitToSong() + { + var currentSizeDelta = TimelineContent.sizeDelta; + float songBeats = Conductor.instance.SongLengthInBeats(); + if (songBeats == 0) songBeats = 320; + else songBeats += 10; + TimelineContent.sizeDelta = new Vector2(songBeats, currentSizeDelta.y); + } + public void AutoBtnUpdate() { var animName = GameManager.instance.autoplay ? "Idle" : "Disabled"; diff --git a/Assets/Scripts/Util/Sound.cs b/Assets/Scripts/Util/Sound.cs index 99e33851..ff6ae992 100644 --- a/Assets/Scripts/Util/Sound.cs +++ b/Assets/Scripts/Util/Sound.cs @@ -107,7 +107,8 @@ namespace RhythmHeavenMania.Util public void Stop() { - audioSource.Stop(); + if (audioSource != null) + audioSource.Stop(); } public void Delete()