mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 10:27:37 +02:00
Tunnel tunnels (#577)
* 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>
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using System.Linq;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
public class BPMText : MonoBehaviour
|
||||
{
|
||||
@ -12,9 +13,9 @@ namespace HeavenStudio.Editor
|
||||
[SerializeField] private TMP_Text BPM;
|
||||
[SerializeField] private TMP_Text BPMRounded;
|
||||
|
||||
private List<float> pressTimes = new List<float>();
|
||||
private List<double> pressTimes = new();
|
||||
|
||||
public void ChangeText(float timePressed)
|
||||
public void ChangeText(double timePressed)
|
||||
{
|
||||
pressTimes.Add(timePressed);
|
||||
|
||||
@ -25,12 +26,13 @@ namespace HeavenStudio.Editor
|
||||
if (pressTimes.Count > maxPressTimes)
|
||||
pressTimes.RemoveAt(0);
|
||||
|
||||
var averageTime = pressTimes.GetRange(1, pressTimes.Count - 1).Average();
|
||||
double averageTime = pressTimes.GetRange(1, pressTimes.Count - 1).Average();
|
||||
|
||||
float thisBPM = 60 / averageTime; // BPM = 60/t
|
||||
BPM.text = $"{thisBPM}";
|
||||
BPMRounded.text = $"{Mathf.RoundToInt(thisBPM)}";
|
||||
double thisBPM = 60 / averageTime;
|
||||
BPM.text = $"{thisBPM:0.000}";
|
||||
BPMRounded.text = $"{(int)Math.Round(thisBPM)}";
|
||||
}
|
||||
|
||||
public void ResetText()
|
||||
{
|
||||
pressTimes.Clear();
|
||||
@ -38,5 +40,21 @@ namespace HeavenStudio.Editor
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,41 +2,76 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
public class TempoFinder : Dialog
|
||||
{
|
||||
private bool pressed;
|
||||
private float timePressed;
|
||||
[SerializeField] private BPMText bpmText;
|
||||
private void Awake()
|
||||
private bool pressed;
|
||||
private double timePressed;
|
||||
private double lastTimePressed = double.MinValue;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
pressed = false;
|
||||
timePressed = 0f;
|
||||
lastTimePressed = double.MinValue;
|
||||
}
|
||||
|
||||
public void SwitchTempoDialog()
|
||||
{
|
||||
if(dialog.activeSelf) {
|
||||
if (dialog.activeSelf)
|
||||
{
|
||||
dialog.SetActive(false);
|
||||
timePressed = 0;
|
||||
lastTimePressed = double.MinValue;
|
||||
bpmText.ResetText();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetAllDialogs();
|
||||
dialog.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void TapBPM()
|
||||
{
|
||||
pressed = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
bool conductorTimeSource = Conductor.instance != null && Conductor.instance.NotStopped();
|
||||
timePressed += Time.deltaTime;
|
||||
if(pressed)
|
||||
if (timePressed > 2)
|
||||
{
|
||||
pressed = false;
|
||||
bpmText.ChangeText(timePressed);
|
||||
timePressed = 0;
|
||||
lastTimePressed = double.MinValue;
|
||||
bpmText.ClearSamples();
|
||||
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;
|
||||
}
|
||||
timePressed = 0;
|
||||
pressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user