2019-09-29 10:00:16 +00:00
|
|
|
using UnityEngine;
|
2019-10-02 16:17:08 +00:00
|
|
|
using UnityEngine.Events;
|
2019-09-29 10:00:16 +00:00
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
{
|
2019-10-02 16:17:08 +00:00
|
|
|
[System.Serializable]
|
|
|
|
class UnityFloatEvent : UnityEvent<float> { }
|
|
|
|
|
2019-10-04 13:35:23 +00:00
|
|
|
|
|
|
|
public class PdSpectrumBind : MonoBehaviour
|
2019-09-29 10:00:16 +00:00
|
|
|
{
|
2019-10-04 19:58:32 +00:00
|
|
|
[SerializeField] private PdBackend pdBackend = null;
|
|
|
|
[SerializeField] private Rect selection = Rect.zero;
|
|
|
|
[SerializeField] private UnityFloatEvent energyChanged = null;
|
2019-10-04 13:35:23 +00:00
|
|
|
[SerializeField] private int channel = 0;
|
2019-10-02 16:17:08 +00:00
|
|
|
|
|
|
|
private ISpectrumGenerator spectrumGenerator_;
|
2019-10-05 16:09:24 +00:00
|
|
|
private IPdArraySelector arraySelector_;
|
2019-09-29 19:53:47 +00:00
|
|
|
|
2019-10-02 16:17:08 +00:00
|
|
|
public int TextureWidth { get; } = 512;
|
|
|
|
public int TextureHeight { get; } = 256;
|
|
|
|
public Texture2D Spectrum => spectrumGenerator_.Spectrum;
|
|
|
|
public int Energy { get; private set; }
|
|
|
|
|
2019-10-04 13:35:23 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
2019-10-05 16:09:24 +00:00
|
|
|
arraySelector_ = new PdArraySelector(pdBackend.SpectrumArrayContainer);
|
2019-10-04 13:35:23 +00:00
|
|
|
spectrumGenerator_ = new SpectrumGeneratorPlayMode(TextureWidth, TextureHeight, arraySelector_);
|
|
|
|
}
|
|
|
|
|
2019-10-02 16:17:08 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2019-10-04 13:35:23 +00:00
|
|
|
arraySelector_.Selection = channel;
|
2019-10-02 16:17:08 +00:00
|
|
|
var energy = spectrumGenerator_.Update(selection);
|
|
|
|
if (energy == Energy)
|
|
|
|
return;
|
|
|
|
Energy = energy;
|
|
|
|
energyChanged.Invoke(Energy);
|
|
|
|
}
|
2019-09-29 10:00:16 +00:00
|
|
|
}
|
|
|
|
}
|