soundvision/UnityProject/Assets/Scripts/PdConnection/PdSpectrumBind.cs
Chikashi Miyama cb599bf5ca refer #62
2019-10-05 18:09:24 +02:00

41 lines
No EOL
1.3 KiB
C#

using UnityEngine;
using UnityEngine.Events;
namespace cylvester
{
[System.Serializable]
class UnityFloatEvent : UnityEvent<float> { }
public class PdSpectrumBind : MonoBehaviour
{
[SerializeField] private PdBackend pdBackend = null;
[SerializeField] private Rect selection = Rect.zero;
[SerializeField] private UnityFloatEvent energyChanged = null;
[SerializeField] private int channel = 0;
private ISpectrumGenerator spectrumGenerator_;
private IPdArraySelector arraySelector_;
public int TextureWidth { get; } = 512;
public int TextureHeight { get; } = 256;
public Texture2D Spectrum => spectrumGenerator_.Spectrum;
public int Energy { get; private set; }
private void Start()
{
arraySelector_ = new PdArraySelector(pdBackend.SpectrumArrayContainer);
spectrumGenerator_ = new SpectrumGeneratorPlayMode(TextureWidth, TextureHeight, arraySelector_);
}
private void Update()
{
arraySelector_.Selection = channel;
var energy = spectrumGenerator_.Update(selection);
if (energy == Energy)
return;
Energy = energy;
energyChanged.Invoke(Energy);
}
}
}