From f29a1549c5f4b2ee0996884926728e9bde793f81 Mon Sep 17 00:00:00 2001 From: Chikashi Miyama Date: Sat, 28 Sep 2019 20:29:31 +0200 Subject: [PATCH] close #29 --- UnityProject/Assets/Editor/PdConsole.cs | 30 ++++++++++++++----- UnityProject/Assets/Editor/TogglePresenter.cs | 3 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/UnityProject/Assets/Editor/PdConsole.cs b/UnityProject/Assets/Editor/PdConsole.cs index 76ca64e..f4f3272 100644 --- a/UnityProject/Assets/Editor/PdConsole.cs +++ b/UnityProject/Assets/Editor/PdConsole.cs @@ -1,5 +1,4 @@ using UnityEditor; -using UnityEngine; namespace cylvester { @@ -17,20 +16,35 @@ namespace cylvester } private void OnEnable() - { - object[] foundObjects = FindObjectsOfType(typeof(PdBackend)); - - + { + var foundObjects = FindObjectsOfType(typeof(PdBackend)); + if (foundObjects.Length != 1) + return; + + pdBackend_ = (IPdBackend) foundObjects[0]; dspToggle_ = new EditorToggle(); - togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_); + + togglePresenter_ = new TogglePresenter(dspToggle_, pdBackend_); } - void OnGUI () + private void OnGUI () { - foundObjects. + if(!ValidatePdBackend(pdBackend_)) + return; + dspToggle_.State = EditorGUILayout.Toggle("Pure Data Process", dspToggle_.State); } + + private bool ValidatePdBackend(IPdBackend pdBackend) + { + var exist = pdBackend_ != null; + if (!exist) + { + EditorGUILayout.LabelField("No Pd backend found in the scene"); + } + return exist; + } } } diff --git a/UnityProject/Assets/Editor/TogglePresenter.cs b/UnityProject/Assets/Editor/TogglePresenter.cs index eba08df..177f9ca 100644 --- a/UnityProject/Assets/Editor/TogglePresenter.cs +++ b/UnityProject/Assets/Editor/TogglePresenter.cs @@ -20,8 +20,7 @@ namespace cylvester onToggleChanged_ = () => { - var state = editorToggle_.State; - // apply state to pd backend; + pdBackend.State = editorToggle_.State; }; editorToggle_.ToggleStateChanged += onToggleChanged_;