Custom snap interval, but not in the editor (yet)

This commit is contained in:
Braedon
2022-02-11 20:15:36 -05:00
parent 75e25ceac0
commit c04f994d1b
19 changed files with 1037 additions and 1109 deletions

View File

@ -83,7 +83,7 @@ namespace RhythmHeavenMania.Editor.Track
if (create == true)
{
tempoChange.transform.position = new Vector3(Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition).x + 0.08f, tempoChange.transform.position.y);
tempoChange.transform.localPosition = new Vector3(Starpelly.Mathp.Round2Nearest(tempoChange.transform.localPosition.x, 0.25f), tempoChange.transform.localPosition.y);
tempoChange.transform.localPosition = new Vector3(Starpelly.Mathp.Round2Nearest(tempoChange.transform.localPosition.x, Timeline.SnapInterval()), tempoChange.transform.localPosition.y);
Beatmap.TempoChange tempoC = new Beatmap.TempoChange();
tempoC.beat = tempoChange.transform.localPosition.x;

View File

@ -71,7 +71,7 @@ namespace RhythmHeavenMania.Editor.Track
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(mousePos.x - startPosX, transform.position.y, 0);
transform.localPosition = new Vector3(Mathf.Clamp(Starpelly.Mathp.Round2Nearest(transform.localPosition.x, 0.25f), 0, Mathf.Infinity), transform.localPosition.y);
transform.localPosition = new Vector3(Mathf.Clamp(Starpelly.Mathp.Round2Nearest(transform.localPosition.x, Timeline.SnapInterval()), 0, Mathf.Infinity), transform.localPosition.y);
}
if (Input.GetMouseButtonUp(0))
{

View File

@ -26,6 +26,9 @@ namespace RhythmHeavenMania.Editor.Track
public bool resizable;
private bool movingPlayback;
public CurrentTimelineState timelineState = new CurrentTimelineState();
public float snapInterval = 0.25f; // 4/4
public static float SnapInterval() { return instance.snapInterval; }
public class CurrentTimelineState
{
@ -256,7 +259,7 @@ namespace RhythmHeavenMania.Editor.Track
if (movingPlayback)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(TimelineContent, Input.mousePosition, Editor.instance.EditorCamera, out lastMousePos);
TimelineSlider.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(lastMousePos.x + 0.12f, 0.25f), 0, Mathf.Infinity), TimelineSlider.transform.localPosition.y);
TimelineSlider.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(lastMousePos.x + 0.12f, Timeline.SnapInterval()), 0, Mathf.Infinity), TimelineSlider.transform.localPosition.y);
if (TimelineSlider.localPosition.x != lastBeatPos)
Conductor.instance.SetBeat(TimelineSlider.transform.localPosition.x);
@ -576,7 +579,7 @@ namespace RhythmHeavenMania.Editor.Track
public void SetPlaybackSpeed(float speed)
{
float spd = Mathp.Round2Nearest(speed, 0.25f);
float spd = Mathp.Round2Nearest(speed, Timeline.SnapInterval());
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: {spd}x";
Conductor.instance.musicSource.pitch = spd;
PlaybackSpeed.value = spd;

View File

@ -149,7 +149,7 @@ namespace RhythmHeavenMania.Editor.Track
lastPos_ = transform.localPosition;
this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
this.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(this.transform.localPosition.y));
this.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.x, Timeline.SnapInterval()), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(this.transform.localPosition.y));
// moveTemp.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
// moveTemp.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(moveTemp.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(moveTemp.transform.localPosition.y));
@ -171,9 +171,9 @@ namespace RhythmHeavenMania.Editor.Track
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Editor.instance.EditorCamera, out mousePos);
sizeDelta = new Vector2(-mousePos.x + 0.15f, sizeDelta.y);
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, rectTransform.localPosition.x), sizeDelta.y);
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, Timeline.SnapInterval(), rectTransform.localPosition.x), sizeDelta.y);
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, 0.25f), sizeDelta.y);
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, Timeline.SnapInterval()), sizeDelta.y);
SetPivot(new Vector2(0, rectTransform.pivot.y));
OnComplete(false);
}
@ -185,9 +185,9 @@ namespace RhythmHeavenMania.Editor.Track
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Editor.instance.EditorCamera, out mousePos);
sizeDelta = new Vector2(mousePos.x + 0.15f, sizeDelta.y);
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, Mathf.Infinity), sizeDelta.y);
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, Timeline.SnapInterval(), Mathf.Infinity), sizeDelta.y);
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, 0.25f), sizeDelta.y);
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, Timeline.SnapInterval()), sizeDelta.y);
SetPivot(new Vector2(0, rectTransform.pivot.y));
OnComplete(false);
}