mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-23 01:55:16 +00:00
878e07ae31
* tunnel tunnel tunnel * tunnel messes with the volume * tempo finder can now be reset by waiting now uses the conductor's time source if it exists and is playing * wip anims * Animations Finished * add tunnel sound * tunnel shader fix the left sound * add pre-sliced BG assets --------- Co-authored-by: Seanski2 <seanbenedit@gmail.com>
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using System.Linq;
|
|
|
|
namespace HeavenStudio.Editor
|
|
{
|
|
public class BPMText : MonoBehaviour
|
|
{
|
|
public const int maxPressTimes = 50;
|
|
|
|
[SerializeField] private TMP_Text BPM;
|
|
[SerializeField] private TMP_Text BPMRounded;
|
|
|
|
private List<double> pressTimes = new();
|
|
|
|
public void ChangeText(double timePressed)
|
|
{
|
|
pressTimes.Add(timePressed);
|
|
|
|
// First press isn't good to work with.
|
|
if (pressTimes.Count < 2) return;
|
|
|
|
// Limit the number of press times stored.
|
|
if (pressTimes.Count > maxPressTimes)
|
|
pressTimes.RemoveAt(0);
|
|
|
|
double averageTime = pressTimes.GetRange(1, pressTimes.Count - 1).Average();
|
|
|
|
double thisBPM = 60 / averageTime;
|
|
BPM.text = $"{thisBPM:0.000}";
|
|
BPMRounded.text = $"{(int)Math.Round(thisBPM)}";
|
|
}
|
|
|
|
public void ResetText()
|
|
{
|
|
pressTimes.Clear();
|
|
|
|
BPM.text = "---";
|
|
BPMRounded.text = "---";
|
|
}
|
|
|
|
public void ClearSamples()
|
|
{
|
|
if (pressTimes.Count < 2) return;
|
|
|
|
if (pressTimes.Count > maxPressTimes)
|
|
pressTimes.RemoveAt(0);
|
|
|
|
double averageTime = pressTimes.GetRange(1, pressTimes.Count - 1).Average();
|
|
|
|
double thisBPM = 60 / averageTime;
|
|
BPM.text = $"<color=\"yellow\">{thisBPM:0.000}";
|
|
BPMRounded.text = $"<color=\"yellow\">{(int)Math.Round(thisBPM)}";
|
|
|
|
pressTimes.Clear();
|
|
}
|
|
}
|
|
}
|