slider_widget.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator, Component, Node, Slider } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('slider_widget')
  4. export class slider_widget extends Component {
  5. @property(Node) slider:Node = null;
  6. protected m_call_back = null;
  7. protected m_end_call = null;
  8. public getCurScale(){
  9. let progress = this.slider.getComponent(Slider).progress;
  10. return progress>0.5?(progress+0.5):1-(0.5-progress)
  11. }
  12. public initView(call,end_call){
  13. this.m_call_back = call;
  14. this.m_end_call =end_call;
  15. this.slider.on(Node.EventType.TOUCH_END,()=>{
  16. this.on_end()
  17. })
  18. this.slider.getComponent(Slider).handle.node.on(Node.EventType.TOUCH_END,()=>{
  19. this.on_end()
  20. })
  21. this.slider.getComponent(Slider).handle.node.on(Node.EventType.TOUCH_CANCEL,()=>{
  22. this.on_end()
  23. })
  24. this.slider.on(Node.EventType.TOUCH_CANCEL,()=>{
  25. this.on_end()
  26. })
  27. }
  28. on_end(){
  29. this.slider.getComponent(Slider).progress = 0.5;
  30. if(this.m_end_call!=null){
  31. this.m_end_call()
  32. }
  33. }
  34. public onSlider(){
  35. if(this.m_call_back!=null){
  36. this.m_call_back(this.getCurScale())
  37. }
  38. }
  39. }