public static void BeginBake(BakedDataTask[] tasks) { SteamAudioManager.Initialize(ManagerInitReason.Baking); SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false); SteamAudioStaticMesh staticMeshComponent = null; var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects(); foreach (var rootObject in rootObjects) { staticMeshComponent = rootObject.GetComponent <SteamAudioStaticMesh>(); if (staticMeshComponent) { break; } } if (staticMeshComponent == null || staticMeshComponent.asset == null) { Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name)); return; } var staticMesh = new StaticMesh(SteamAudioManager.Context, SteamAudioManager.CurrentScene, staticMeshComponent.asset); staticMesh.AddToScene(SteamAudioManager.CurrentScene); SteamAudioManager.CurrentScene.Commit(); staticMesh.Release(); sTasks = tasks; sStatus = BakeStatus.InProgress; sProgressCallback = new ProgressCallback(AdvanceProgress); #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) sProgressCallbackPointer = Marshal.GetFunctionPointerForDelegate(sProgressCallback); sProgressCallbackHandle = GCHandle.Alloc(sProgressCallbackPointer); GC.Collect(); #endif #if UNITY_EDITOR EditorApplication.update += InEditorUpdate; #endif sThread = new Thread(BakeThread); sThread.Start(); }
public void GenerateProbes() { SteamAudioManager.Initialize(ManagerInitReason.GeneratingProbes); SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false); var scene = SteamAudioManager.CurrentScene; SteamAudioStaticMesh staticMeshComponent = null; var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects(); foreach (var rootObject in rootObjects) { staticMeshComponent = rootObject.GetComponentInChildren <SteamAudioStaticMesh>(); if (staticMeshComponent) { break; } } if (staticMeshComponent == null || staticMeshComponent.asset == null) { Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name)); return; } var staticMesh = new StaticMesh(SteamAudioManager.Context, scene, staticMeshComponent.asset); staticMesh.AddToScene(scene); scene.Commit(); var probeArray = new ProbeArray(SteamAudioManager.Context); var probeGenerationParams = new ProbeGenerationParams { }; probeGenerationParams.type = placementStrategy; probeGenerationParams.spacing = horizontalSpacing; probeGenerationParams.height = heightAboveFloor; probeGenerationParams.transform = Common.TransposeMatrix(Common.ConvertTransform(gameObject.transform)); // Probe generation requires a transposed matrix. probeArray.GenerateProbes(scene, probeGenerationParams); var numProbes = probeArray.GetNumProbes(); mProbeSpheres = new Sphere[numProbes]; for (var i = 0; i < numProbes; ++i) { mProbeSpheres[i] = probeArray.GetProbe(i); } var probeBatch = new ProbeBatch(SteamAudioManager.Context); probeBatch.AddProbeArray(probeArray); probeDataSize = probeBatch.Save(GetAsset()); probeBatch.Release(); probeArray.Release(); staticMesh.Release(); SteamAudioManager.ShutDown(); DestroyImmediate(SteamAudioManager.Singleton.gameObject); ResetLayers(); Debug.Log("Generated " + mProbeSpheres.Length + " probes for game object " + gameObject.name + "."); // Redraw scene view for probes to show up instantly. #if UNITY_EDITOR SceneView.RepaintAll(); #endif }