

export default class CCSAnimationUtils
{
     /**
     * 设置动画速度
     * @param target 
     * @param animation 
     * @param speed 
     */
    public static SetAnimationSpeed(target:cc.Animation,animation:string,speed:number):void{
        let state:cc.AnimationState=target.getAnimationState(animation);
        if(state==null){
            throw new Error(target.node.name+"找不到动画："+animation);
        }
        state.speed=speed;
    }

    /**
     * 设置动画事件帧
     * @param target 
     * @param clipName 
     * @param data 
     */
    public static SetAnimationEvent(target:cc.Animation,clipName:string,events:any[]):void{
        let isTrue:boolean=false;
        let clips:cc.AnimationClip[]=target.getClips();
        clips.forEach(element => {
            if(element.name==clipName){
                events.forEach(eventData => {
                    element.events.push(eventData);
                });
                isTrue=true;
            }
        });
        if(isTrue==false){
            throw new Error(target.name+"找不到："+clipName+"动画,无法设置动画事件回调");
        }
    }
}