From af24468f254090c7505afbc9bff4900f84bb96ad Mon Sep 17 00:00:00 2001 From: Braedon Date: Fri, 28 Jan 2022 21:26:34 -0500 Subject: [PATCH] Some tempo changes improvements --- Assets/Resources/Music/practice.json | 2 +- Assets/Scenes/Editor.unity | 109 +++++++++++++++++- Assets/Scripts/Conductor.cs | 2 +- .../LevelEditor/Commands/CommandManager.cs | 4 +- .../LevelEditor/Timeline/TempoTimeline.cs | 74 ++++++++++-- .../LevelEditor/Timeline/TempoTimelineObj.cs | 71 ++++++++++-- .../Scripts/LevelEditor/Timeline/Timeline.cs | 82 +++++++++---- Assets/Scripts/LevelEditor/editortheme.json | 2 +- Assets/karateman.json | 2 +- 9 files changed, 297 insertions(+), 51 deletions(-) diff --git a/Assets/Resources/Music/practice.json b/Assets/Resources/Music/practice.json index b000574c..02fd0ba1 100644 --- a/Assets/Resources/Music/practice.json +++ b/Assets/Resources/Music/practice.json @@ -1 +1 @@ -{"bpm":125.0,"entities":[{"beat":0.0,"track":0,"length":33.0,"datamodel":"karateman/bop"},{"beat":1.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":3.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":3.5,"track":2,"length":1.0,"datamodel":"karateman/hit3"},{"beat":5.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":6.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":7.0,"track":3,"length":2.0,"datamodel":"karateman/rock"},{"beat":9.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":11.0,"track":1,"length":2.0,"datamodel":"karateman/bulb"},{"beat":13.0,"track":1,"length":4.5,"datamodel":"karateman/kick"},{"beat":17.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":19.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":19.5,"track":2,"length":1.0,"datamodel":"karateman/hit4"},{"beat":21.0,"track":0,"length":2.0,"datamodel":"karateman/pot"},{"beat":22.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":23.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":24.0,"track":3,"length":2.0,"datamodel":"karateman/ball"},{"beat":25.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":27.0,"track":1,"length":2.0,"datamodel":"karateman/bulb"},{"beat":29.0,"track":1,"length":4.0,"datamodel":"karateman/combo"}]} \ No newline at end of file +{"bpm":125.0,"entities":[{"beat":0.0,"track":0,"length":33.0,"datamodel":"karateman/bop"},{"beat":0.0,"track":3,"length":1.0,"datamodel":"gameManager/switchGame/karateman"},{"beat":1.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":3.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":3.5,"track":2,"length":1.0,"datamodel":"karateman/hit3"},{"beat":5.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":6.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":7.0,"track":3,"length":2.0,"datamodel":"karateman/rock"},{"beat":9.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":11.0,"track":1,"length":2.0,"datamodel":"karateman/bulb"},{"beat":13.0,"track":1,"length":4.5,"datamodel":"karateman/kick"},{"beat":17.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":19.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":19.5,"track":2,"length":1.0,"datamodel":"karateman/hit4"},{"beat":21.0,"track":0,"length":2.0,"datamodel":"karateman/pot"},{"beat":22.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":23.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":24.0,"track":3,"length":2.0,"datamodel":"karateman/ball"},{"beat":25.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":27.0,"track":1,"length":2.0,"datamodel":"karateman/bulb"},{"beat":29.0,"track":1,"length":4.0,"datamodel":"karateman/combo"},{"beat":33.0,"track":1,"length":1.0,"datamodel":"clappyTrio/bop"},{"beat":33.0,"track":0,"length":1.0,"datamodel":"gameManager/switchGame/clappyTrio"},{"beat":34.0,"track":1,"length":1.0,"datamodel":"clappyTrio/bop"},{"beat":35.0,"track":1,"length":1.0,"datamodel":"clappyTrio/prepare_alt"},{"beat":36.5,"track":1,"length":0.75,"datamodel":"clappyTrio/clap"},{"beat":38.5,"track":0,"length":1.0,"datamodel":"clappyTrio/prepare"},{"beat":39.0,"track":1,"length":0.25,"datamodel":"clappyTrio/clap"},{"beat":40.0,"track":1,"length":1.0,"datamodel":"clappyTrio/bop"},{"beat":41.0,"track":0,"length":1.0,"datamodel":"gameManager/switchGame/spaceball"},{"beat":42.0,"track":1,"length":2.0,"datamodel":"spaceball/shoot"},{"beat":45.0,"track":1,"length":3.0,"datamodel":"spaceball/shootHigh"},{"beat":48.0,"track":1,"length":2.0,"datamodel":"spaceball/shoot"},{"beat":50.0,"track":1,"length":2.0,"datamodel":"spaceball/shoot"},{"beat":53.0,"track":1,"length":3.0,"datamodel":"spaceball/shootHigh"},{"beat":57.0,"track":1,"length":2.0,"datamodel":"spaceball/shoot"},{"beat":59.0,"track":1,"length":2.0,"datamodel":"spaceball/shoot"},{"beat":61.0,"track":1,"length":3.0,"datamodel":"spaceball/shootHigh"},{"beat":64.0,"track":0,"length":1.0,"datamodel":"gameManager/switchGame/forkLifter"},{"beat":65.0,"track":1,"length":3.0,"datamodel":"forkLifter/pea"},{"beat":68.0,"track":0,"length":3.0,"datamodel":"forkLifter/pea"},{"beat":70.0,"track":1,"length":3.0,"datamodel":"forkLifter/pea"},{"beat":72.5,"track":2,"length":1.0,"datamodel":"forkLifter/gulp"},{"beat":73.0,"track":1,"length":2.0,"datamodel":"spaceSoccer/ball dispense"},{"beat":73.0,"track":0,"length":1.0,"datamodel":"gameManager/switchGame/spaceSoccer"},{"beat":75.0,"track":1,"length":10.0,"datamodel":"spaceSoccer/keep-up"},{"beat":85.0,"track":1,"length":3.0,"datamodel":"spaceSoccer/high kick-toe!"},{"beat":88.0,"track":1,"length":5.0,"datamodel":"spaceSoccer/keep-up"},{"beat":93.0,"track":1,"length":3.0,"datamodel":"spaceSoccer/high kick-toe!"},{"beat":96.0,"track":1,"length":4.0,"datamodel":"spaceSoccer/keep-up"}],"tempoChanges":[]} \ No newline at end of file diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index f5b3dd3c..732399aa 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -4297,6 +4297,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 666273484} + - component: {fileID: 666273485} m_Layer: 5 m_Name: TempoChange m_TagString: Untagged @@ -4318,6 +4319,7 @@ RectTransform: - {fileID: 2127964035} - {fileID: 1287203020} - {fileID: 499528698} + - {fileID: 983551349} m_Father: {fileID: 689207020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -4326,6 +4328,26 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0.0876, y: 0} m_Pivot: {x: 0, y: 1} +--- !u!114 &666273485 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 666273483} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dfe88f36dac55f44dac7fe958fe3c228, type: 3} + m_Name: + m_EditorClassIdentifier: + rectTransform: {fileID: 0} + tempoTXT: {fileID: 499528699} + raycastRect: {fileID: 983551349} + tempoChange: + beat: 0 + length: 0 + tempo: 0 + hovering: 0 --- !u!1 &678553524 GameObject: m_ObjectHideFlags: 0 @@ -4511,6 +4533,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: RefTempoChange: {fileID: 666273484} + StartingBPM: {fileID: 1199306549} + tempoTimelineObjs: [] --- !u!114 &689207022 MonoBehaviour: m_ObjectHideFlags: 0 @@ -6366,6 +6390,81 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 954835803} m_CullTransparentMesh: 1 +--- !u!1 &983551348 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 983551349} + - component: {fileID: 983551351} + - component: {fileID: 983551350} + m_Layer: 5 + m_Name: Raycast + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &983551349 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 983551348} + m_LocalRotation: {x: 0, y: 0, z: 1, w: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 666273484} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 180} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0.36, y: 33.998} + m_Pivot: {x: 0.5, y: 1} +--- !u!114 &983551350 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 983551348} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 0} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &983551351 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 983551348} + m_CullTransparentMesh: 1 --- !u!1 &991363086 GameObject: m_ObjectHideFlags: 0 @@ -8725,7 +8824,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0.02000001, y: 33.998} + m_SizeDelta: {x: 0.03, y: 33.998} m_Pivot: {x: 0.5, y: 1} --- !u!114 &1287203021 MonoBehaviour: @@ -9340,8 +9439,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f86858990a87c764892672104bdaef1f, type: 3} m_Name: m_EditorClassIdentifier: - level: {fileID: 4900000, guid: fafaeee85f4121643a0699a4de97da53, type: 3} - music: {fileID: 8300000, guid: a0589cdba27fb254e90da17b4804c2fe, type: 3} + level: {fileID: 4900000, guid: ad2467f171a3aee4b9be8c26e2e1a42c, type: 3} + music: {fileID: 8300000, guid: 7d1a104c87e593f40a262ebbcb2a371b, type: 3} debugUI: 0 playOnStart: 0 editor: 1 @@ -11656,12 +11755,12 @@ MonoBehaviour: SongBeat: {fileID: 932211468} SongPos: {fileID: 1567318397} CurrentTempo: {fileID: 1783963081} - StartingBPM: {fileID: 1199306549} eventObjs: [] LayerCount: 4 metronomeEnabled: 0 resizable: 0 TimelineSlider: {fileID: 770589360} + TimelineGridSelect: {fileID: 238901181} TimelinePlaybackBeat: {fileID: 117889364} TimelineContent: {fileID: 1852819573} TimelineSongPosLineRef: {fileID: 580861938} @@ -12795,7 +12894,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0.109999985, y: 11.84} + m_SizeDelta: {x: 0.15, y: 11.84} m_Pivot: {x: 0.5, y: 0} --- !u!114 &2127964036 MonoBehaviour: diff --git a/Assets/Scripts/Conductor.cs b/Assets/Scripts/Conductor.cs index 87c9ecf1..f3ad5057 100644 --- a/Assets/Scripts/Conductor.cs +++ b/Assets/Scripts/Conductor.cs @@ -120,7 +120,7 @@ namespace RhythmHeavenMania songPosition = time - firstBeatOffset; - songPositionInBeats += (Time.deltaTime - firstBeatOffset) / secPerBeat; + songPositionInBeats += ((Time.deltaTime * musicSource.pitch) - firstBeatOffset) / secPerBeat; // songPositionInBeats = Time.deltaTime / secPerBeat; if (metronome) diff --git a/Assets/Scripts/LevelEditor/Commands/CommandManager.cs b/Assets/Scripts/LevelEditor/Commands/CommandManager.cs index dae1835c..b6e92ed8 100644 --- a/Assets/Scripts/LevelEditor/Commands/CommandManager.cs +++ b/Assets/Scripts/LevelEditor/Commands/CommandManager.cs @@ -38,7 +38,7 @@ namespace RhythmHeavenMania.Editor public void Undo() { - if (!canUndo()) return; + if (!canUndo() || Conductor.instance.NotStopped()) return; if (historyStack.Count > 0) { @@ -49,7 +49,7 @@ namespace RhythmHeavenMania.Editor public void Redo() { - if (!canRedo()) return; + if (!canRedo() || Conductor.instance.NotStopped()) return; if (redoHistoryStack.Count > 0) { diff --git a/Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs b/Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs index d9dc6ae1..dd21d13f 100644 --- a/Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs @@ -13,24 +13,62 @@ namespace RhythmHeavenMania.Editor.Track [Header("Components")] private RectTransform rectTransform; [SerializeField] private RectTransform RefTempoChange; + [SerializeField] private RectTransform StartingBPM; + + public List tempoTimelineObjs = new List(); private void Start() { rectTransform = this.GetComponent(); + + for (int i = 0; i < GameManager.instance.Beatmap.tempoChanges.Count; i++) + { + Beatmap.TempoChange tempoChange = GameManager.instance.Beatmap.tempoChanges[i]; + AddTempoChange(false, tempoChange); + } + + StartingBPM.GetChild(0).GetComponent().text = GameManager.instance.Beatmap.bpm.ToString(); } private void Update() { - if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main)) + if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped()) { - if (Input.GetMouseButtonDown(0)) + if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main)) { - AddTempoChange(); + if (Input.GetMouseButtonDown(0)) + { + if (tempoTimelineObjs.FindAll(c => c.hovering == true).Count == 0) + { + AddTempoChange(true); + } + } } + + if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPM, Input.mousePosition, Camera.main)) + { + float increase = Input.mouseScrollDelta.y; + if (Input.GetKey(KeyCode.LeftControl)) + increase /= 100f; + if (Input.GetKey(KeyCode.LeftShift)) + increase *= 5f; + + GameManager.instance.Beatmap.bpm += increase; + StartingBPM.transform.GetChild(0).GetComponent().text = GameManager.instance.Beatmap.bpm.ToString(); + } + + StartingBPM.GetComponent().enabled = true; + StartingBPM.GetComponent