Page.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import { _decorator, Component, EventHandler } from 'cc';
  2. import { PageView } from './PageView';
  3. const { ccclass, property } = _decorator;
  4. /**
  5. * 页面
  6. * @description 提供显示和隐藏事件
  7. * @author 袁浩
  8. */
  9. @ccclass('Page')
  10. export class Page extends Component {
  11. @property({ tooltip: "当页面显示时", type: EventHandler })
  12. public onShow: EventHandler[] = [];
  13. @property({ tooltip: "当页面显示时", type: EventHandler })
  14. public onHide: EventHandler[] = [];
  15. @property({ tooltip: "是否自动显示/隐藏" })
  16. public autoVisible = true;
  17. show(owner: PageView) {
  18. for (let i = 0; i < this.onShow.length; i++) {
  19. this.onShow[i] && this.onShow[i].emit([this, owner]);
  20. }
  21. if (this.autoVisible) {
  22. this.node.active = true;
  23. }
  24. }
  25. hide(owner: PageView) {
  26. for (let i = 0; i < this.onHide.length; i++) {
  27. this.onHide[i] && this.onHide[i].emit([this, owner]);
  28. }
  29. if (this.autoVisible) {
  30. this.node.active = false;
  31. }
  32. }
  33. }