需求:在写一个框架,场景初始化之前,加载一些资源,创建一些节点(随便举个例子,框架根据不同情况,创建一个UI来显示一张图片,图片动态加载出来)。但所有这些操作都需要在所有场景节点onLoad之前完成。
目前看到director.runSceneImmediate事实上是有抛两个事件出来的。引擎代码如下:
if (onBeforeLoadScene) {
onBeforeLoadScene();
}
this.emit(Director.EVENT_BEFORE_SCENE_LAUNCH, scene);
// Run an Entity Scene
this._scene = scene;
if (BUILD && DEBUG) {
console.time('Activate');
}
// @ts-expect-error run private method
scene._activate();
if (BUILD && DEBUG) {
console.timeEnd('Activate');
}
// start scene
if (this._root) {
this._root.resetCumulativeTime();
}
this.startAnimation();
if (onLaunched) {
onLaunched(null, scene);
}
this.emit(Director.EVENT_AFTER_SCENE_LAUNCH, scene);
请问这边可以支持一个异步事件或者是函数吗。就跟GAME.onPostProjectInitDelegate这种也可以。让开发人员可以在场景节点active之前自己处理一些事件,同时还能拿到scene对象,对场景提前做一些操作。