soundvision/UnityProject/Assets/Scripts/Visualizer/WaterfallVisualizer.cs

45 lines
1.4 KiB
C#
Raw Normal View History

2019-10-03 17:06:11 +00:00
using UnityEngine;
namespace cylvester
{
public class WaterfallVisualizer : MonoBehaviour
{
private const int historySize = 32;
[SerializeField] private PdBackend pdBackend;
[SerializeField] private GameObject spectrumPrefab;
[SerializeField, Range(1, 16)] private int channel = 1;
private IPdArray spectrumArray_;
private ISpectrumVisualizer[] visualizers_;
private Transform[] transforms_;
private int head_;
private void Start()
{
visualizers_ = new ISpectrumVisualizer[historySize];
transforms_ = new Transform[historySize];
for (var i = 0; i < historySize; ++i)
{
var instance = Instantiate(spectrumPrefab, gameObject.transform, true);
transforms_[i] = instance.transform;
visualizers_[i] = instance.GetComponent<SpectrumVisualizer>();
}
}
public void Update()
{
2019-10-04 13:35:23 +00:00
spectrumArray_ = pdBackend.spectrumArrayContainer[channel-1];
2019-10-03 17:06:11 +00:00
visualizers_[head_].Spectrum = spectrumArray_.Data;
head_++;
head_ %= historySize;
for (var i = 0; i < historySize; ++i)
{
var index = (head_ + i) % historySize;
transforms_[index].localPosition = new Vector3(0, 0, 1f * i);
}
}
}
}