Files
Alien_Sniper/temp/programming/packer-driver/targets/preview/chunks/63/63a64431b6b21cd924e8e7464d636fa810675c73.js
T
2026-07-14 11:44:07 +08:00

119 lines
4.0 KiB
JavaScript

System.register(["cc"], function (_export, _context) {
"use strict";
var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, resources, instantiate, Prefab, js, _dec, _class, _crd, ccclass, property, PanelBase;
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
return {
setters: [function (_cc) {
_cclegacy = _cc.cclegacy;
__checkObsolete__ = _cc.__checkObsolete__;
__checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
_decorator = _cc._decorator;
Component = _cc.Component;
resources = _cc.resources;
instantiate = _cc.instantiate;
Prefab = _cc.Prefab;
js = _cc.js;
}],
execute: function () {
_crd = true;
_cclegacy._RF.push({}, "54c675nj3NKjJ59O4YaWqa4", "PanelBase", undefined);
__checkObsolete__(['_decorator', 'Component', 'Node', 'director', 'resources', 'instantiate', 'Prefab', 'js']);
({
ccclass,
property
} = _decorator);
_export("PanelBase", PanelBase = (_dec = ccclass('PanelBase'), _dec(_class = class PanelBase extends Component {
constructor() {
super(...arguments);
this.isOpen = false;
}
open() {
var _this = this;
return _asyncToGenerator(function* () {
if (_this.isOpen) return;
_this.node.active = true;
_this.isOpen = true;
_this.onOpen();
})();
}
static LoadPanel(prefabPath, parentNode) {
var _this2 = this;
return _asyncToGenerator(function* () {
var panelNode = null;
resources.load(prefabPath, Prefab, (err, prefabAsset) => {
if (prefabAsset) {
var node = instantiate(prefabAsset);
node.parent = parentNode;
node.getComponent(PanelBase).open();
panelNode = node;
} else {
console.error("Failed to load UI prefab: " + prefabPath);
}
});
yield _this2.waitUntil(() => panelNode != null);
return panelNode;
})();
}
static waitUntil(condition) {
return new Promise(resolve => {
var checkCondition = () => {
if (condition()) {
resolve(); // 条件成立,结束等待
} else {
// 条件不成立,继续轮询
requestAnimationFrame(checkCondition);
}
};
checkCondition(); // 开始检查条件
});
}
close() {
console.log("close panel", this.node.name);
if (!this.isOpen) return;
if (!this.isValid) return;
if (this.node && this.node.parent) {
this.node.removeFromParent();
this.node.destroy();
this.isOpen = false;
this.onClose();
}
}
getPrefabPath() {
var panelName = js.getClassName(this);
return "ui/" + panelName; // 生成预制件路径
}
onOpen() {// 子类可以重写此方法以执行打开后的操作
}
onClose() {// 子类可以重写此方法以执行关闭后的操作
}
}) || _class));
_cclegacy._RF.pop();
_crd = false;
}
};
});
//# sourceMappingURL=63a64431b6b21cd924e8e7464d636fa810675c73.js.map