예제 #1
0
    public override void OnInspectorGUI()
    {
        SyntactsHub script = (SyntactsHub)target;

        serializedObject.Update();

        EditorGUI.BeginDisabledGroup(Application.isPlaying);

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(openMode, new GUIContent("Open Mode", "Determines how Devices will be opened."));

        if (openMode.enumValueIndex == (int)SyntactsHub.OpenMode.ByIndex)
        {
            EditorGUILayout.PropertyField(index, new GUIContent("Device Index"));
        }
        else if (openMode.enumValueIndex == (int)SyntactsHub.OpenMode.ByAPI)
        {
            EditorGUILayout.PropertyField(api, new GUIContent("Device API"));
        }
        else if (openMode.enumValueIndex == (int)SyntactsHub.OpenMode.Custom)
        {
            EditorGUILayout.PropertyField(index, new GUIContent("Device Index"));
            EditorGUILayout.PropertyField(channelCount, new GUIContent("Channel Count"));
            EditorGUILayout.PropertyField(sampleRate, new GUIContent("Sample Rate"));
        }
        else if (openMode.enumValueIndex == (int)SyntactsHub.OpenMode.ByName)
        {
            EditorGUILayout.PropertyField(name, new GUIContent("Device Name"));
            EditorGUILayout.PropertyField(api, new GUIContent("Device API"));
        }

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }

        EditorGUI.EndDisabledGroup();


        showDeviceInfo = EditorGUILayout.BeginFoldoutHeaderGroup(showDeviceInfo, "Device");
        if (showDeviceInfo)
        {
            if (!Application.isPlaying)
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.LabelField("Only available when the Application is running.", italicLabel);
                EditorGUI.EndDisabledGroup();
            }
            else if (script.session != null && script.session.isOpen)
            {
                EditorGUILayout.LabelField("Index:", script.device.index.ToString());
                EditorGUILayout.LabelField("Name:", script.device.name.ToString());
                EditorGUILayout.LabelField("Default:", script.device.isDefault.ToString());
                EditorGUILayout.LabelField("API:", script.device.apiName.ToString());
                EditorGUILayout.LabelField("API Default:", script.device.isDefault.ToString());
                EditorGUILayout.LabelField("Max Channels:", script.device.maxChannels.ToString());
                EditorGUILayout.LabelField("Channels:", script.session.channelCount.ToString());
                EditorGUILayout.LabelField("Sample Rate:", script.session.sampleRate.ToString());
                EditorGUILayout.LabelField("CPU Load:", Mathf.Round((float)script.session.cpuLoad * 100).ToString() + "%");
            }
            else
            {
                EditorGUILayout.LabelField("Failed to open Device!", errorLabel);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();

        showChannelInfo = EditorGUILayout.BeginFoldoutHeaderGroup(showChannelInfo, "Channels");
        if (showChannelInfo)
        {
            // EditorGUI.BeginDisabledGroup(true);
            if (!Application.isPlaying)
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.LabelField("Only available when the Application is running.", italicLabel);
                EditorGUI.EndDisabledGroup();
            }
            else if (script.session != null && script.session.isOpen)
            {
                int count = script.session.channelCount;
                for (int i = 0; i < count; ++i)
                {
                    EditorGUILayout.LabelField("Channel " + i.ToString(), EditorStyles.miniBoldLabel);
                    EditorGUI.BeginChangeCheck();
                    float vol = EditorGUILayout.Slider("Volume", (float)script.session.GetVolume(i), 0, 1);
                    if (EditorGUI.EndChangeCheck())
                    {
                        script.session.SetVolume(i, vol);
                    }

                    EditorGUI.BeginChangeCheck();
                    float pitch = EditorGUILayout.Slider("Pitch", (float)script.session.GetPitch(i), 0, 10);
                    if (EditorGUI.EndChangeCheck())
                    {
                        script.session.SetPitch(i, pitch);
                    }
                }
            }
            else
            {
                EditorGUILayout.LabelField("Failed to open Device!", errorLabel);
            }
            // EditorGUI.EndDisabledGroup();
        }
        EditorGUILayout.EndFoldoutHeaderGroup();


        showAvailable = EditorGUILayout.BeginFoldoutHeaderGroup(showAvailable, "Available Devices");
        if (showAvailable)
        {
            foreach (var pair in availableDevices)
            {
                EditorGUILayout.LabelField(pair.Key.ToString(), EditorStyles.boldLabel);
                foreach (Device dev in pair.Value)
                {
                    EditorGUILayout.LabelField(dev.index.ToString(), dev.name);
                }
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();


        showDebug = EditorGUILayout.BeginFoldoutHeaderGroup(showDebug, "Debug");
        if (showDebug)
        {
            EditorGUILayout.LabelField("Syntacts Version:", version);
            EditorGUILayout.LabelField("ASIO Support:", asio.ToString());
            EditorGUILayout.LabelField("Session Count:", Syntacts.Session.count.ToString());
            EditorGUILayout.LabelField("Signal Count:", Syntacts.Signal.count.ToString());
        }
        EditorGUILayout.EndFoldoutHeaderGroup();


        // if (GUILayout.Button("Open Session")) {



        // }
        // if (GUILayout.Button("Close Session")) {

        // }
    }
예제 #2
0
 private void Start()
 {
     hub = FindObjectOfType <SyntactsHub>();
 }