BtnOpenPanel.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. const { ccclass, property } = cc._decorator;
  2. import { OpenActionType } from '../../mk/system/UISystem';
  3. /**
  4. * 打开指定名字的面板
  5. * @author 薛鸿潇
  6. */
  7. @ccclass
  8. export default class BtnOpenPanel extends cc.Component {
  9. @property({ displayName: '预制体路径', tooltip: '对应路径:resources/' })
  10. private panel_name = '';
  11. @property({ displayName: '打开类型', tooltip: 'normal不操作,closeOther关闭其他,closeLast关闭上一个', type: cc.Enum(OpenActionType) })
  12. private open_type = OpenActionType.normal;
  13. @property({ displayName: '完成回调', tooltip: "面板打开完成后触发", type: cc.Component.EventHandler })
  14. public onComplete: cc.Component.EventHandler[] = [];
  15. onLoad() {
  16. if (!this.node.getComponent(cc.Button)) this.node.addComponent(cc.Button);
  17. }
  18. start() {
  19. this.node.on('click', this.openPanel, this);
  20. }
  21. private async openPanel() {
  22. await mk.ui.openPanel(this.panel_name, this.open_type);
  23. const c_count = this.onComplete.length;
  24. for (let i = 0; i < c_count; i++) {
  25. if (this.onComplete[i].handler) this.onComplete[i].emit([])
  26. }
  27. }
  28. // update (dt) {}
  29. }