瀏覽代碼

enable audio in asset container

Trevor Baron 7 年之前
父節點
當前提交
739cd84e06
共有 2 個文件被更改,包括 14 次插入2 次删除
  1. 3 2
      src/Loading/Plugins/babylon.babylonFileLoader.ts
  2. 11 0
      src/babylon.assetContainer.ts

+ 3 - 2
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -846,12 +846,13 @@
                             if (!loadedSounds[parsedSound.url]) {
                                 loadedSound = Sound.Parse(parsedSound, scene, rootUrl);
                                 loadedSounds[parsedSound.url] = loadedSound;
+                                container.sounds.push(loadedSound);
                             }
                             else {
-                                Sound.Parse(parsedSound, scene, rootUrl, loadedSounds[parsedSound.url]);
+                                container.sounds.push(Sound.Parse(parsedSound, scene, rootUrl, loadedSounds[parsedSound.url]));
                             }
                         } else {
-                            new Sound(parsedSound.name, null, scene);
+                            container.sounds.push(new Sound(parsedSound.name, null, scene));
                         }
                     }
                 }

+ 11 - 0
src/babylon.assetContainer.ts

@@ -17,6 +17,7 @@ module BABYLON {
         public lensFlareSystems = new Array<LensFlareSystem>();
         public shadowGenerators = new Array<ShadowGenerator>();
         public actionManagers = new Array<ActionManager>();
+        public sounds = new Array<Sound>();
         
         constructor(scene:Scene){
             this.scene = scene;
@@ -62,6 +63,11 @@ module BABYLON {
             this.actionManagers.forEach((o)=>{
                 this.scene.addActionManager(o);
             });
+            this.sounds.forEach((o)=>{
+                o.play();
+                o.autoplay=true;
+                this.scene.mainSoundTrack.AddSound(o)
+            })
         }
         removeAllFromScene(){
             this.cameras.forEach((o)=>{
@@ -104,6 +110,11 @@ module BABYLON {
                 this.scene.removeActionManager(o);
             });
             // TODO, do shadow generators need to be removed somehow?
+            this.sounds.forEach((o)=>{
+                o.stop();
+                o.autoplay = false
+                this.scene.mainSoundTrack.RemoveSound(o)
+            })
         }
     }
 }