From f86ea3078f9d07110117c922fd9304154af8fadb Mon Sep 17 00:00:00 2001 From: Chikashi Miyama Date: Sat, 28 Sep 2019 21:21:58 +0200 Subject: [PATCH] add level meters --- UnityProject/Assembly-CSharp-Editor.csproj | 1 + UnityProject/Assets/Editor/LevelMeter.cs | 44 +++++++++++++++++++ UnityProject/Assets/Editor/LevelMeter.cs.meta | 3 ++ UnityProject/Assets/Editor/PdConsole.cs | 17 +++++++ UnityProject/Assets/Editor/TogglePresenter.cs | 2 - 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 UnityProject/Assets/Editor/LevelMeter.cs create mode 100644 UnityProject/Assets/Editor/LevelMeter.cs.meta diff --git a/UnityProject/Assembly-CSharp-Editor.csproj b/UnityProject/Assembly-CSharp-Editor.csproj index c014631..e177087 100644 --- a/UnityProject/Assembly-CSharp-Editor.csproj +++ b/UnityProject/Assembly-CSharp-Editor.csproj @@ -59,6 +59,7 @@ + diff --git a/UnityProject/Assets/Editor/LevelMeter.cs b/UnityProject/Assets/Editor/LevelMeter.cs new file mode 100644 index 0000000..33f2523 --- /dev/null +++ b/UnityProject/Assets/Editor/LevelMeter.cs @@ -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(); + } + + } +} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/LevelMeter.cs.meta b/UnityProject/Assets/Editor/LevelMeter.cs.meta new file mode 100644 index 0000000..bf3a850 --- /dev/null +++ b/UnityProject/Assets/Editor/LevelMeter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f3be381e60d047f8a67bbbae4a0af44b +timeCreated: 1569696904 \ No newline at end of file diff --git a/UnityProject/Assets/Editor/PdConsole.cs b/UnityProject/Assets/Editor/PdConsole.cs index f4f3272..be314b2 100644 --- a/UnityProject/Assets/Editor/PdConsole.cs +++ b/UnityProject/Assets/Editor/PdConsole.cs @@ -1,4 +1,5 @@ using UnityEditor; +using UnityEngine; namespace cylvester { @@ -7,12 +8,15 @@ namespace cylvester private IEditorToggle dspToggle_; private ITogglePresenter togglePresenter_; private IPdBackend pdBackend_; + private LevelMeter[] levelMeters_; [MenuItem("SoundVision/Pd console %#p")] static void Init() { var window = (PdConsole)GetWindow(typeof(PdConsole)); window.Show(); + + } private void OnEnable() @@ -25,6 +29,9 @@ namespace cylvester dspToggle_ = new EditorToggle(); togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_); + levelMeters_ = new LevelMeter[16]; + for (var i = 0; i < 16; ++i) + levelMeters_[i] = new LevelMeter(i); } private void OnGUI () @@ -32,9 +39,19 @@ namespace cylvester if(!ValidatePdBackend(pdBackend_)) return; + EditorGUILayout.Space(); 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) { diff --git a/UnityProject/Assets/Editor/TogglePresenter.cs b/UnityProject/Assets/Editor/TogglePresenter.cs index 177f9ca..b6d1f41 100644 --- a/UnityProject/Assets/Editor/TogglePresenter.cs +++ b/UnityProject/Assets/Editor/TogglePresenter.cs @@ -9,14 +9,12 @@ namespace cylvester public class TogglePresenter : ITogglePresenter, IDisposable { private readonly IEditorToggle editorToggle_; - private IPdBackend pdBackend_; private readonly Action onToggleChanged_; public TogglePresenter(IEditorToggle toggle, IPdBackend pdBackend) { editorToggle_ = toggle; - pdBackend_ = pdBackend; onToggleChanged_ = () => {