UISetting.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { Widget, _decorator, Node, Label } from 'cc';
  2. import { UIBase } from '../scriptBase/UIBase';
  3. import { Switcher } from '../uiExtend/Switcher';
  4. import { Setting } from '../Setting';
  5. import { AudioMgr } from '../manager/AudioMgr';
  6. import { UI } from '../enum/UI';
  7. import { Bundle } from '../enum/Bundle';
  8. const { ccclass, property, requireComponent } = _decorator;
  9. @ccclass('UI/UISetting')
  10. @requireComponent(Widget)
  11. export class UISetting extends UIBase {
  12. private swBgm: Switcher = null
  13. private swSfx: Switcher = null
  14. protected onLoad(): void {
  15. this.swBgm = this.findComp('SwBgm', Switcher)
  16. this.swSfx = this.findComp('SwSfx', Switcher)
  17. }
  18. public onOpen(data?: any): void {
  19. this.swBgm.IsOn = Setting.BgmEnabled
  20. this.swSfx.IsOn = Setting.SfxEnabled
  21. }
  22. public onClose(data?: any): void {
  23. }
  24. protected onBtnCloseClick(): void {
  25. this.close()
  26. }
  27. protected onSwBgmClick(): void {
  28. Setting.BgmEnabled = !Setting.BgmEnabled
  29. if (Setting.BgmEnabled) {
  30. AudioMgr.playBgm()
  31. } else {
  32. AudioMgr.stopBgm()
  33. }
  34. }
  35. protected onSwSfxClick(): void {
  36. Setting.SfxEnabled = !Setting.SfxEnabled
  37. }
  38. }