mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-07 19:07:30 +08:00
优化
This commit is contained in:
@@ -59,37 +59,38 @@ export class LayerUI extends Node {
|
||||
|
||||
/**
|
||||
* 加载界面资源
|
||||
* @param vp 显示参数
|
||||
* @param uip 显示参数
|
||||
* @param bundle 远程资源包名,如果为空就是默认本地资源包
|
||||
*/
|
||||
protected async load(vp: UIParams, bundle?: string) {
|
||||
protected async load(uip: UIParams, bundle?: string) {
|
||||
// 加载界面资源超时提示
|
||||
const timerId = setTimeout(this.onLoadingTimeoutGui, oops.config.game.loadingTimeoutGui);
|
||||
|
||||
if (vp && vp.node) {
|
||||
await this.showUi(vp);
|
||||
if (uip && uip.node) {
|
||||
await this.showUi(uip);
|
||||
}
|
||||
else {
|
||||
// 优先加载配置的指定资源包中资源,如果没配置则加载默认资源包资源
|
||||
bundle = bundle || oops.res.defaultBundleName;
|
||||
const res = await oops.res.loadAsync(bundle, vp.config.prefab, Prefab);
|
||||
const res = await oops.res.loadAsync(bundle, uip.config.prefab, Prefab);
|
||||
if (res) {
|
||||
vp.node = instantiate(res);
|
||||
uip.node = instantiate(res);
|
||||
|
||||
// 是否启动真机安全区域显示
|
||||
if (vp.config.safeArea) vp.node.addComponent(SafeArea);
|
||||
if (uip.config.safeArea) uip.node.addComponent(SafeArea);
|
||||
|
||||
// 窗口事件委托
|
||||
const dc = vp.node.addComponent(LayerUIElement);
|
||||
dc.params = vp;
|
||||
const dc = uip.node.addComponent(LayerUIElement);
|
||||
dc.params = uip;
|
||||
//@ts-ignore
|
||||
dc.onCloseWindow = this.onCloseWindow.bind(this);
|
||||
|
||||
// 显示界面
|
||||
await this.showUi(vp);
|
||||
await this.showUi(uip);
|
||||
}
|
||||
else {
|
||||
console.warn(`路径为【${vp.config.prefab}】的预制加载失败`);
|
||||
this.failure(vp);
|
||||
console.warn(`路径为【${uip.config.prefab}】的预制加载失败`);
|
||||
this.failure(uip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@ import { oops } from "../../core/Oops";
|
||||
import { resLoader } from "../../core/common/loader/ResLoader";
|
||||
import { Uiid } from "../../core/gui/layer/LayerEnum";
|
||||
import { LayerUIElement, UICallbacks } from "../../core/gui/layer/LayerUIElement";
|
||||
import { UIConfig } from "../../core/gui/layer/UIConfig";
|
||||
import { ViewUtil } from "../../core/utils/ViewUtil";
|
||||
import { ecs } from "../../libs/ecs/ECS";
|
||||
import { CompType } from "../../libs/ecs/ECSModel";
|
||||
import { CCComp } from "./CCComp";
|
||||
import { CCVMParentComp } from "./CCVMParentComp";
|
||||
|
||||
export type ECSCtor<T extends ecs.Comp> = __private.__types_globals__Constructor<T> | __private.__types_globals__AbstractedConstructor<T>;
|
||||
|
||||
export class ModuleUtil {
|
||||
/**
|
||||
* 添加界面组件
|
||||
@@ -18,11 +19,7 @@ export class ModuleUtil {
|
||||
* @param uiId 界面资源编号
|
||||
* @param uiArgs 界面参数
|
||||
*/
|
||||
static addViewUi<T extends CCVMParentComp | CCComp>(
|
||||
ent: ecs.Entity,
|
||||
ctor: __private.__types_globals__Constructor<T> | __private.__types_globals__AbstractedConstructor<T>,
|
||||
uiId: number,
|
||||
uiArgs: any = null) {
|
||||
static addViewUi<T extends CCVMParentComp | CCComp>(ent: ecs.Entity, ctor: ECSCtor<T>, uiId: Uiid, uiArgs: any = null) {
|
||||
const uic: UICallbacks = {
|
||||
onAdded: (node: Node, params: any) => {
|
||||
const comp = node.getComponent(ctor) as ecs.Comp;
|
||||
@@ -41,11 +38,7 @@ export class ModuleUtil {
|
||||
* @param uiArgs 界面参数
|
||||
* @returns 界面节点
|
||||
*/
|
||||
static addViewUiAsync<T extends CCVMParentComp | CCComp>(
|
||||
ent: ecs.Entity,
|
||||
ctor: __private.__types_globals__Constructor<T> | __private.__types_globals__AbstractedConstructor<T>,
|
||||
uiId: number | UIConfig,
|
||||
uiArgs: any = null): Promise<Node | null> {
|
||||
static addViewUiAsync<T extends CCVMParentComp | CCComp>(ent: ecs.Entity, ctor: ECSCtor<T>, uiId: Uiid, uiArgs: any = null): Promise<Node | null> {
|
||||
return new Promise<Node | null>((resolve, reject) => {
|
||||
const uic: UICallbacks = {
|
||||
onAdded: (node: Node, params: any) => {
|
||||
@@ -69,12 +62,7 @@ export class ModuleUtil {
|
||||
* @param url 显示资源地址
|
||||
* @param bundleName 资源包名称
|
||||
*/
|
||||
static addView<T extends CCVMParentComp | CCComp>(
|
||||
ent: ecs.Entity,
|
||||
ctor: __private.__types_globals__Constructor<T> | __private.__types_globals__AbstractedConstructor<T>,
|
||||
parent: Node,
|
||||
url: string,
|
||||
bundleName: string = resLoader.defaultBundleName) {
|
||||
static addView<T extends CCVMParentComp | CCComp>(ent: ecs.Entity, ctor: ECSCtor<T>, parent: Node, url: string, bundleName: string = resLoader.defaultBundleName) {
|
||||
const node = ViewUtil.createPrefabNode(url, bundleName);
|
||||
const comp = node.getComponent(ctor)!;
|
||||
ent.add(comp);
|
||||
|
||||
Reference in New Issue
Block a user