2022-02-25 01:02:05 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2023-11-24 22:59:34 +00:00
|
|
|
namespace HeavenStudio.Editor
|
2022-02-25 01:02:05 +00:00
|
|
|
{
|
2022-08-27 03:43:01 +00:00
|
|
|
public class TempoFinder : Dialog
|
2022-02-25 01:02:05 +00:00
|
|
|
{
|
2022-02-25 04:30:02 +00:00
|
|
|
[SerializeField] private BPMText bpmText;
|
2023-11-24 22:59:34 +00:00
|
|
|
private bool pressed;
|
|
|
|
private double timePressed;
|
|
|
|
private double lastTimePressed = double.MinValue;
|
|
|
|
|
|
|
|
private void Awake()
|
2022-02-25 01:02:05 +00:00
|
|
|
{
|
|
|
|
pressed = false;
|
|
|
|
timePressed = 0f;
|
2023-11-24 22:59:34 +00:00
|
|
|
lastTimePressed = double.MinValue;
|
2022-02-25 01:02:05 +00:00
|
|
|
}
|
2023-11-24 22:59:34 +00:00
|
|
|
|
2022-02-25 01:02:05 +00:00
|
|
|
public void SwitchTempoDialog()
|
|
|
|
{
|
2023-11-24 22:59:34 +00:00
|
|
|
if (dialog.activeSelf)
|
|
|
|
{
|
2022-08-27 03:43:01 +00:00
|
|
|
dialog.SetActive(false);
|
2022-02-25 01:02:05 +00:00
|
|
|
timePressed = 0;
|
2023-11-24 22:59:34 +00:00
|
|
|
lastTimePressed = double.MinValue;
|
2022-02-25 04:30:02 +00:00
|
|
|
bpmText.ResetText();
|
2023-11-24 22:59:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-27 03:43:01 +00:00
|
|
|
ResetAllDialogs();
|
|
|
|
dialog.SetActive(true);
|
2022-02-25 01:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-24 22:59:34 +00:00
|
|
|
|
2022-02-25 01:02:05 +00:00
|
|
|
public void TapBPM()
|
|
|
|
{
|
|
|
|
pressed = true;
|
|
|
|
}
|
2023-11-24 22:59:34 +00:00
|
|
|
|
2022-02-25 01:02:05 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2023-11-24 22:59:34 +00:00
|
|
|
bool conductorTimeSource = Conductor.instance != null && Conductor.instance.NotStopped();
|
2022-02-25 01:02:05 +00:00
|
|
|
timePressed += Time.deltaTime;
|
2023-11-24 22:59:34 +00:00
|
|
|
if (timePressed > 2)
|
2022-02-25 01:02:05 +00:00
|
|
|
{
|
2023-11-24 22:59:34 +00:00
|
|
|
timePressed = 0;
|
|
|
|
lastTimePressed = double.MinValue;
|
|
|
|
bpmText.ClearSamples();
|
2022-02-25 01:02:05 +00:00
|
|
|
pressed = false;
|
2023-11-24 22:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pressed)
|
|
|
|
{
|
|
|
|
if (!conductorTimeSource)
|
|
|
|
{
|
|
|
|
bpmText.ChangeText(timePressed);
|
|
|
|
lastTimePressed = double.MinValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lastTimePressed == double.MinValue)
|
|
|
|
{
|
|
|
|
bpmText.ChangeText(timePressed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bpmText.ChangeText(Conductor.instance.songPositionAsDouble - lastTimePressed);
|
|
|
|
}
|
|
|
|
lastTimePressed = Conductor.instance.songPositionAsDouble;
|
|
|
|
}
|
2022-02-25 01:02:05 +00:00
|
|
|
timePressed = 0;
|
2023-11-24 22:59:34 +00:00
|
|
|
pressed = false;
|
2022-02-25 01:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|