Browse Source

enable audio in asset container

Trevor Baron 7 years ago
parent
commit
739cd84e06
2 changed files with 14 additions and 2 deletions
  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]) {
                             if (!loadedSounds[parsedSound.url]) {
                                 loadedSound = Sound.Parse(parsedSound, scene, rootUrl);
                                 loadedSound = Sound.Parse(parsedSound, scene, rootUrl);
                                 loadedSounds[parsedSound.url] = loadedSound;
                                 loadedSounds[parsedSound.url] = loadedSound;
+                                container.sounds.push(loadedSound);
                             }
                             }
                             else {
                             else {
-                                Sound.Parse(parsedSound, scene, rootUrl, loadedSounds[parsedSound.url]);
+                                container.sounds.push(Sound.Parse(parsedSound, scene, rootUrl, loadedSounds[parsedSound.url]));
                             }
                             }
                         } else {
                         } 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 lensFlareSystems = new Array<LensFlareSystem>();
         public shadowGenerators = new Array<ShadowGenerator>();
         public shadowGenerators = new Array<ShadowGenerator>();
         public actionManagers = new Array<ActionManager>();
         public actionManagers = new Array<ActionManager>();
+        public sounds = new Array<Sound>();
         
         
         constructor(scene:Scene){
         constructor(scene:Scene){
             this.scene = scene;
             this.scene = scene;
@@ -62,6 +63,11 @@ module BABYLON {
             this.actionManagers.forEach((o)=>{
             this.actionManagers.forEach((o)=>{
                 this.scene.addActionManager(o);
                 this.scene.addActionManager(o);
             });
             });
+            this.sounds.forEach((o)=>{
+                o.play();
+                o.autoplay=true;
+                this.scene.mainSoundTrack.AddSound(o)
+            })
         }
         }
         removeAllFromScene(){
         removeAllFromScene(){
             this.cameras.forEach((o)=>{
             this.cameras.forEach((o)=>{
@@ -104,6 +110,11 @@ module BABYLON {
                 this.scene.removeActionManager(o);
                 this.scene.removeActionManager(o);
             });
             });
             // TODO, do shadow generators need to be removed somehow?
             // TODO, do shadow generators need to be removed somehow?
+            this.sounds.forEach((o)=>{
+                o.stop();
+                o.autoplay = false
+                this.scene.mainSoundTrack.RemoveSound(o)
+            })
         }
         }
     }
     }
 }
 }