public bool BakedReverbGUI(PhononManager phononManager) { PhononListener bakedReverb = GameObject.FindObjectOfType <PhononListener>(); if (bakedReverb == null || !bakedReverb.enableReverb || bakedReverb.reverbSimulationType != ReverbSimulationType.BakedReverb) { return(false); } PhononGUI.SectionHeader("Bake Reverb"); GUI.enabled = !PhononBaker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; EditorGUILayout.BeginHorizontal(); bakedReverb.UpdateBakedDataStatistics(); bool previousValues = bakedReverb.bakeToggle; bool newValue = GUILayout.Toggle(bakedReverb.bakeToggle, " reverb"); if (previousValues != newValue) { Undo.RecordObject(bakedReverb, "Toggled reverb in Phonon Manager"); bakedReverb.bakeToggle = newValue; } EditorGUILayout.LabelField((bakedReverb.bakedDataSize / 1000.0f).ToString("0.0") + " KB"); EditorGUILayout.EndHorizontal(); GUI.enabled = true; return(true); }
void DisplayProgressBarAndCancel() { PhononManager phononManager = serializedObject.targetObject as PhononManager; phononManager.phononBaker.DrawProgressBar(); Repaint(); }
void DisplayProgressBarAndCancel(BakedStaticListenerNode phononStaticNode, PhononManager phononManager) { if (phononManager.currentlyBakingObject == null || phononManager.currentlyBakingObject != phononStaticNode) { return; } phononStaticNode.phononBaker.DrawProgressBar(); Repaint(); }
void DisplayProgressBarAndCancel(PhononListener phononReverb, PhononManager phononManager) { if (phononManager.currentlyBakingObject == null) { return; } phononReverb.phononBaker.DrawProgressBar(); Repaint(); }
void DisplayProgressBarAndCancel(PhononSource phononSource, PhononManager phononManager) { if (phononManager.currentlyBakingObject == null || phononManager.currentlyBakingObject != phononSource) { return; } phononSource.phononBaker.DrawProgressBar(); Repaint(); }
public bool BakedSourcesGUI(PhononManager phononManager) { PhononSource[] bakedSources = GameObject.FindObjectsOfType <PhononSource>(); bool showBakedSources = false; foreach (PhononSource bakedSource in bakedSources) { if (bakedSource.enableReflections && bakedSource.uniqueIdentifier.Length != 0 && bakedSource.sourceSimulationType == SourceSimulationType.BakedStaticSource) { showBakedSources = true; break; } } if (showBakedSources) { PhononGUI.SectionHeader("Baked Sources"); } else { return(false); } foreach (PhononSource bakedSource in bakedSources) { if (!bakedSource.enableReflections || bakedSource.uniqueIdentifier.Length == 0 || bakedSource.sourceSimulationType != SourceSimulationType.BakedStaticSource) { continue; } GUI.enabled = !PhononBaker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; EditorGUILayout.BeginHorizontal(); bakedSource.UpdateBakedDataStatistics(); bool previousValue = bakedSource.bakeToggle; bool newValue = GUILayout.Toggle(bakedSource.bakeToggle, " " + bakedSource.uniqueIdentifier); if (previousValue != newValue) { Undo.RecordObject(bakedSource, "Toggled " + bakedSource.uniqueIdentifier + " in Phonon Manager"); bakedSource.bakeToggle = newValue; } EditorGUILayout.LabelField((bakedSource.bakedDataSize / 1000.0f).ToString("0.0") + " KB"); EditorGUILayout.EndHorizontal(); GUI.enabled = true; } return(true); }
// Initializes Phonon Manager Component, in particular various Phonon API handles contained within Phonon // Manager Container. Initialize will be performed only once despite repeated calls to Initialize without // calls to Destroy. public void Initialize(bool initializeRenderer, PhononManager phononManager) { if (refCounter != 0) { return; } ++refCounter; bool useOpenCL; int numComputeUnits; ComputeDeviceType deviceType; deviceType = phononManager.ComputeDeviceSettings(out numComputeUnits, out useOpenCL); SimulationSettings simulationSettings = phononManager.SimulationSettings(); GlobalContext globalContext = phononManager.GlobalContext(); RenderingSettings renderingSettings = phononManager.RenderingSettings(); try { computeDevice.Create(useOpenCL, deviceType, numComputeUnits); } catch (Exception e) { throw e; } probeManager.Create(); if (scene.Create(computeDevice, simulationSettings, globalContext) == Error.None) { try { environment.Create(computeDevice, simulationSettings, scene, probeManager, globalContext); } catch (Exception e) { throw e; } if (initializeRenderer) { environmentRenderer.Create(environment, renderingSettings, simulationSettings, globalContext); } } if (initializeRenderer) { binauralRenderer.Create(environment, renderingSettings, globalContext); } }
public bool BakedStaticListenerNodeGUI(PhononManager phononManager) { BakedStaticListenerNode[] bakedStaticNodes = GameObject.FindObjectsOfType <BakedStaticListenerNode>(); if (bakedStaticNodes.Length > 0) { PhononGUI.SectionHeader("Baked Static Listener Nodes"); } else { return(false); } foreach (BakedStaticListenerNode bakedStaticNode in bakedStaticNodes) { if (bakedStaticNode.uniqueIdentifier.Length == 0) { continue; } GUI.enabled = !bakedStaticNode.phononBaker.IsBakeActive(); EditorGUILayout.BeginHorizontal(); bakedStaticNode.UpdateBakedDataStatistics(); EditorGUILayout.LabelField("__staticlistener__" + bakedStaticNode.uniqueIdentifier, (bakedStaticNode.bakedDataSize / 1000.0f).ToString("0.0") + " KB"); if (GUILayout.Button("Bake Effect", GUILayout.Width(200.0f))) { phononManager.currentlyBakingObject = bakedStaticNode; Debug.Log("START: Baking effect for \"" + bakedStaticNode.uniqueIdentifier + "\"."); bakedStaticNode.BeginBake(); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; DisplayProgressBarAndCancel(bakedStaticNode, phononManager); if (bakedStaticNode.phononBaker.GetBakeStatus() == BakeStatus.Complete) { bakedStaticNode.EndBake(); phononManager.currentlyBakingObject = null; EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); Debug.Log("COMPLETED: Baking effect for \"" + bakedStaticNode.uniqueIdentifier + "\"."); } } return(true); }
public bool BakedReverbGUI(PhononManager phononManager) { PhononListener bakedReverb = GameObject.FindObjectOfType <PhononListener>(); if (bakedReverb == null || !bakedReverb.enableReverb || bakedReverb.reverbSimulationType != ReverbSimulationType.BakedReverb) { return(false); } PhononGUI.SectionHeader("Bake Reverb"); GUI.enabled = !bakedReverb.phononBaker.IsBakeActive(); EditorGUILayout.BeginHorizontal(); bakedReverb.UpdateBakedDataStatistics(); EditorGUILayout.LabelField("__reverb__", (bakedReverb.bakedDataSize / 1000.0f).ToString("0.0") + " KB"); if (GUILayout.Button("Bake Reverb", GUILayout.Width(200.0f))) { Debug.Log("START: Baking reverb effect."); phononManager.currentlyBakingObject = bakedReverb; bakedReverb.BeginBake(); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; DisplayProgressBarAndCancel(bakedReverb, phononManager); if (bakedReverb.phononBaker.GetBakeStatus() == BakeStatus.Complete) { bakedReverb.EndBake(); phononManager.currentlyBakingObject = null; EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); Debug.Log("COMPLETED: Baking reverb effect."); } return(true); }
// // Draws the inspector. // public override void OnInspectorGUI() { serializedObject.Update(); // Audio Engine PhononGUI.SectionHeader("Audio Engine Integration"); string[] engines = { "Unity Audio" }; var audioEngineProperty = serializedObject.FindProperty("audioEngine"); audioEngineProperty.enumValueIndex = EditorGUILayout.Popup("Audio Engine", audioEngineProperty.enumValueIndex, engines); // Scene Settings PhononManager phononManager = ((PhononManager)target); PhononGUI.SectionHeader("Global Material Settings"); EditorGUILayout.PropertyField(serializedObject.FindProperty("materialPreset")); if (serializedObject.FindProperty("materialPreset").enumValueIndex < 11) { PhononMaterialValue actualValue = phononManager.materialValue; actualValue.CopyFrom(PhononMaterialPresetList.PresetValue(serializedObject.FindProperty("materialPreset").enumValueIndex)); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("materialValue")); } PhononGUI.SectionHeader("Scene Export"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); bool exportOBJ = false; bool exportScene = false; if (GUILayout.Button("Export to OBJ")) { exportOBJ = true; } if (GUILayout.Button("Pre-Export Scene")) { exportScene = true; } if (exportOBJ || exportScene) { if (exportScene) { phononManager.ExportScene(); } if (exportOBJ) { phononManager.DumpScene(); } } EditorGUILayout.EndHorizontal(); // Simulation Settings PhononGUI.SectionHeader("Simulation Settings"); EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationPreset")); if (serializedObject.FindProperty("simulationPreset").enumValueIndex < 3) { SimulationSettingsValue actualValue = phononManager.simulationValue; actualValue.CopyFrom(SimulationSettingsPresetList.PresetValue(serializedObject.FindProperty("simulationPreset").enumValueIndex)); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationValue")); if (Application.isEditor && EditorApplication.isPlayingOrWillChangePlaymode) { SimulationSettingsValue actualValue = phononManager.simulationValue; IntPtr environment = phononManager.PhononManagerContainer().Environment().GetEnvironment(); if (environment != IntPtr.Zero) { PhononCore.iplSetNumBounces(environment, actualValue.RealtimeBounces); } } } EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
// // Draws the inspector. // public override void OnInspectorGUI() { serializedObject.Update(); // Audio Engine PhononGUI.SectionHeader("Audio Engine Integration"); string[] engines = { "Unity Audio" }; var audioEngineProperty = serializedObject.FindProperty("audioEngine"); audioEngineProperty.enumValueIndex = EditorGUILayout.Popup("Audio Engine", audioEngineProperty.enumValueIndex, engines); // Scene Settings PhononManager phononManager = ((PhononManager)target); PhononGUI.SectionHeader("Global Material Settings"); EditorGUILayout.PropertyField(serializedObject.FindProperty("materialPreset")); if (serializedObject.FindProperty("materialPreset").enumValueIndex < 11) { PhononMaterialValue actualValue = phononManager.materialValue; actualValue.CopyFrom(PhononMaterialPresetList.PresetValue(serializedObject.FindProperty("materialPreset").enumValueIndex)); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("materialValue")); } PhononGUI.SectionHeader("Scene Export"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("Export to OBJ")) { phononManager.ExportScene(true); } if (GUILayout.Button("Pre-Export Scene")) { phononManager.ExportScene(false); } EditorGUILayout.EndHorizontal(); // Simulation Settings PhononGUI.SectionHeader("Simulation Settings"); EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationPreset")); if (serializedObject.FindProperty("simulationPreset").enumValueIndex < 3) { SimulationSettingsValue actualValue = phononManager.simulationValue; actualValue.CopyFrom(SimulationSettingsPresetList.PresetValue(serializedObject.FindProperty("simulationPreset").enumValueIndex)); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty("simulationValue")); if (Application.isEditor && EditorApplication.isPlayingOrWillChangePlaymode) { SimulationSettingsValue actualValue = phononManager.simulationValue; IntPtr environment = phononManager.PhononManagerContainer().Environment().GetEnvironment(); if (environment != IntPtr.Zero) { PhononCore.iplSetNumBounces(environment, actualValue.RealtimeBounces); } } } // Fold Out for Advanced Settings PhononGUI.SectionHeader("Advanced Options"); phononManager.showLoadTimeOptions = EditorGUILayout.Foldout(phononManager.showLoadTimeOptions, "Per Frame Query Optimization"); if (phononManager.showLoadTimeOptions) { EditorGUILayout.PropertyField(serializedObject.FindProperty("updateComponents")); } phononManager.showMassBakingOptions = EditorGUILayout.Foldout(phononManager.showMassBakingOptions, "Consolidated Baking Options"); if (phononManager.showMassBakingOptions) { bool noSettingMessage = false; noSettingMessage = ProbeGenerationGUI() || noSettingMessage; noSettingMessage = BakedSourcesGUI(phononManager) || noSettingMessage; noSettingMessage = BakedReverbGUI(phononManager) || noSettingMessage; noSettingMessage = BakedStaticListenerNodeGUI(phononManager) || noSettingMessage; if (!noSettingMessage) { EditorGUILayout.LabelField("Scene does not contain any baking related components."); } } EditorGUILayout.HelpBox("Do not manually add Phonon Manager component. Click Window > Phonon.", MessageType.Info); EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
public bool BakedSourcesGUI(PhononManager phononManager) { PhononSource[] bakedSources = GameObject.FindObjectsOfType <PhononSource>(); bool showBakedSources = false; foreach (PhononSource bakedSource in bakedSources) { if (bakedSource.enableReflections && bakedSource.uniqueIdentifier.Length != 0 && bakedSource.sourceSimulationType == SourceSimulationType.BakedStaticSource) { showBakedSources = true; break; } } if (showBakedSources) { PhononGUI.SectionHeader("Baked Sources"); } else { return(false); } foreach (PhononSource bakedSource in bakedSources) { if (!bakedSource.enableReflections || bakedSource.uniqueIdentifier.Length == 0 || bakedSource.sourceSimulationType != SourceSimulationType.BakedStaticSource) { continue; } GUI.enabled = !bakedSource.phononBaker.IsBakeActive(); EditorGUILayout.BeginHorizontal(); bakedSource.UpdateBakedDataStatistics(); EditorGUILayout.LabelField(bakedSource.uniqueIdentifier, (bakedSource.bakedDataSize / 1000.0f).ToString("0.0") + " KB"); if (GUILayout.Button("Bake Effect", GUILayout.Width(200.0f))) { phononManager.currentlyBakingObject = bakedSource; Debug.Log("START: Baking effect for \"" + bakedSource.uniqueIdentifier + "\" with influence radius of " + bakedSource.bakingRadius + " meters."); bakedSource.BeginBake(); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; DisplayProgressBarAndCancel(bakedSource, phononManager); if (bakedSource.phononBaker.GetBakeStatus() == BakeStatus.Complete) { bakedSource.EndBake(); phononManager.currentlyBakingObject = null; EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); Debug.Log("COMPLETED: Baking effect for \"" + bakedSource.uniqueIdentifier + "\" with influence radius of " + bakedSource.bakingRadius + " meters."); } } return(true); }
public void BakeSelected() { List <GameObject> gameObjects = new List <GameObject>(); List <BakingMode> bakingModes = new List <BakingMode>(); List <string> identifers = new List <string>(); List <Sphere> influenceSpheres = new List <Sphere>(); List <ProbeBox[]> probeBoxes = new List <ProbeBox[]>(); PhononSource[] bakedSources = GameObject.FindObjectsOfType <PhononSource>(); foreach (PhononSource bakedSource in bakedSources) { if (bakedSource.enableReflections && bakedSource.uniqueIdentifier.Length != 0 && bakedSource.sourceSimulationType == SourceSimulationType.BakedStaticSource && bakedSource.bakeToggle) { gameObjects.Add(bakedSource.gameObject); bakingModes.Add(BakingMode.StaticSource); identifers.Add(bakedSource.uniqueIdentifier); Sphere bakeSphere; Vector3 sphereCenter = Common.ConvertVector(bakedSource.transform.position); bakeSphere.centerx = sphereCenter.x; bakeSphere.centery = sphereCenter.y; bakeSphere.centerz = sphereCenter.z; bakeSphere.radius = bakedSource.bakingRadius; influenceSpheres.Add(bakeSphere); if (bakedSource.useAllProbeBoxes) { probeBoxes.Add(FindObjectsOfType <ProbeBox>() as ProbeBox[]); } else { probeBoxes.Add(bakedSource.probeBoxes); } } } BakedStaticListenerNode[] bakedStaticNodes = GameObject.FindObjectsOfType <BakedStaticListenerNode>(); foreach (BakedStaticListenerNode bakedStaticNode in bakedStaticNodes) { if (bakedStaticNode.uniqueIdentifier.Length != 0 && bakedStaticNode.bakeToggle) { gameObjects.Add(bakedStaticNode.gameObject); bakingModes.Add(BakingMode.StaticListener); identifers.Add(bakedStaticNode.uniqueIdentifier); Sphere bakeSphere; Vector3 sphereCenter = Common.ConvertVector(bakedStaticNode.transform.position); bakeSphere.centerx = sphereCenter.x; bakeSphere.centery = sphereCenter.y; bakeSphere.centerz = sphereCenter.z; bakeSphere.radius = bakedStaticNode.bakingRadius; influenceSpheres.Add(bakeSphere); if (bakedStaticNode.useAllProbeBoxes) { probeBoxes.Add(FindObjectsOfType <ProbeBox>() as ProbeBox[]); } else { probeBoxes.Add(bakedStaticNode.probeBoxes); } } } PhononListener bakedReverb = GameObject.FindObjectOfType <PhononListener>(); if (!(bakedReverb == null || !bakedReverb.enableReverb || bakedReverb.reverbSimulationType != ReverbSimulationType.BakedReverb) && bakedReverb.bakeToggle) { gameObjects.Add(bakedReverb.gameObject); bakingModes.Add(BakingMode.Reverb); identifers.Add("__reverb__"); influenceSpheres.Add(new Sphere()); if (bakedReverb.useAllProbeBoxes) { probeBoxes.Add(FindObjectsOfType <ProbeBox>() as ProbeBox[]); } else { probeBoxes.Add(bakedReverb.probeBoxes); } } if (gameObjects.Count > 0) { PhononManager phononManager = serializedObject.targetObject as PhononManager; phononManager.phononBaker.BeginBake(gameObjects.ToArray(), bakingModes.ToArray(), identifers.ToArray(), influenceSpheres.ToArray(), probeBoxes.ToArray()); } else { Debug.LogWarning("No game object selected for baking."); } }