import { _decorator, Component, EventHandler } from 'cc'; import { PageView } from './PageView'; const { ccclass, property } = _decorator; /** * 页面 * @description 提供显示和隐藏事件 * @author 袁浩 */ @ccclass('Page') export class Page extends Component { @property({ tooltip: "当页面显示时", type: EventHandler }) public onShow: EventHandler[] = []; @property({ tooltip: "当页面显示时", type: EventHandler }) public onHide: EventHandler[] = []; @property({ tooltip: "是否自动显示/隐藏" }) public autoVisible = true; show(owner: PageView) { for (let i = 0; i < this.onShow.length; i++) { this.onShow[i] && this.onShow[i].emit([this, owner]); } if (this.autoVisible) { this.node.active = true; } } hide(owner: PageView) { for (let i = 0; i < this.onHide.length; i++) { this.onHide[i] && this.onHide[i].emit([this, owner]); } if (this.autoVisible) { this.node.active = false; } } }