123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { _decorator, Component, Node, Slider } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('slider_widget')
- export class slider_widget extends Component {
- @property(Node) slider:Node = null;
- protected m_call_back = null;
- protected m_end_call = null;
- public getCurScale(){
- let progress = this.slider.getComponent(Slider).progress;
- return progress>0.5?(progress+0.5):1-(0.5-progress)
- }
- public initView(call,end_call){
- this.m_call_back = call;
- this.m_end_call =end_call;
- this.slider.on(Node.EventType.TOUCH_END,()=>{
- this.on_end()
- })
- this.slider.getComponent(Slider).handle.node.on(Node.EventType.TOUCH_END,()=>{
- this.on_end()
- })
- this.slider.getComponent(Slider).handle.node.on(Node.EventType.TOUCH_CANCEL,()=>{
- this.on_end()
- })
- this.slider.on(Node.EventType.TOUCH_CANCEL,()=>{
- this.on_end()
- })
- }
- on_end(){
- this.slider.getComponent(Slider).progress = 0.5;
- if(this.m_end_call!=null){
- this.m_end_call()
- }
- }
- public onSlider(){
- if(this.m_call_back!=null){
- this.m_call_back(this.getCurScale())
- }
- }
- }
|