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

32 lines
867 B
C#
Raw Permalink Normal View History

using UnityEngine;
2019-09-28 18:17:39 +00:00
namespace cylvester
{
public class WaveformVisualizerBehaviour : MonoBehaviour
{
#pragma warning disable 649
[SerializeField] private string pdArrayName;
[SerializeField] private int pdArraySize;
[SerializeField] private LineRenderer lineRenderer;
[SerializeField, Range(0f, 10f)] private float scale = 1f;
#pragma warning restore 649
2019-09-28 18:17:39 +00:00
private PdArray pdArray_;
void Start()
{
2019-09-28 18:17:39 +00:00
pdArray_ = new PdArray(pdArrayName, pdArraySize);
}
void Update()
{
pdArray_.Update();
for(var i = 0; i < pdArray_.Data.Length; i++)
{
var posX = (i / 20f) - 0.5f;
lineRenderer.SetPosition(i, new Vector3(posX, pdArray_.Data[i] * scale, 0));
}
}
}
}