UI.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Component, director, Label, Node } from 'cc';
  2. import { EventManager } from '../EventManager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('UI')
  5. export class UI extends Component {
  6. @property(Node)
  7. FuhuoNode: Node = null;
  8. @property(Node)
  9. RestartNode: Node = null;
  10. @property(Node)
  11. HomeNode: Node = null;
  12. protected onLoad(): void {
  13. EventManager.instance.et.on(EventManager.EventType.OpenUIPnael, this.OpenUIPnael, this);
  14. }
  15. OpenUIPnael() {
  16. this.init()
  17. }
  18. init() {
  19. this.node.children.forEach((item: Node) => {
  20. item.active = true;
  21. })
  22. this.FuhuoNode.active = true;
  23. this.RestartNode.active = false;
  24. this.HomeNode.active = false;
  25. this.schedule(() => {
  26. this.FuhuoNode.getComponentInChildren(Label).string = (parseInt(this.FuhuoNode.getComponentInChildren(Label).string) - 1) + ''
  27. }, 1, 3, 0)
  28. this.scheduleOnce(() => {
  29. this.FuhuoNode.active = false;
  30. this.RestartNode.active = true;
  31. this.HomeNode.active = true;
  32. }, 3)
  33. }
  34. Restart() {
  35. director.loadScene('Game', (err) => {
  36. if (err) {
  37. console.error(err);
  38. return;
  39. }
  40. console.log('加载场景成功');
  41. })
  42. this.close()
  43. }
  44. Home() {
  45. director.loadScene('loading', (err) => {
  46. if (err) {
  47. console.error(err);
  48. return;
  49. }
  50. console.log('加载场景成功');
  51. })
  52. this.close()
  53. }
  54. FuHuo() {
  55. EventManager.instance.et.emit(EventManager.EventType.Add_haert);
  56. EventManager.instance.et.emit(EventManager.EventType.Set_Add_Score_BOOL, true);
  57. EventManager.instance.et.emit(EventManager.EventType.Reset_Role);
  58. this.close()
  59. }
  60. close() {
  61. this.unscheduleAllCallbacks()
  62. this.node.children.forEach((item: Node) => {
  63. item.active = false;
  64. })
  65. }
  66. }