CCSAnimationUtils.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { AnimationComponent, AnimationState } from "cc";
  2. export default class CCSAnimationUtils
  3. {
  4. /**
  5. * 设置动画速度
  6. * @param target
  7. * @param animation
  8. * @param speed
  9. */
  10. public static SetAnimationSpeed(target:AnimationComponent,animation:string,speed:number):void{
  11. let state:AnimationState=target.getState(animation);
  12. if(state==null){
  13. throw new Error(target.node.name+"找不到动画:"+animation);
  14. }
  15. state.speed=speed;
  16. }
  17. /**
  18. * 设置动画事件帧
  19. * @param target
  20. * @param clipName
  21. * @param data
  22. */
  23. public static SetAnimationEvent(target:AnimationComponent,clipName:string,events:any[]):void{
  24. let isTrue:boolean=false;
  25. target.clips.forEach(element => {
  26. if(element.name==clipName){
  27. events.forEach(eventData => {
  28. element.events.push(eventData);
  29. });
  30. isTrue=true;
  31. element.updateEventDatas();
  32. }
  33. });
  34. if(isTrue==false){
  35. throw new Error(target.name+"找不到:"+clipName+"动画,无法设置动画事件回调");
  36. }
  37. }
  38. }