Browse Source

Simpler detach for Behaviors

David Catuhe 8 years ago
parent
commit
4d86fc42d7

File diff suppressed because it is too large
+ 6849 - 6849
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 6849 - 6849
dist/preview release/babylon.module.d.ts


+ 3 - 2
src/Behaviors/Cameras/babylon.autoRotationBehavior.ts

@@ -116,11 +116,12 @@ module BABYLON {
             });
             });
         }
         }
              
              
-        public detach(camera: ArcRotateCamera): void {
+        public detach(): void {
             let scene = this._attachedCamera.getScene();
             let scene = this._attachedCamera.getScene();
             
             
             scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);
             scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);
-            camera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
+			this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
+			this._attachedCamera = null;
 		}
 		}
 
 
 		/**
 		/**

+ 4 - 3
src/Behaviors/Cameras/babylon.bouncingBehavior.ts

@@ -90,11 +90,12 @@ module BABYLON {
             });
             });
         }
         }
         
         
-        public detach(camera: ArcRotateCamera): void {
-			camera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
+        public detach(): void {
+			this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
 			if (this._onMeshTargetChangedObserver) {
 			if (this._onMeshTargetChangedObserver) {
-				camera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);
+				this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);
 			}
 			}
+			this._attachedCamera = null;
         }
         }
 
 
         // Animations
         // Animations

+ 5 - 3
src/Behaviors/Cameras/babylon.framingBehavior.ts

@@ -181,12 +181,14 @@ module BABYLON {
             });
             });
         }
         }
              
              
-        public detach(camera: ArcRotateCamera): void {
+        public detach(): void {
             let scene = this._attachedCamera.getScene();
             let scene = this._attachedCamera.getScene();
             
             
             scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);
             scene.onPrePointerObservable.remove(this._onPrePointerObservableObserver);
-			camera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
-			camera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);
+			this._attachedCamera.onAfterCheckInputsObservable.remove(this._onAfterCheckInputsObserver);
+			this._attachedCamera.onMeshTargetChangedObservable.remove(this._onMeshTargetChangedObserver);
+
+			this._attachedCamera = null;
         }
         }
 
 
         // Framing control
         // Framing control

+ 1 - 1
src/Behaviors/babylon.behavior.ts

@@ -3,6 +3,6 @@ module BABYLON {
         name: string;
         name: string;
 
 
         attach(node: T): void;
         attach(node: T): void;
-        detach(node: T): void;
+        detach(): void;
     }
     }
 }
 }

+ 4 - 2
src/babylon.node.ts

@@ -129,7 +129,7 @@ module BABYLON {
                 return;
                 return;
             } 
             } 
 
 
-            this._behaviors[index].detach(this);
+            this._behaviors[index].detach();
             this._behaviors.splice(index, 1);
             this._behaviors.splice(index, 1);
 
 
             return this;
             return this;
@@ -411,8 +411,10 @@ module BABYLON {
 
 
             // Behaviors
             // Behaviors
             for (var behavior of this._behaviors) {
             for (var behavior of this._behaviors) {
-                behavior.detach(this);
+                behavior.detach();
             }
             }
+
+            this._behaviors = [];
         }
         }
         
         
         public static ParseAnimationRanges(node: Node, parsedNode: any, scene: Scene): void {
         public static ParseAnimationRanges(node: Node, parsedNode: any, scene: Scene): void {