2019-10-02 16:17:08 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
|
{
|
|
|
|
|
public class SpectrumGeneratorPlayMode : SpectrumGenerator, ISpectrumGenerator
|
|
|
|
|
{
|
2019-10-05 16:09:24 +00:00
|
|
|
|
private IPdArraySelector arraySelector_;
|
2019-10-02 16:17:08 +00:00
|
|
|
|
|
2019-10-05 16:09:24 +00:00
|
|
|
|
public SpectrumGeneratorPlayMode(int textureWidth, int textureHeight, IPdArraySelector 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
|
|
|
|
}
|
|
|
|
|
|
2020-01-15 20:54:46 +00:00
|
|
|
|
public int Update(Rect selectionRect)
|
2019-10-02 16:17:08 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
});
|
2020-01-15 20:54:46 +00:00
|
|
|
|
|
|
|
|
|
// statt <20>ber alle Pixel, nur <20>ber SpektrumArray und dann die Auswahl pr<70>fen
|
|
|
|
|
/*for (int x = (int) selectionRect.x; x < selectionRect.x+selectionRect.width-1; x++)
|
|
|
|
|
{
|
|
|
|
|
for (int y = (int) selectionRect.y; y < Spectrum.height - selectionRect.y - (selectionRect.height - 1); 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++;
|
|
|
|
|
|
|
|
|
|
Spectrum.SetPixel(x, y, color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
Spectrum.Apply();
|
2019-10-02 16:17:08 +00:00
|
|
|
|
return numPixels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|