UIPause.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Widget, _decorator, Node } from 'cc';
  2. import { UIBase } from '../scriptBase/UIBase';
  3. import { GameMgr } from '../manager/GameMgr';
  4. import { Switcher } from '../uiExtend/Switcher';
  5. import { Setting } from '../Setting';
  6. import { AudioMgr } from '../manager/AudioMgr';
  7. import { TransMgr } from '../manager/TransMgr';
  8. import { UI } from '../enum/UI';
  9. const { ccclass, property, requireComponent } = _decorator;
  10. @ccclass('UI/UIPause')
  11. @requireComponent(Widget)
  12. export class UIPause extends UIBase {
  13. private swBgm: Switcher = null
  14. private swSfx: Switcher = null
  15. protected onLoad(): void {
  16. this.swBgm = this.findComp('SwBgm', Switcher)
  17. this.swSfx = this.findComp('SwSfx', Switcher)
  18. }
  19. public onOpen(data?: any): void {
  20. GameMgr.Pause = true
  21. this.swBgm.IsOn = Setting.BgmEnabled
  22. this.swSfx.IsOn = Setting.SfxEnabled
  23. }
  24. public onClose(data?: any): void {
  25. GameMgr.Pause = false
  26. }
  27. protected onBtnCloseClick(): void {
  28. this.close()
  29. }
  30. protected async onBtnRestartClick() {
  31. await TransMgr.Inst.fadeIn()
  32. GameMgr.startGame()
  33. this.close()
  34. TransMgr.Inst.fadeOut()
  35. }
  36. protected async onBtnBackClick() {
  37. await TransMgr.Inst.fadeIn()
  38. GameMgr.quitGame()
  39. this.close()
  40. this.open(UI.Main)
  41. TransMgr.Inst.fadeOut()
  42. }
  43. protected onSwBgmClick(): void {
  44. Setting.BgmEnabled = !Setting.BgmEnabled
  45. if (Setting.BgmEnabled) {
  46. AudioMgr.playBgm()
  47. } else {
  48. AudioMgr.stopBgm()
  49. }
  50. }
  51. protected onSwSfxClick(): void {
  52. Setting.SfxEnabled = !Setting.SfxEnabled
  53. }
  54. }