2020-06-21 10:27:15 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
|
|
|
|
|
|
*/
|
|
|
|
|
|
abstract class SceneTransition {
|
2020-06-22 15:27:58 +08:00
|
|
|
|
private _hasPreviousSceneRender: boolean;
|
2020-06-21 10:27:15 +08:00
|
|
|
|
/** 是否加载新场景的标志 */
|
|
|
|
|
|
public loadsNewScene: boolean;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 将此用于两个部分的转换。例如,淡出会先淡出到黑色,然后当isNewSceneLoaded为true,它会淡出。
|
|
|
|
|
|
* 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。
|
|
|
|
|
|
*/
|
|
|
|
|
|
public isNewSceneLoaded: boolean;
|
|
|
|
|
|
/** 返回新加载场景的函数 */
|
|
|
|
|
|
protected sceneLoadAction: Function;
|
|
|
|
|
|
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
|
|
|
|
|
|
public onScreenObscured: Function;
|
|
|
|
|
|
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
|
|
|
|
|
|
public onTransitionCompleted: Function;
|
|
|
|
|
|
|
2020-06-22 15:27:58 +08:00
|
|
|
|
public get hasPreviousSceneRender(){
|
|
|
|
|
|
if (!this._hasPreviousSceneRender){
|
2020-06-21 10:27:15 +08:00
|
|
|
|
this._hasPreviousSceneRender = true;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-22 15:27:58 +08:00
|
|
|
|
constructor(sceneLoadAction: Function) {
|
|
|
|
|
|
this.sceneLoadAction = sceneLoadAction;
|
|
|
|
|
|
this.loadsNewScene = sceneLoadAction != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-21 10:27:15 +08:00
|
|
|
|
public preRender() { }
|
|
|
|
|
|
|
2020-06-22 15:27:58 +08:00
|
|
|
|
public render() {
|
|
|
|
|
|
|
2020-06-21 10:27:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-22 15:27:58 +08:00
|
|
|
|
public onBeginTransition() {
|
|
|
|
|
|
this.loadNextScene();
|
|
|
|
|
|
this.transitionComplete();
|
2020-06-21 10:27:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected transitionComplete() {
|
|
|
|
|
|
SceneManager.sceneTransition = null;
|
|
|
|
|
|
|
2020-06-22 15:27:58 +08:00
|
|
|
|
if (this.onTransitionCompleted) {
|
2020-06-21 10:27:15 +08:00
|
|
|
|
this.onTransitionCompleted();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-22 15:27:58 +08:00
|
|
|
|
protected loadNextScene() {
|
|
|
|
|
|
if (this.onScreenObscured)
|
|
|
|
|
|
this.onScreenObscured();
|
2020-06-21 10:27:15 +08:00
|
|
|
|
|
2020-06-22 15:27:58 +08:00
|
|
|
|
if (!this.loadsNewScene) {
|
2020-06-21 10:27:15 +08:00
|
|
|
|
this.isNewSceneLoaded = true;
|
2020-06-22 15:27:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SceneManager.scene = this.sceneLoadAction();
|
|
|
|
|
|
this.isNewSceneLoaded = true;
|
2020-06-21 10:27:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|