File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . Collections ;
33using System . Collections . Generic ;
44using 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 ;
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments