mirror of
https://github.com/MrUnknownDE/vcc-tools.git
synced 2026-04-19 15:03:47 +02:00
add AudioLink BPM Detector
This commit is contained in:
43
AudioLink/BeatDetectorDisplay.cs
Normal file
43
AudioLink/BeatDetectorDisplay.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class BeatDetectorDisplay : UdonSharpBehaviour
|
||||
{
|
||||
public AudioLinkBeatDetector engine;
|
||||
public TextMeshProUGUI bpmText;
|
||||
public Image beatIndicator;
|
||||
public Color activeColor = Color.cyan;
|
||||
|
||||
private float flashTimer;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (engine == null) return;
|
||||
|
||||
// Wenn die Engine einen Beat erkennt...
|
||||
if (engine.isBeat)
|
||||
{
|
||||
// ...aktualisieren wir SOFORT den Text mit der instantBpm
|
||||
if (bpmText != null)
|
||||
{
|
||||
bpmText.text = engine.instantBpm.ToString("F0"); // "F0" für ganze Zahlen ohne Lag-Gefühl
|
||||
}
|
||||
|
||||
// Visueller Kick
|
||||
flashTimer = 0.1f;
|
||||
if (beatIndicator != null) beatIndicator.color = activeColor;
|
||||
}
|
||||
|
||||
// Timer für das Abklingen der LED
|
||||
if (flashTimer > 0)
|
||||
{
|
||||
flashTimer -= Time.deltaTime;
|
||||
if (flashTimer <= 0 && beatIndicator != null)
|
||||
{
|
||||
beatIndicator.color = new Color(0.1f, 0.1f, 0.1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user