event_play_sound.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. private m_data:event_item_play_sound = null;
  14. public initView(data:event_item_play_sound){
  15. this.m_data = data;
  16. this.btn_select_sound.on(Node.EventType.TOUCH_END,()=>{
  17. tools.select_sound_list((data:bag_item_data)=>{
  18. this.m_data.sound_res.name = data.name;
  19. this.m_data.sound_res.url = data.url;
  20. this.updateStatus()
  21. })
  22. })
  23. this.updateStatus()
  24. this.toggle.node.on(Toggle.EventType.TOGGLE,()=>{
  25. this.m_data.isLoop = this.toggle.isChecked
  26. })
  27. }
  28. onSlider(){
  29. this.m_data.volume = this.slider_volume.progress;
  30. }
  31. updateStatus(){
  32. if(this.m_data.sound_res.name.length>0){
  33. this.lab_name.getComponent(Label).string = this.m_data.sound_res.name
  34. this.select_loop.active = true;
  35. this.select_volume.active = true;
  36. }else{
  37. this.lab_name.getComponent(Label).string = "选择一个音频文件"
  38. this.select_loop.active = false;
  39. this.select_volume.active = false;
  40. }
  41. if(this.m_data.isLoop==undefined){
  42. this.m_data.isLoop = false;
  43. }
  44. if( this.m_data.volume==undefined){
  45. this.m_data.volume = 1;
  46. }
  47. this.toggle.isChecked = this.m_data.isLoop;
  48. this.slider_volume.progress = this.m_data.volume;
  49. }
  50. }