cocos creator从零开发简单框架(21)-Panel接口完善

编辑framework/scripts/view/PanelMgr.ts,增加isAliveupdateView,hideAll方法。

// 判断 Panel 是否打开
public static isAlive(panelCls: any): boolean {
    const viewName = AppUtil.getClassName(panelCls)

    return this._panels.has(viewName) && this._panels.get(viewName).skin.active
}

// 更新 Panel
public static updateView(panelCls: any, ...args: any[]) {
    const viewName = AppUtil.getClassName(panelCls)

    if (!this.isAlive(panelCls)) {
        console.error('PanelMgr.updateView [%s] 更新 view 失败, 未打开或未激活', viewName)
        return
    }

    this._panels.get(viewName).updateView(args)
}

// 隐藏 Panel
// ...... 省略代码 ......

// 隐藏所有 Panel
public static hideAll() {
    this._panels.forEach(panel => {
        if (panel.skin.active) {
            this.destroy(panel.panelName)
        }
    })
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!