You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					68 lines
				
				1.7 KiB
			
		
		
			
		
	
	
					68 lines
				
				1.7 KiB
			| 
								 
											11 months ago
										 
									 | 
							
								const { ccclass, property } = cc._decorator;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@ccclass
							 | 
						||
| 
								 | 
							
								export default class WanderTweenAnimation extends cc.Component {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @property(cc.Node)
							 | 
						||
| 
								 | 
							
								    wanderTweenNode: cc.Node = null;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @property(cc.Vec3)
							 | 
						||
| 
								 | 
							
								    wanderPoint: cc.Vec3[] = [];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @property(cc.Node)
							 | 
						||
| 
								 | 
							
								    wanderFrameList: cc.Node[] = [];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @property()
							 | 
						||
| 
								 | 
							
								    speed: number = 30;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // LIFE-CYCLE CALLBACKS:
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // onLoad () {}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // start() {}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    protected onEnable(): void {
							 | 
						||
| 
								 | 
							
								        if (!this.wanderTweenNode) {
							 | 
						||
| 
								 | 
							
								            this.wanderTweenNode = this.node;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        for (const iterator of this.wanderFrameList) {
							 | 
						||
| 
								 | 
							
								            iterator.active = false;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        let atween = cc.tween(this.wanderTweenNode)
							 | 
						||
| 
								 | 
							
								        for (let index = 0; index < this.wanderPoint.length; index++) {
							 | 
						||
| 
								 | 
							
								            let nextIndex = (index >= this.wanderPoint.length - 1) ? 0 : index + 1;
							 | 
						||
| 
								 | 
							
								            let delayTime_ = this.wanderPoint[nextIndex].sub(this.wanderPoint[index]).len() / this.speed / 10;
							 | 
						||
| 
								 | 
							
								            let startPoint = this.wanderPoint[index],
							 | 
						||
| 
								 | 
							
								                endPoint = this.wanderPoint[nextIndex],
							 | 
						||
| 
								 | 
							
								                showNodo = this.wanderFrameList[index];
							 | 
						||
| 
								 | 
							
								            atween.set({ position: startPoint })
							 | 
						||
| 
								 | 
							
								                .call(() => {
							 | 
						||
| 
								 | 
							
								                    showNodo.active = true;
							 | 
						||
| 
								 | 
							
								                })
							 | 
						||
| 
								 | 
							
								                .to(delayTime_, { position: endPoint })
							 | 
						||
| 
								 | 
							
								                .call(() => {
							 | 
						||
| 
								 | 
							
								                    showNodo.active = false;
							 | 
						||
| 
								 | 
							
								                })
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        atween.union()
							 | 
						||
| 
								 | 
							
								            .repeatForever()
							 | 
						||
| 
								 | 
							
								            .start();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        this.node.attr({
							 | 
						||
| 
								 | 
							
								            start: () => {
							 | 
						||
| 
								 | 
							
								                atween.start();
							 | 
						||
| 
								 | 
							
								            },
							 | 
						||
| 
								 | 
							
								            stop: () => {
							 | 
						||
| 
								 | 
							
								                atween.stop();
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // update (dt) {}
							 | 
						||
| 
								 | 
							
								}
							 |