浏览代码

Add disposable event on controls.

sebavan 5 年之前
父节点
当前提交
1a8e6a99ee
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      gui/src/2D/controls/control.ts

+ 9 - 0
gui/src/2D/controls/control.ts

@@ -281,6 +281,11 @@ export class Control {
     public onAfterDrawObservable = new Observable<Control>();
     public onAfterDrawObservable = new Observable<Control>();
 
 
     /**
     /**
+    * An event triggered when the control has been disposed
+    */
+   public onDisposeObservable = new Observable<Control>();
+
+    /**
      * Get the hosting AdvancedDynamicTexture
      * Get the hosting AdvancedDynamicTexture
      */
      */
     public get host(): AdvancedDynamicTexture {
     public get host(): AdvancedDynamicTexture {
@@ -1914,6 +1919,10 @@ export class Control {
                 this.linkWithMesh(null);
                 this.linkWithMesh(null);
             }
             }
         }
         }
+
+        // Callback
+        this.onDisposeObservable.notifyObservers(this);
+        this.onDisposeObservable.clear();
     }
     }
 
 
     // Statics
     // Statics