2019-09-28 19:21:58 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
{
|
2019-09-29 16:04:26 +00:00
|
|
|
interface ILevelMeter
|
|
|
|
{
|
|
|
|
void Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class LevelMeter : ILevelMeter
|
2019-09-28 19:21:58 +00:00
|
|
|
{
|
2019-09-28 22:19:35 +00:00
|
|
|
private const int TextureWidth = 1;
|
|
|
|
private const int TextureHeight = 100;
|
|
|
|
|
|
|
|
private readonly Texture2D meterImageTexture_;
|
|
|
|
private readonly int index_;
|
|
|
|
private readonly string label_;
|
|
|
|
private readonly IPdArray pdArray_;
|
2019-09-28 19:21:58 +00:00
|
|
|
|
2019-09-28 22:19:35 +00:00
|
|
|
public LevelMeter(int index, IPdArray pdArray)
|
2019-09-28 19:21:58 +00:00
|
|
|
{
|
2019-09-28 22:19:35 +00:00
|
|
|
index_ = index;
|
|
|
|
label_ = (index_ + 1).ToString();
|
|
|
|
pdArray_ = pdArray;
|
|
|
|
meterImageTexture_ = new Texture2D(TextureWidth, TextureHeight);
|
2019-09-28 19:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Render()
|
|
|
|
{
|
|
|
|
UpdateTexture();
|
|
|
|
var rect = EditorGUILayout.BeginVertical();
|
|
|
|
var style = new GUIStyle(GUI.skin.label)
|
|
|
|
{
|
|
|
|
alignment = TextAnchor.UpperCenter,
|
|
|
|
fixedHeight = 120
|
|
|
|
};
|
|
|
|
GUILayout.Label(label_, style);
|
|
|
|
rect.y += 20;
|
|
|
|
rect.height -= 20;
|
|
|
|
EditorGUI.DrawPreviewTexture(rect, meterImageTexture_);
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateTexture()
|
|
|
|
{
|
2019-09-28 22:19:35 +00:00
|
|
|
var level = pdArray_.Data[index_];
|
|
|
|
for (var i = 0; i < 100; ++i)
|
2019-09-28 19:21:58 +00:00
|
|
|
{
|
2019-09-28 22:19:35 +00:00
|
|
|
meterImageTexture_.SetPixel(0, i, i < level ? Color.green : Color.black);
|
2019-09-28 19:21:58 +00:00
|
|
|
}
|
|
|
|
meterImageTexture_.Apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|