HeavenStudioPlus/Assets/Scripts/LevelEditor/TempoFinder/TempoFinder.cs

78 lines
2.1 KiB
C#
Raw Normal View History

2022-02-25 01:02:05 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HeavenStudio.Editor
2022-02-25 01:02:05 +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;
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;
lastTimePressed = double.MinValue;
2022-02-25 01:02:05 +00:00
}
2022-02-25 01:02:05 +00:00
public void SwitchTempoDialog()
{
if (dialog.activeSelf)
{
dialog.SetActive(false);
2022-02-25 01:02:05 +00:00
timePressed = 0;
lastTimePressed = double.MinValue;
2022-02-25 04:30:02 +00:00
bpmText.ResetText();
}
else
{
ResetAllDialogs();
dialog.SetActive(true);
2022-02-25 01:02:05 +00:00
}
}
2022-02-25 01:02:05 +00:00
public void TapBPM()
{
pressed = true;
}
2022-02-25 01:02:05 +00:00
private void Update()
{
bool conductorTimeSource = Conductor.instance != null && Conductor.instance.NotStopped();
2022-02-25 01:02:05 +00:00
timePressed += Time.deltaTime;
if (timePressed > 2)
2022-02-25 01:02:05 +00:00
{
timePressed = 0;
lastTimePressed = double.MinValue;
bpmText.ClearSamples();
2022-02-25 01:02:05 +00:00
pressed = false;
}
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;
pressed = false;
2022-02-25 01:02:05 +00:00
}
}
}
}