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

39 lines
911 B
C#
Raw Normal View History

2019-10-03 17:06:11 +00:00
using UnityEngine;
namespace cylvester
{
public interface ISpectrumVisualizer
{
float[] Spectrum { set; }
}
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class SpectrumVisualizer : MonoBehaviour, ISpectrumVisualizer
{
private MeshFilter meshFilter_;
private ICombMesh combMesh_;
private void Start()
{
combMesh_ = new CombMesh(512, 0.1f);
meshFilter_ = GetComponent<MeshFilter>();
meshFilter_.mesh = new Mesh
{
vertices = combMesh_.Vertices,
triangles = combMesh_.Indices
};
}
public float[] Spectrum
{
set
{
combMesh_.Update(value);
meshFilter_.mesh.vertices = combMesh_.Vertices;
}
}
}
}