コード例 #1
0
        //
        // Draws the inspector.
        //
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Audio Engine
            GUI.enabled = !EditorApplication.isPlayingOrWillChangePlaymode;
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Do not manually add Steam Audio Manager component. " +
                                    "Click Window > Steam Audio.", MessageType.Info);
            EditorGUILayout.LabelField("Audio Engine Integration", EditorStyles.boldLabel);
            string[] engines             = { "Unity", "FMOD Studio" };
            var      audioEngineProperty = serializedObject.FindProperty("audioEngine");

            audioEngineProperty.enumValueIndex = EditorGUILayout.Popup("Audio Engine",
                                                                       audioEngineProperty.enumValueIndex, engines);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("HRTF Settings", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("sofaFiles"), new GUIContent("SOFA Files"), true);

            SteamAudioManager steamAudioManager = (SteamAudioManager)target;

            var wasGUIEnabled = GUI.enabled;

            GUI.enabled = true;

            var sofaFiles = steamAudioManager.GetSOFAFileNames();

            if (sofaFiles != null)
            {
                var sofaFileNames = new string[sofaFiles.Length];
                for (var i = 0; i < sofaFileNames.Length; ++i)
                {
                    sofaFileNames[i] = sofaFiles[i];
                    if (sofaFileNames[i].Length == 0 || sofaFileNames[i] == "")
                    {
                        sofaFileNames[i] = "Default";
                    }
                }
                var currentSOFAFileProperty = serializedObject.FindProperty("currentSOFAFile");
                if (currentSOFAFileProperty.intValue >= sofaFiles.Length)
                {
                    currentSOFAFileProperty.intValue = 0;
                }
                currentSOFAFileProperty.intValue = EditorGUILayout.Popup("Current SOFA File",
                                                                         currentSOFAFileProperty.intValue, sofaFileNames);
            }

            GUI.enabled = wasGUIEnabled;

            // Scene Settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Global Material Settings", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("materialPreset"));
            if (serializedObject.FindProperty("materialPreset").enumValueIndex < 11)
            {
                MaterialValue actualValue = steamAudioManager.materialValue;
                actualValue.CopyFrom(MaterialPresetList.PresetValue(
                                         serializedObject.FindProperty("materialPreset").enumValueIndex));
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("materialValue"));
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Scene Export", EditorStyles.boldLabel);
            if (GUILayout.Button("Pre-Export Scene"))
            {
                steamAudioManager.ExportScene(false);
            }
            if (GUILayout.Button("Export All Dynamic Objects"))
            {
                ExportAllDynamicObjects();
            }
            if (GUILayout.Button("Export to OBJ"))
            {
                steamAudioManager.ExportScene(true);
            }

            // Simulation Settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Simulation Settings", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationPreset"));
            if (serializedObject.FindProperty("simulationPreset").enumValueIndex < 3)
            {
                SimulationSettingsValue actualValue = steamAudioManager.simulationValue;
                actualValue.CopyFrom(SimulationSettingsPresetList.PresetValue(
                                         serializedObject.FindProperty("simulationPreset").enumValueIndex));

                EditorGUILayout.Space();
                UnityRayTracerGUI(true);
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationValue"));

                SimulationSettingsValue actualValue = steamAudioManager.simulationValue;

                if (actualValue.AmbisonicsOrder > 2)
                {
                    var numChannels = (actualValue.AmbisonicsOrder + 1) * (actualValue.AmbisonicsOrder + 1);
                    EditorGUILayout.HelpBox("Ambisonics order " + actualValue.AmbisonicsOrder.ToString() +
                                            " uses " + numChannels.ToString() + " channels per source for processing indirect sound. " +
                                            "This may significantly increase CPU usage. Consider reducing this value unless necessary.",
                                            MessageType.Warning);
                }

                UnityRayTracerGUI(false);

                if (Application.isEditor && EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    IntPtr environment = steamAudioManager.GameEngineState().Environment().GetEnvironment();
                    if (environment != IntPtr.Zero)
                    {
                        PhononCore.iplSetNumBounces(environment, actualValue.RealtimeBounces);
                    }
                }
            }

            // Display information message about CPU usage.
            int    realTimeThreads = (int)Mathf.Max(1, (steamAudioManager.simulationValue.RealtimeThreadsPercentage * SystemInfo.processorCount) / 100.0f);
            int    bakingThreads   = (int)Mathf.Max(1, (steamAudioManager.simulationValue.BakeThreadsPercentage * SystemInfo.processorCount) / 100.0f);
            string realTimeString  = (realTimeThreads == 1) ? "1 of " + SystemInfo.processorCount + " logical processor" :
                                     realTimeThreads + " of " + SystemInfo.processorCount + " logical processors";
            string bakingString = (bakingThreads == 1) ? "1 of " + SystemInfo.processorCount + " logical processor" :
                                  bakingThreads + " of " + SystemInfo.processorCount + " logical processors";

            EditorGUILayout.HelpBox("On this machine setting realtime CPU cores to " + steamAudioManager.simulationValue.RealtimeThreadsPercentage +
                                    "% will use " + realTimeString + " and setting baking CPU cores to " + steamAudioManager.simulationValue.BakeThreadsPercentage +
                                    "% will use " + bakingString + ". The number of logical processors used on an end user's machine might be different.", MessageType.Info);

            // Fold Out for Advanced Settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Advanced Options", EditorStyles.boldLabel);
            serializedObject.FindProperty("showLoadTimeOptions").boolValue =
                EditorGUILayout.Foldout(serializedObject.FindProperty("showLoadTimeOptions").boolValue,
                                        "Per Frame Query Optimization");

            if (steamAudioManager.showLoadTimeOptions)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("updateComponents"));

                var updateComponents = serializedObject.FindProperty("updateComponents").boolValue;
                if (!updateComponents)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("currentAudioListener"));
                }
            }

            serializedObject.FindProperty("showMassBakingOptions").boolValue =
                EditorGUILayout.Foldout(serializedObject.FindProperty("showMassBakingOptions").boolValue,
                                        "Consolidated Baking Options");
            if (steamAudioManager.showMassBakingOptions)
            {
                bool noSettingMessage = false;
                noSettingMessage = ProbeGenerationGUI() || noSettingMessage;
                noSettingMessage = BakeAllGUI() || noSettingMessage;
                noSettingMessage = BakedSourcesGUI(steamAudioManager) || noSettingMessage;
                noSettingMessage = BakedStaticListenerNodeGUI(steamAudioManager) || noSettingMessage;
                noSettingMessage = BakedReverbGUI(steamAudioManager) || noSettingMessage;

                if (!noSettingMessage)
                {
                    EditorGUILayout.LabelField("Scene does not contain any baking related components.");
                }
            }

            GUI.enabled = true;
            EditorGUILayout.Space();
            serializedObject.ApplyModifiedProperties();
        }