import { _decorator, CCInteger, Component, Enum, Node, sp, tween, Vec3 } from 'cc'; import { CupHeight } from '../TakeGobletGlobalInstance'; import { LevelAction } from '../LevelAction'; import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher'; import { GameEvent } from '../Enum/GameEvent'; import { Water } from './Water'; const { ccclass, property, executeInEditMode } = _decorator; //原浆杯状态 默认 抬起 倒水 export enum OriginCupState { Default, Up, PourWater } /** 原浆酒杯组件脚本*/ @ccclass('OriginCup') @executeInEditMode export class OriginCup extends Component { @property(sp.Skeleton) cupSkeleton: sp.Skeleton = null!; //杯骨骼 @property({ type: Enum(CupHeight), displayName: '杯高度' }) cupHeight: CupHeight = CupHeight.Two @property(Node) waters: Node = null!; //水节点 @property(Node) marks: Node = null!; //mark节点 start() { this.cupSkeleton = this.node.getChildByName('Cup')?.getComponent(sp.Skeleton)!; this.node.on(Node.EventType.TOUCH_END, () => { EventDispatcher.instance.emit(GameEvent.EVENT_CLICK_ORIGIN_CUP, this); }); } //播放动画根据状态 playAnimation(state: OriginCupState, index?: number) { switch (state) { case OriginCupState.Up: this.playUpAnimation(); break; case OriginCupState.PourWater: this.playPourWaterAnimation(index); break; default: break; } } playUpAnimation() { if (!this.cupSkeleton) return; this.cupSkeleton.setAnimation(0, 'pour_idle', false); this.waters.children.forEach(water => { water.getComponent(Water)?.playAnimation(OriginCupState.Up); }); } playPourWaterAnimation(index: number) { if (!this.cupSkeleton) return; this.cupSkeleton.setAnimation(0, `pour_0${index}`, false); this.waters.children.forEach(water => { water.getComponent(Water)?.playAnimation(OriginCupState.PourWater, index); }); } setMark(bool: boolean) { this.marks.active = bool; } destroyOriginCup() { const id = this.node.uuid; console.log('销毁原浆杯id : ', id); tween(this.node) .to(0.3, { scale: Vec3.ZERO }) .call(() => { EventDispatcher.instance.emit(GameEvent.EVENT_ORIGIN_CUP_DESTROYED, id); this.node.destroy(); }) .start(); } }