소스 검색

Adding observables to the AssetsManager

They coexist with the current success and error handling and can be used
from now on just like the old method.
Raanan Weber 8 년 전
부모
커밋
fabc4c5d5a
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      src/Tools/babylon.assetsManager.ts

+ 9 - 0
src/Tools/babylon.assetsManager.ts

@@ -263,6 +263,12 @@
         public onTaskSuccess: (task: IAssetTask) => void;
         public onTaskSuccess: (task: IAssetTask) => void;
         public onTaskError: (task: IAssetTask) => void;
         public onTaskError: (task: IAssetTask) => void;
 
 
+        //Observables
+
+        public onTaskSuccessObservable = new Observable<IAssetTask>();
+        public onTaskErrorObservable = new Observable<IAssetTask>();
+        public onTasksDoneObservable = new Observable<IAssetTask[]>();
+
         public useDefaultLoadingScreen = true;
         public useDefaultLoadingScreen = true;
 
 
         constructor(scene: Scene) {
         constructor(scene: Scene) {
@@ -336,11 +342,13 @@
                 if (this.onTaskSuccess) {
                 if (this.onTaskSuccess) {
                     this.onTaskSuccess(task);
                     this.onTaskSuccess(task);
                 }
                 }
+                this.onTaskSuccessObservable.notifyObservers(task);
                 this._decreaseWaitingTasksCount();
                 this._decreaseWaitingTasksCount();
             }, () => {
             }, () => {
                 if (this.onTaskError) {
                 if (this.onTaskError) {
                     this.onTaskError(task);
                     this.onTaskError(task);
                 }
                 }
+                this.onTaskErrorObservable.notifyObservers(task);
                 this._decreaseWaitingTasksCount();
                 this._decreaseWaitingTasksCount();
             });
             });
         }
         }
@@ -357,6 +365,7 @@
                 if (this.onFinish) {
                 if (this.onFinish) {
                     this.onFinish(this.tasks);
                     this.onFinish(this.tasks);
                 }
                 }
+                this.onTasksDoneObservable.notifyObservers(this.tasks);
                 return this;
                 return this;
             }
             }