VehicleViewAnimator.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { _decorator, v3 } from "cc";
  2. import { AnimatorSkeletal } from "../../../../../extensions/oops-plugin-framework/assets/libs/animator/AnimatorSkeletal";
  3. import { AnimatorStateLogic } from "../../../../../extensions/oops-plugin-framework/assets/libs/animator/core/AnimatorStateLogic";
  4. import { Vehicle } from "../Vehicle";
  5. import { VehicleAnimatorType } from "../model/VehicleEnum";
  6. import { VehicleStateOpenDoor } from "./animator/VehicleStateOpenDoor";
  7. import { MoveToComp } from "../../common/ecs/position/MoveTo";
  8. import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
  9. const { ccclass } = _decorator;
  10. @ccclass("VehicleViewAnimator")
  11. export class VehicleViewAnimator extends AnimatorSkeletal {
  12. /**关门完成完成 */
  13. onOpenDoorComplete: Function = null!;
  14. onLeaveComplete: Function = null!;
  15. onWaitComplete: Function = null!;
  16. onStationComplete: Function = null!;
  17. /** 角色对象 */
  18. vehicle: Vehicle = null!;
  19. timer = null
  20. start() {
  21. super.start();
  22. // // 动画状态机
  23. // let asl: Map<string, AnimatorStateLogic> = new Map();
  24. // asl.set(VehicleAnimatorType.OpenDoor, new VehicleStateOpenDoor(this.vehicle));
  25. // this.initArgs(asl);
  26. }
  27. playAnimation(animName: string, loop: boolean): void {
  28. super.playAnimation(animName,loop)
  29. }
  30. moveToStation(){
  31. clearTimeout(this.timer)
  32. const moveTo = this.vehicle.add(MoveToComp,true)
  33. moveTo.speed = 3
  34. moveTo.node = this.node
  35. moveTo.onComplete = this.onStationComplete
  36. moveTo.target = v3(0,0,-5)
  37. oops.audio.playEffect('common/audio/bus_arrive_leave')
  38. }
  39. moveToWait(){
  40. this.timer = setTimeout(()=>{
  41. const moveTo = this.vehicle.add(MoveToComp,true)
  42. moveTo.speed = 3
  43. moveTo.node = this.node
  44. moveTo.target = v3(-3,0,-5)
  45. moveTo.onComplete = this.onWaitComplete
  46. clearTimeout(this.timer)
  47. },1000)
  48. }
  49. moveToLeave(){
  50. const moveTo = this.vehicle.add(MoveToComp,true)
  51. moveTo.speed = 3
  52. moveTo.node = this.node
  53. moveTo.target = v3(10,0,-5)
  54. moveTo.onComplete = this.onLeaveComplete
  55. oops.audio.playEffect('common/audio/bus_arrive_leave')
  56. }
  57. }