add level meters
This commit is contained in:
parent
f29a1549c5
commit
f86ea3078f
5 changed files with 65 additions and 2 deletions
|
@ -59,6 +59,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Assets\Editor\AppBuilder.cs" />
|
<Compile Include="Assets\Editor\AppBuilder.cs" />
|
||||||
<Compile Include="Assets\Editor\EditorToggle.cs" />
|
<Compile Include="Assets\Editor\EditorToggle.cs" />
|
||||||
|
<Compile Include="Assets\Editor\LevelMeter.cs" />
|
||||||
<Compile Include="Assets\Editor\PdBindEditor.cs" />
|
<Compile Include="Assets\Editor\PdBindEditor.cs" />
|
||||||
<Compile Include="Assets\Editor\PdConsole.cs" />
|
<Compile Include="Assets\Editor\PdConsole.cs" />
|
||||||
<Compile Include="Assets\Editor\TogglePresenter.cs" />
|
<Compile Include="Assets\Editor\TogglePresenter.cs" />
|
||||||
|
|
44
UnityProject/Assets/Editor/LevelMeter.cs
Normal file
44
UnityProject/Assets/Editor/LevelMeter.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace cylvester
|
||||||
|
{
|
||||||
|
public class LevelMeter
|
||||||
|
{
|
||||||
|
private string label_;
|
||||||
|
private float dB_;
|
||||||
|
private Texture2D meterImageTexture_;
|
||||||
|
|
||||||
|
public LevelMeter(int index)
|
||||||
|
{
|
||||||
|
label_ = (index + 1).ToString();
|
||||||
|
meterImageTexture_ = new Texture2D(1, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < 32; ++i)
|
||||||
|
{
|
||||||
|
meterImageTexture_.SetPixel(0, i, i < 10 ? Color.green : Color.black);
|
||||||
|
}
|
||||||
|
meterImageTexture_.Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
3
UnityProject/Assets/Editor/LevelMeter.cs.meta
Normal file
3
UnityProject/Assets/Editor/LevelMeter.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f3be381e60d047f8a67bbbae4a0af44b
|
||||||
|
timeCreated: 1569696904
|
|
@ -1,4 +1,5 @@
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace cylvester
|
namespace cylvester
|
||||||
{
|
{
|
||||||
|
@ -7,12 +8,15 @@ namespace cylvester
|
||||||
private IEditorToggle dspToggle_;
|
private IEditorToggle dspToggle_;
|
||||||
private ITogglePresenter togglePresenter_;
|
private ITogglePresenter togglePresenter_;
|
||||||
private IPdBackend pdBackend_;
|
private IPdBackend pdBackend_;
|
||||||
|
private LevelMeter[] levelMeters_;
|
||||||
|
|
||||||
[MenuItem("SoundVision/Pd console %#p")]
|
[MenuItem("SoundVision/Pd console %#p")]
|
||||||
static void Init()
|
static void Init()
|
||||||
{
|
{
|
||||||
var window = (PdConsole)GetWindow(typeof(PdConsole));
|
var window = (PdConsole)GetWindow(typeof(PdConsole));
|
||||||
window.Show();
|
window.Show();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
|
@ -25,6 +29,9 @@ namespace cylvester
|
||||||
dspToggle_ = new EditorToggle();
|
dspToggle_ = new EditorToggle();
|
||||||
|
|
||||||
togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_);
|
togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_);
|
||||||
|
levelMeters_ = new LevelMeter[16];
|
||||||
|
for (var i = 0; i < 16; ++i)
|
||||||
|
levelMeters_[i] = new LevelMeter(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGUI ()
|
private void OnGUI ()
|
||||||
|
@ -32,10 +39,20 @@ namespace cylvester
|
||||||
if(!ValidatePdBackend(pdBackend_))
|
if(!ValidatePdBackend(pdBackend_))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
EditorGUILayout.Space();
|
||||||
dspToggle_.State = EditorGUILayout.Toggle("Pure Data Process", dspToggle_.State);
|
dspToggle_.State = EditorGUILayout.Toggle("Pure Data Process", dspToggle_.State);
|
||||||
|
|
||||||
|
EditorGUILayout.Space();
|
||||||
|
EditorGUILayout.BeginHorizontal();
|
||||||
|
foreach (var levelMeter in levelMeters_)
|
||||||
|
levelMeter.Render();
|
||||||
|
|
||||||
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private bool ValidatePdBackend(IPdBackend pdBackend)
|
private bool ValidatePdBackend(IPdBackend pdBackend)
|
||||||
{
|
{
|
||||||
var exist = pdBackend_ != null;
|
var exist = pdBackend_ != null;
|
||||||
|
|
|
@ -9,14 +9,12 @@ namespace cylvester
|
||||||
public class TogglePresenter : ITogglePresenter, IDisposable
|
public class TogglePresenter : ITogglePresenter, IDisposable
|
||||||
{
|
{
|
||||||
private readonly IEditorToggle editorToggle_;
|
private readonly IEditorToggle editorToggle_;
|
||||||
private IPdBackend pdBackend_;
|
|
||||||
|
|
||||||
private readonly Action onToggleChanged_;
|
private readonly Action onToggleChanged_;
|
||||||
|
|
||||||
public TogglePresenter(IEditorToggle toggle, IPdBackend pdBackend)
|
public TogglePresenter(IEditorToggle toggle, IPdBackend pdBackend)
|
||||||
{
|
{
|
||||||
editorToggle_ = toggle;
|
editorToggle_ = toggle;
|
||||||
pdBackend_ = pdBackend;
|
|
||||||
|
|
||||||
onToggleChanged_ = () =>
|
onToggleChanged_ = () =>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue