Procházet zdrojové kódy

Migrate debug layer to component

sebastien před 7 roky
rodič
revize
76241a86ac
2 změnil soubory, kde provedl 31 přidání a 18 odebrání
  1. 31 0
      src/Debug/babylon.debugLayer.ts
  2. 0 18
      src/babylon.scene.ts

+ 31 - 0
src/Debug/babylon.debugLayer.ts

@@ -4,6 +4,31 @@ module BABYLON {
     declare var INSPECTOR: any;
     // load the inspector using require, if not present in the global namespace.
 
+    export interface Scene {
+        /**
+         * @hidden
+         * Backing field
+         */
+        _debugLayer: DebugLayer;
+
+        /**
+         * Gets the debug layer (aka Inspector) associated with the scene
+         * @see http://doc.babylonjs.com/features/playground_debuglayer
+         */
+        debugLayer: DebugLayer;
+    }
+    
+    Object.defineProperty(Scene.prototype, "debugLayer", {
+        get: function (this: Scene) {
+            if (!this._debugLayer) {
+                this._debugLayer = new DebugLayer(this);
+            }
+            return this._debugLayer;
+        },
+        enumerable: true,
+        configurable: true
+    });
+
     export class DebugLayer {
         private _scene: Scene;
         public static InspectorURL = 'https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js';
@@ -16,6 +41,12 @@ module BABYLON {
 
         constructor(scene: Scene) {
             this._scene = scene;
+            this._scene.onDisposeObservable.add(() => {
+                // Debug layer
+                if (this._scene._debugLayer) {
+                    this._scene._debugLayer.hide();
+                }
+            })
         }
 
         /** Creates the inspector window. */

+ 0 - 18
src/babylon.scene.ts

@@ -1011,8 +1011,6 @@
 
         private _pointerOverMesh: Nullable<AbstractMesh>;
 
-        private _debugLayer: DebugLayer;
-
         private _pickedDownMesh: Nullable<AbstractMesh>;
         private _pickedUpMesh: Nullable<AbstractMesh>;
         private _externalData: StringDictionary<Object>;
@@ -1242,17 +1240,6 @@
             this.getCollidingSubMeshCandidates = this._getDefaultSubMeshCandidates.bind(this);
         }
 
-        /**
-         * Gets the debug layer (aka Inspector) associated with the scene
-         * @see http://doc.babylonjs.com/features/playground_debuglayer
-         */
-        public get debugLayer(): DebugLayer {
-            if (!this._debugLayer) {
-                this._debugLayer = new DebugLayer(this);
-            }
-            return this._debugLayer;
-        }
-
         public set workerCollisions(enabled: boolean) {
             if (!CollisionCoordinatorLegacy) {
                 return;
@@ -4811,11 +4798,6 @@
                 request.abort();
             }
 
-            // Debug layer
-            if (this._debugLayer) {
-                this._debugLayer.hide();
-            }
-
             // Events
             this.onDisposeObservable.notifyObservers(this);