| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { _decorator, ccenum, Component, Enum, Node, Sprite } from 'cc';
- import { audioManager } from './AudioManager';
- const { ccclass, property } = _decorator;
- enum MusicType{
- music,
- sound,
- vibrate,
- }
- @ccclass('MusicBar')
- export class MusicBar extends Component {
- @property({ type: Enum(MusicType) })
- readonly musicType:MusicType
- @property(Node)
- openBtn:Node
- @property(Node)
- closeBtn:Node
- protected onEnable(): void {
- this.openBtn?.on(Node.EventType.TOUCH_END,this.clickOpen,this)
- this.closeBtn?.on(Node.EventType.TOUCH_END,this.clickClose,this)
- if(this.musicType ==MusicType.music ){
- this.flash(audioManager.switchMusic)
- }
- if(this.musicType ==MusicType.sound ){
- this.flash(audioManager.switchEffect)
- }
- if(this.musicType ==MusicType.vibrate ){
-
- this.flash(audioManager.switch_vibrate)
- }
- }
- clickSwich(boolean){
-
- // audioManager.playOneShot("audios/clickUI")
- this.closeBtn.active =boolean
- this.openBtn.active =!boolean
- if(this.musicType ==MusicType.music ){
-
- audioManager.switchMusic = !boolean
- if(!boolean){
- audioManager.replay_music()
- }
- }
- if(this.musicType ==MusicType.sound ){
- audioManager.switchEffect = !boolean
- }
- if(this.musicType ==MusicType.vibrate ){
- audioManager.switch_vibrate = !boolean
- }
- audioManager.save()
- }
- clickOpen(){
- this.clickSwich(true)
- }
- clickClose(){
- this.clickSwich(false)
- }
- flash(open){
- this.openBtn.active = open
- this.closeBtn.active = !open
- }
-
-
- }
|