2022-01-28 02:50:57 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using TMPro;
|
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Editor.Track
|
2022-01-28 02:50:57 +00:00
|
|
|
{
|
|
|
|
public class TempoTimelineObj : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Header("Components")]
|
|
|
|
[SerializeField] private RectTransform rectTransform;
|
|
|
|
[SerializeField] private TMP_Text tempoTXT;
|
2022-01-29 02:26:34 +00:00
|
|
|
[SerializeField] private RectTransform raycastRect;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
|
|
|
public Beatmap.TempoChange tempoChange;
|
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
private float startPosX;
|
|
|
|
private bool moving = false;
|
|
|
|
|
|
|
|
public bool hovering;
|
|
|
|
|
|
|
|
private float lastPosX;
|
|
|
|
|
2022-01-28 02:50:57 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
rectTransform = GetComponent<RectTransform>();
|
|
|
|
tempoTXT = transform.GetChild(2).GetComponent<TMP_Text>();
|
|
|
|
UpdateTempo();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-01-29 02:26:34 +00:00
|
|
|
if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped())
|
2022-01-28 02:50:57 +00:00
|
|
|
{
|
2022-02-03 08:25:27 +00:00
|
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(raycastRect, Input.mousePosition, Editor.instance.EditorCamera))
|
2022-01-29 02:26:34 +00:00
|
|
|
{
|
|
|
|
float newTempo = Input.mouseScrollDelta.y;
|
|
|
|
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
|
|
newTempo *= 5f;
|
|
|
|
if (Input.GetKey(KeyCode.LeftControl))
|
|
|
|
newTempo /= 100f;
|
|
|
|
|
|
|
|
tempoChange.tempo += newTempo;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-06-28 20:58:23 +00:00
|
|
|
//make sure tempo is positive
|
|
|
|
if (tempoChange.tempo < 1)
|
|
|
|
tempoChange.tempo = 1;
|
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
{
|
2022-02-03 08:25:27 +00:00
|
|
|
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
2022-01-29 02:26:34 +00:00
|
|
|
startPosX = mousePos.x - transform.position.x;
|
|
|
|
moving = true;
|
|
|
|
lastPosX = transform.localPosition.x;
|
|
|
|
}
|
|
|
|
else if (Input.GetMouseButtonDown(1))
|
|
|
|
{
|
|
|
|
GameManager.instance.Beatmap.tempoChanges.Remove(tempoChange);
|
2022-02-25 07:01:41 +00:00
|
|
|
transform.parent.GetComponent<TempoTimeline>().tempoTimelineObjs.Remove(this);
|
2022-01-29 02:26:34 +00:00
|
|
|
Destroy(this.gameObject);
|
|
|
|
}
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
hovering = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hovering = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moving)
|
|
|
|
{
|
2022-02-03 08:25:27 +00:00
|
|
|
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
2022-01-29 02:26:34 +00:00
|
|
|
|
|
|
|
transform.position = new Vector3(mousePos.x - startPosX, transform.position.y, 0);
|
2022-02-12 01:15:36 +00:00
|
|
|
transform.localPosition = new Vector3(Mathf.Clamp(Starpelly.Mathp.Round2Nearest(transform.localPosition.x, Timeline.SnapInterval()), 0, Mathf.Infinity), transform.localPosition.y);
|
2022-01-29 02:26:34 +00:00
|
|
|
}
|
|
|
|
if (Input.GetMouseButtonUp(0))
|
|
|
|
{
|
|
|
|
if (transform.parent.GetComponent<TempoTimeline>().tempoTimelineObjs.Find(c => c.gameObject.transform.localPosition.x == this.transform.localPosition.x && c != this) != null)
|
|
|
|
{
|
|
|
|
transform.localPosition = new Vector3(lastPosX, transform.localPosition.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tempoChange.beat = transform.localPosition.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
moving = false;
|
|
|
|
lastPosX = transform.localPosition.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateTempo();
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateTempo()
|
|
|
|
{
|
|
|
|
tempoTXT.text = $"{tempoChange.tempo} BPM";
|
2022-06-28 20:58:23 +00:00
|
|
|
Timeline.instance.FitToSong();
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|