소스 검색

Lazy loading

sebastien 7 년 전
부모
커밋
5e8710a40b
1개의 변경된 파일34개의 추가작업 그리고 20개의 파일을 삭제
  1. 34 20
      src/Audio/babylon.audioSceneComponent.ts

+ 34 - 20
src/Audio/babylon.audioSceneComponent.ts

@@ -73,6 +73,12 @@ module BABYLON {
 
     Object.defineProperty(Scene.prototype, "mainSoundTrack", {
         get: function (this:Scene) {
+            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
+            if (!compo) {
+                compo = new AudioSceneComponent(this);
+                this._addComponent(compo);
+            }
+
             if (!this._mainSoundTrack) {
                 this._mainSoundTrack = new SoundTrack(this, { mainTrack: true });
             }
@@ -106,22 +112,26 @@ module BABYLON {
 
     Object.defineProperty(Scene.prototype, "audioEnabled", {
         get: function (this:Scene) {
-            const compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
+            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
             if (!compo) {
-                return false;
+                compo = new AudioSceneComponent(this);
+                this._addComponent(compo);
             }
 
             return compo.audioEnabled;
         },
         set: function(this:Scene, value: boolean) {
-            const compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
-            if (compo) {
-                if (value) {
-                    compo.enableAudio();
-                }
-                else {
-                    compo.disableAudio();
-                }
+            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
+            if (!compo) {
+                compo = new AudioSceneComponent(this);
+                this._addComponent(compo);
+            }
+
+            if (value) {
+                compo.enableAudio();
+            }
+            else {
+                compo.disableAudio();
             }
         },
         enumerable: true,
@@ -130,22 +140,26 @@ module BABYLON {
 
     Object.defineProperty(Scene.prototype, "headphone", {
         get: function (this:Scene) {
-            const compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
+            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
             if (!compo) {
-                return false;
+                compo = new AudioSceneComponent(this);
+                this._addComponent(compo);
             }
 
             return compo.headphone;
         },
         set: function(this:Scene, value: boolean) {
-            const compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
-            if (compo) {
-                if (value) {
-                    compo.switchAudioModeForHeadphones();
-                }
-                else {
-                    compo.switchAudioModeForNormalSpeakers();
-                }
+            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
+            if (!compo) {
+                compo = new AudioSceneComponent(this);
+                this._addComponent(compo);
+            }
+            
+            if (value) {
+                compo.switchAudioModeForHeadphones();
+            }
+            else {
+                compo.switchAudioModeForNormalSpeakers();
             }
         },
         enumerable: true,