This commit is contained in:
donggang
2024-02-27 15:06:40 +08:00
parent d038d14ec8
commit eb74f2874d
2 changed files with 23 additions and 3 deletions

View File

@@ -195,8 +195,8 @@ export class LayerManager {
* @param uiArgs 新打开场景参数
*/
replace(removeUiId: number, openUiId: number, uiArgs: any = null) {
this.remove(removeUiId);
this.open(openUiId, uiArgs);
this.remove(removeUiId);
}
/**
@@ -206,8 +206,11 @@ export class LayerManager {
* @param uiArgs 新打开场景参数
*/
replaceAsync(removeUiId: number, openUiId: number, uiArgs: any = null): Promise<Node | null> {
this.remove(removeUiId);
return this.openAsync(openUiId, uiArgs);
return new Promise<Node | null>(async (resolve, reject) => {
var node = await this.openAsync(openUiId, uiArgs);
this.remove(removeUiId);
resolve(node);
});
}
/**

View File

@@ -21,6 +21,23 @@ export class ModuleUtil {
oops.gui.open(uiId, uiArgs, uic);
}
public static addViewAsync<T extends CCVMParentComp | CCComp>(
ent: ecs.Entity,
ctor: __private._types_globals__Constructor<T> | __private._types_globals__AbstractedConstructor<T>,
uiId: number,
uiArgs: any = null): Promise<Node | null> {
return new Promise<Node | null>((resolve, reject) => {
var uic: UICallbacks = {
onAdded: (node: Node, params: any) => {
var comp = node.getComponent(ctor) as ecs.Comp;
ent.add(comp);
resolve(node);
}
};
oops.gui.open(uiId, uiArgs, uic);
});
}
public static removeView(ent: ecs.Entity, ctor: CompType<ecs.IComp>, uiId: number, isDestroy: boolean = true) {
ent.remove(ctor);
oops.gui.remove(uiId, isDestroy);