Files
esengine/source/src/ECS/SceneTransition.ts

97 lines
3.2 KiB
TypeScript
Raw Normal View History

2022-03-12 23:49:14 +08:00
module es {
/**
* SceneTransition用于从一个场景过渡到另一个场景
* sceneLoadAction为null
*/
export abstract class SceneTransition {
/** 该函数应返回新加载的场景 */
protected sceneLoadAction: () => Scene;
/**
* loadNextScene执行时调用
*
*/
public onScreenObscured: Function;
/**
* 便
*/
public onTransitionCompleted: Function;
/**
*
*/
public _loadsNewScene: boolean = false;
private _hasPreviousSceneRender: boolean = false;
public get hasPreviousSceneRender() {
if (!this._hasPreviousSceneRender) {
this._hasPreviousSceneRender = true;
return false;
}
return true;
}
/**
* _isNewSceneLoaded变为true时会褪色
* isNewSceneLoaded设置为true
*/
public _isNewSceneLoaded: boolean = false;
protected constructor(sceneLoadAction: () => Scene) {
this.sceneLoadAction = sceneLoadAction;
this._loadsNewScene = sceneLoadAction != null;
}
protected * LoadNextScene() {
// 如果我们有渲染界面,可以在这让玩家知道屏幕是模糊的(正在加载)
if (this.onScreenObscured != null)
this.onScreenObscured();
// 如果我们不加载一个新场景,我们只需设置标志
if (!this._loadsNewScene) {
this._isNewSceneLoaded = true;
yield "break";
}
Core.scene = this.sceneLoadAction();
this._isNewSceneLoaded = true;
while (!this._isNewSceneLoaded)
yield null;
}
/**
*
*
*/
public * onBeginTransition(): any {
yield null;
yield Core.startCoroutine(this.LoadNextScene());
this.transitionComplete();
}
/**
*
*/
public preRender() { }
/**
*
*/
public render() { }
/**
*
*/
protected transitionComplete() {
Core.Instance._sceneTransition = null;
if (this.onTransitionCompleted != null)
this.onTransitionCompleted();
}
}
}