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_;