Skip to content

Commit 3c54ad4

Browse files
authored
Merge pull request #8 from jukibom/master
feat: dragging on timeline now respects beat snap
2 parents 677b775 + 714f11c commit 3c54ad4

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

Assets/Scripts/Timeline.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
@@ -83,7 +83,8 @@ public class Timeline : MonoBehaviour {
8383

8484
public static float time { get; set; }
8585

86-
private int beatSnap = 4;
86+
public int beatSnap { get; private set; } = 4;
87+
8788
[HideInInspector] public static int scale = 20;
8889
private float targetScale = 0.7f;
8990
private float scaleOffset = 0;

Assets/Scripts/Tools/DragSelect/DragSelect.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,26 @@ void Update() {
390390
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
391391
var offsetFromDragPoint = pos - startDragMovePos;
392392

393-
// Vector3 newPos = NoteGridSnap.SnapToGrid(mousePos, EditorInput.selectedSnappingMode);
393+
Vector3 newPos = SnapToBeat(mousePos);
394394
// TODO: Snap!
395395

396-
mousePos += offsetFromDragPoint;
397-
intent.target.timelineTargetIcon.transform.localPosition = new Vector3(mousePos.x, pos.y, pos.z);
398-
intent.target.gridTargetIcon.transform.localPosition = new Vector3(gridPos.x, gridPos.y, mousePos.x);
396+
newPos += offsetFromDragPoint;
397+
intent.target.timelineTargetIcon.transform.localPosition = new Vector3(newPos.x, pos.y, pos.z);
398+
intent.target.gridTargetIcon.transform.localPosition = new Vector3(gridPos.x, gridPos.y, newPos.x);
399399

400-
intent.intendedPosition = new Vector3(mousePos.x, pos.y, pos.z);
400+
intent.intendedPosition = new Vector3(newPos.x, pos.y, pos.z);
401401
}
402402
}
403403
}
404404
}
405+
406+
private Vector3 SnapToBeat(Vector3 position) {
407+
var increments = ((480 / timeline.beatSnap) * 4f) / 480; // what even is life
408+
return new Vector3(
409+
Mathf.Round(position.x / increments) * increments,
410+
position.y,
411+
position.z
412+
);
413+
}
405414
}
406415
}

0 commit comments

Comments
 (0)