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-01-28 02:50:57 +00:00
|
|
|
namespace RhythmHeavenMania.Editor.Track
|
|
|
|
{
|
|
|
|
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-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);
|
|
|
|
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);
|
|
|
|
transform.localPosition = new Vector3(Mathf.Clamp(Starpelly.Mathp.Round2Nearest(transform.localPosition.x, 0.25f), 0, Mathf.Infinity), transform.localPosition.y);
|
|
|
|
}
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|