2019-09-28 18:17:39 +00:00
|
|
|
|
using UnityEditor;
|
2019-09-28 19:21:58 +00:00
|
|
|
|
using UnityEngine;
|
2019-09-28 18:17:39 +00:00
|
|
|
|
|
|
|
|
|
namespace cylvester
|
|
|
|
|
{
|
|
|
|
|
public class PdConsole : EditorWindow
|
|
|
|
|
{
|
|
|
|
|
private IEditorToggle dspToggle_;
|
|
|
|
|
private ITogglePresenter togglePresenter_;
|
|
|
|
|
private IPdBackend pdBackend_;
|
2019-09-28 19:21:58 +00:00
|
|
|
|
private LevelMeter[] levelMeters_;
|
2019-09-28 18:17:39 +00:00
|
|
|
|
|
|
|
|
|
[MenuItem("SoundVision/Pd console %#p")]
|
|
|
|
|
static void Init()
|
|
|
|
|
{
|
|
|
|
|
var window = (PdConsole)GetWindow(typeof(PdConsole));
|
|
|
|
|
window.Show();
|
2019-09-28 19:21:58 +00:00
|
|
|
|
|
|
|
|
|
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
2019-09-28 18:29:31 +00:00
|
|
|
|
{
|
|
|
|
|
var foundObjects = FindObjectsOfType(typeof(PdBackend));
|
|
|
|
|
if (foundObjects.Length != 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pdBackend_ = (IPdBackend) foundObjects[0];
|
2019-09-28 18:17:39 +00:00
|
|
|
|
dspToggle_ = new EditorToggle();
|
2019-09-28 18:29:31 +00:00
|
|
|
|
|
|
|
|
|
togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_);
|
2019-09-28 19:21:58 +00:00
|
|
|
|
levelMeters_ = new LevelMeter[16];
|
|
|
|
|
for (var i = 0; i < 16; ++i)
|
|
|
|
|
levelMeters_[i] = new LevelMeter(i);
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-28 18:29:31 +00:00
|
|
|
|
private void OnGUI ()
|
2019-09-28 18:17:39 +00:00
|
|
|
|
{
|
2019-09-28 18:29:31 +00:00
|
|
|
|
if(!ValidatePdBackend(pdBackend_))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-09-28 19:21:58 +00:00
|
|
|
|
EditorGUILayout.Space();
|
2019-09-28 18:17:39 +00:00
|
|
|
|
dspToggle_.State = EditorGUILayout.Toggle("Pure Data Process", dspToggle_.State);
|
2019-09-28 19:21:58 +00:00
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
foreach (var levelMeter in levelMeters_)
|
|
|
|
|
levelMeter.Render();
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
2019-09-28 18:17:39 +00:00
|
|
|
|
|
|
|
|
|
}
|
2019-09-28 19:21:58 +00:00
|
|
|
|
|
|
|
|
|
|
2019-09-28 18:29:31 +00:00
|
|
|
|
|
|
|
|
|
private bool ValidatePdBackend(IPdBackend pdBackend)
|
|
|
|
|
{
|
|
|
|
|
var exist = pdBackend_ != null;
|
|
|
|
|
if (!exist)
|
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.LabelField("No Pd backend found in the scene");
|
|
|
|
|
}
|
|
|
|
|
return exist;
|
|
|
|
|
}
|
2019-09-28 18:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|