コード例 #1
0
        public void DeleteBakedDataByIdentifier(BakedDataIdentifier identifier)
        {
            SteamAudioManager steamAudioManager = null;
            IntPtr            probeBox          = IntPtr.Zero;

            try
            {
                steamAudioManager = FindObjectOfType <SteamAudioManager>();
                if (steamAudioManager == null)
                {
                    throw new Exception("Phonon Manager Settings object not found in the scene! Click Window > Phonon");
                }

                steamAudioManager.Initialize(GameEngineStateInitReason.EditingProbes);
                var context = steamAudioManager.GameEngineState().Context();

                byte[] probeBoxData = LoadData();
                PhononCore.iplLoadProbeBox(context, probeBoxData, probeBoxData.Length, ref probeBox);
                PhononCore.iplDeleteBakedDataByIdentifier(probeBox, identifier);
                RemoveLayer(identifier);

                int probeBoxSize = PhononCore.iplSaveProbeBox(probeBox, null);
                probeBoxData = new byte[probeBoxSize];
                PhononCore.iplSaveProbeBox(probeBox, probeBoxData);
                SaveData(probeBoxData);

                steamAudioManager.Destroy();
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
        }
コード例 #2
0
        void Awake()
        {
            manager = SteamAudioManager.GetSingleton();
            if (manager == null)
            {
                throw new Exception();
            }
            manager.Initialize(GameEngineStateInitReason.Playing);

            if (assetFileName != null && assetFileName.Length > 0)
            {
                manager.CreateInstancedMesh(assetFileName, transform, ref instancedMesh);
            }
        }
コード例 #3
0
ファイル: Baker.cs プロジェクト: gomez-addams/steam-audio
        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();
        }
コード例 #4
0
        public void DeleteBakedDataForIdentifier(BakedDataIdentifier identifier)
        {
            if (asset == null)
            {
                return;
            }

            SteamAudioManager.Initialize(ManagerInitReason.EditingProbes);

            var probeBatch = new ProbeBatch(SteamAudioManager.Context, asset);

            probeBatch.RemoveData(identifier);
            probeDataSize = probeBatch.Save(asset);

            SteamAudioManager.ShutDown();
            DestroyImmediate(SteamAudioManager.Singleton.gameObject);

            RemoveLayer(identifier);
        }
コード例 #5
0
        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
        }
コード例 #6
0
        public void GenerateProbes()
        {
            ProbePlacementParameters placementParameters;

            placementParameters.placement         = placementStrategy;
            placementParameters.maxNumTriangles   = maxNumTriangles;
            placementParameters.maxOctreeDepth    = maxOctreeDepth;
            placementParameters.horizontalSpacing = horizontalSpacing;
            placementParameters.heightAboveFloor  = heightAboveFloor;

            // Initialize environment
            SteamAudioManager steamAudioManager = null;

            try
            {
                steamAudioManager = FindObjectOfType <SteamAudioManager>();
                if (steamAudioManager == null)
                {
                    throw new Exception("Phonon Manager Settings object not found in the scene! Click Window > Phonon");
                }

                steamAudioManager.Initialize(GameEngineStateInitReason.GeneratingProbes);

                if (steamAudioManager.GameEngineState().Scene().GetScene() == IntPtr.Zero)
                {
                    Debug.LogError("Scene not found. Make sure to pre-export the scene.");
                    steamAudioManager.Destroy();
                    return;
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                return;
            }

            // Create bounding box for the probe.
            IntPtr probeBox = IntPtr.Zero;

            PhononCore.iplCreateProbeBox(steamAudioManager.GameEngineState().Context(), steamAudioManager.GameEngineState().Scene().GetScene(),
                                         Common.ConvertMatrix(gameObject.transform.localToWorldMatrix), placementParameters, null, ref probeBox);

            int numProbes = PhononCore.iplGetProbeSpheres(probeBox, null);

            probeSpherePoints = new float[3 * numProbes];
            probeSphereRadii  = new float[numProbes];

            Sphere[] probeSpheres = new Sphere[numProbes];
            PhononCore.iplGetProbeSpheres(probeBox, probeSpheres);
            for (int i = 0; i < numProbes; ++i)
            {
                probeSpherePoints[3 * i + 0] = probeSpheres[i].centerx;
                probeSpherePoints[3 * i + 1] = probeSpheres[i].centery;
                probeSpherePoints[3 * i + 2] = probeSpheres[i].centerz;
                probeSphereRadii[i]          = probeSpheres[i].radius;
            }

            // Save probe box into searlized data;
            int probeBoxSize = PhononCore.iplSaveProbeBox(probeBox, null);

            probeBoxData = new byte[probeBoxSize];
            PhononCore.iplSaveProbeBox(probeBox, probeBoxData);

            if (steamAudioManager.GameEngineState().Scene().GetScene() != IntPtr.Zero)
            {
                Debug.Log("Generated " + probeSpheres.Length + " probes for game object " + gameObject.name + ".");
            }

            // Cleanup.
            PhononCore.iplDestroyProbeBox(ref probeBox);
            steamAudioManager.Destroy();
            ClearProbeDataMapping();

            // Redraw scene view for probes to show up instantly.
#if UNITY_EDITOR
            UnityEditor.SceneView.RepaintAll();
#endif
        }