OriginCup.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, CCInteger, Component, Enum, Node, sp, tween, Vec3 } from 'cc';
  2. import { CupHeight } from '../TakeGobletGlobalInstance';
  3. import { LevelAction } from '../LevelAction';
  4. import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
  5. import { GameEvent } from '../Enum/GameEvent';
  6. import { Water } from './Water';
  7. const { ccclass, property, executeInEditMode } = _decorator;
  8. //原浆杯状态 默认 抬起 倒水
  9. export enum OriginCupState {
  10. Default,
  11. Up,
  12. PourWater
  13. }
  14. /** 原浆酒杯组件脚本*/
  15. @ccclass('OriginCup')
  16. @executeInEditMode
  17. export class OriginCup extends Component {
  18. @property(sp.Skeleton)
  19. cupSkeleton: sp.Skeleton = null!; //杯骨骼
  20. @property({ type: Enum(CupHeight), displayName: '杯高度' })
  21. cupHeight: CupHeight = CupHeight.Two
  22. @property(Node)
  23. waters: Node = null!; //水节点
  24. @property(Node)
  25. marks: Node = null!; //mark节点
  26. start() {
  27. this.cupSkeleton = this.node.getChildByName('Cup')?.getComponent(sp.Skeleton)!;
  28. this.node.on(Node.EventType.TOUCH_END, () => {
  29. EventDispatcher.instance.emit(GameEvent.EVENT_CLICK_ORIGIN_CUP, this);
  30. });
  31. }
  32. //播放动画根据状态
  33. playAnimation(state: OriginCupState, index?: number) {
  34. switch (state) {
  35. case OriginCupState.Up:
  36. this.playUpAnimation();
  37. break;
  38. case OriginCupState.PourWater:
  39. this.playPourWaterAnimation(index);
  40. break;
  41. default:
  42. break;
  43. }
  44. }
  45. playUpAnimation() {
  46. if (!this.cupSkeleton) return;
  47. this.cupSkeleton.setAnimation(0, 'pour_idle', false);
  48. this.waters.children.forEach(water => {
  49. water.getComponent(Water)?.playAnimation(OriginCupState.Up);
  50. });
  51. }
  52. playPourWaterAnimation(index: number) {
  53. if (!this.cupSkeleton) return;
  54. this.cupSkeleton.setAnimation(0, `pour_0${index}`, false);
  55. this.waters.children.forEach(water => {
  56. water.getComponent(Water)?.playAnimation(OriginCupState.PourWater, index);
  57. });
  58. }
  59. setMark(bool: boolean) {
  60. this.marks.active = bool;
  61. }
  62. destroyOriginCup() {
  63. const id = this.node.uuid;
  64. console.log('销毁原浆杯id : ', id);
  65. tween(this.node)
  66. .to(0.3, { scale: Vec3.ZERO })
  67. .call(() => {
  68. EventDispatcher.instance.emit(GameEvent.EVENT_ORIGIN_CUP_DESTROYED, id);
  69. this.node.destroy();
  70. })
  71. .start();
  72. }
  73. }