2019-10-02 16:17:08 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
{
|
|
|
|
public class SpectrumGeneratorPlayMode : SpectrumGenerator, ISpectrumGenerator
|
|
|
|
{
|
2019-10-04 13:35:23 +00:00
|
|
|
private ISpectrumArraySelector arraySelector_;
|
2019-10-02 16:17:08 +00:00
|
|
|
|
2019-10-04 13:35:23 +00:00
|
|
|
public SpectrumGeneratorPlayMode(int textureWidth, int textureHeight, ISpectrumArraySelector arraySelector)
|
2019-10-02 16:17:08 +00:00
|
|
|
:base(textureWidth, textureHeight)
|
|
|
|
{
|
2019-10-04 13:35:23 +00:00
|
|
|
arraySelector_ = arraySelector;
|
2019-10-02 16:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Update( Rect selectionRect)
|
|
|
|
{
|
|
|
|
var numPixels = 0;
|
2019-10-04 13:35:23 +00:00
|
|
|
var data = arraySelector_.SelectedArray;
|
2019-10-02 16:17:08 +00:00
|
|
|
OnAllPixels((x, y) =>
|
|
|
|
{
|
|
|
|
var magnitude = data[x] * 20f;
|
|
|
|
var validPixel = magnitude > y;
|
|
|
|
var color = validPixel ? Color.green : Color.black;
|
|
|
|
|
|
|
|
if (IsInSelection(x, y, ref selectionRect))
|
|
|
|
{
|
|
|
|
color.a = 1f;
|
|
|
|
if (validPixel)
|
|
|
|
numPixels++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
color.a = 0.2f;
|
|
|
|
|
|
|
|
Spectrum.SetPixel(x, y, color);
|
|
|
|
});
|
|
|
|
Spectrum.Apply();
|
|
|
|
return numPixels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|