ButtonSound.ts 747 B

1234567891011121314151617181920212223242526272829303132
  1. import AudioMng from "./AudioMng";
  2. import { UIButton } from "./UIButton";
  3. import GameData from "./GameData";
  4. import {Sprite,Component, _decorator } from "cc";
  5. const {ccclass, property} = _decorator;
  6. @ccclass
  7. export default class ButtonSound extends Component {
  8. @property(Sprite)
  9. offSp: Sprite = null;
  10. start () {
  11. this.refreshUI();
  12. UIButton.BindClick(this.node,()=>{
  13. if(AudioMng.Instance.soundOn)
  14. {
  15. GameData.SetCustomData("SoundOn", 0);
  16. }
  17. else{
  18. GameData.SetCustomData("SoundOn", 1);
  19. }
  20. this.refreshUI();
  21. },this);
  22. }
  23. refreshUI(){
  24. this.offSp.node.active=!AudioMng.Instance.soundOn;
  25. }
  26. }