import { _decorator, Component, CCString, find, Node, Enum, EventHandler, SystemEventType } from "cc"; import { WindowOpenMode } from "./WindowOpenMode"; import { WindowSystem } from "./WindowSystem"; const { ccclass, property } = _decorator; /** * 打开窗口组件,定义窗口的参数、窗口的打开等 * @author 袁浩 */ @ccclass('OpenWindow') export class OpenWindow extends Component { @property({ tooltip: "要加载的预制体对象相对于resources的路径" }) public prefabPath: string = ''; @property({ tooltip: "窗口打开的模式", type: Enum(WindowOpenMode) }) public openMode: WindowOpenMode = WindowOpenMode.NotCloseAndAdd; @property({ tooltip: "自定义参数", type: [CCString] }) public params: string[] = []; @property({ tooltip: "窗口打开触发的节点,不填则无触发", type: [Node] }) public openFroms: Node[] = []; @property({ tooltip: "窗口打开中的回调", type: [EventHandler] }) public onOpening: EventHandler[] = []; @property({ tooltip: "窗口关闭中的回调", type: [EventHandler] }) public onClosing: EventHandler[] = []; protected start() { this.checkOpenFroms(); } public checkOpenFroms() { for (let i = 0; i < this.openFroms.length; i++) { const node = this.openFroms[i]; node.on(SystemEventType.TOUCH_END, () => { this.open() }, this); } } /** * 打开窗口 * @param params 给窗口传递的参数,如果有值,那么此参数始终跟随在自定义参数后面 */ public async open(...params) { var _window = await WindowSystem.open(this.prefabPath, this.openMode, params.concat(this.params), this.onOpening, this.onClosing); return _window; } }