123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { AnimationComponent, AnimationState } from "cc";
- export default class CCSAnimationUtils
- {
- /**
- * 设置动画速度
- * @param target
- * @param animation
- * @param speed
- */
- public static SetAnimationSpeed(target:AnimationComponent,animation:string,speed:number):void{
- let state:AnimationState=target.getState(animation);
- if(state==null){
- throw new Error(target.node.name+"找不到动画:"+animation);
- }
- state.speed=speed;
- }
- /**
- * 设置动画事件帧
- * @param target
- * @param clipName
- * @param data
- */
- public static SetAnimationEvent(target:AnimationComponent,clipName:string,events:any[]):void{
- let isTrue:boolean=false;
- target.clips.forEach(element => {
- if(element.name==clipName){
- events.forEach(eventData => {
- element.events.push(eventData);
- });
- isTrue=true;
- element.updateEventDatas();
- }
- });
- if(isTrue==false){
- throw new Error(target.name+"找不到:"+clipName+"动画,无法设置动画事件回调");
- }
- }
- }
|