event_play_sound.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { _decorator, Component, Label, Node, Slider, Toggle } from 'cc';
  2. import { bag_item_data, event_item_play_sound } from '../../../data/data';
  3. import { tools } from '../../tools';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('event_play_sound')
  6. export class event_play_sound extends Component {
  7. @property(Node) btn_select_sound:Node = null;
  8. @property(Node) lab_name:Node = null;
  9. @property(Toggle) toggle:Toggle = null;
  10. @property(Slider) slider_volume:Slider = null;
  11. @property(Node) select_loop:Node = null;
  12. @property(Node) select_volume:Node = null;
  13. @property(Node) select_BGM:Node = null;
  14. @property(Toggle) BGM_toggle:Toggle = null;
  15. private m_data:event_item_play_sound = null;
  16. public initView(data:event_item_play_sound){
  17. this.m_data = data;
  18. this.btn_select_sound.on(Node.EventType.TOUCH_END,()=>{
  19. tools.select_sound_list((data:bag_item_data)=>{
  20. this.m_data.sound_res.name = data.name;
  21. this.m_data.sound_res.url = data.url;
  22. this.updateStatus()
  23. })
  24. })
  25. this.updateStatus()
  26. this.toggle.node.on(Toggle.EventType.TOGGLE,()=>{
  27. this.m_data.isLoop = this.toggle.isChecked
  28. })
  29. this.BGM_toggle.node.on(Toggle.EventType.TOGGLE, ()=>{
  30. this.m_data.isBGM = this.BGM_toggle.isChecked
  31. })
  32. }
  33. onSlider(){
  34. this.m_data.volume = this.slider_volume.progress;
  35. }
  36. updateStatus(){
  37. if(this.m_data.sound_res.name.length>0){
  38. this.lab_name.getComponent(Label).string = this.m_data.sound_res.name
  39. this.select_loop.active = true;
  40. this.select_volume.active = true;
  41. this.select_BGM.active = true;
  42. }else{
  43. this.lab_name.getComponent(Label).string = "选择一个音频文件"
  44. this.select_loop.active = false;
  45. this.select_volume.active = false;
  46. this.select_BGM.active = false;
  47. }
  48. if(this.m_data.isLoop==undefined){
  49. this.m_data.isLoop = false;
  50. }
  51. if( this.m_data.volume==undefined){
  52. this.m_data.volume = 1;
  53. }
  54. if(this.m_data.isBGM==undefined) {
  55. this.m_data.isBGM = false;
  56. }
  57. this.toggle.isChecked = this.m_data.isLoop;
  58. this.slider_volume.progress = this.m_data.volume;
  59. this.BGM_toggle.isChecked = this.m_data.isBGM
  60. }
  61. }