123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import { _decorator, color, Color, Component, Enum, Node, sp } from 'cc';
- import { CupHeight, WaterColorHex, WaterColors } from '../TakeGobletGlobalInstance';
- import { Water } from './Water';
- import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
- import { GameEvent } from '../Enum/GameEvent';
- import { GameUtil } from '../GameUtil';
- import { TakeGobletAudioMgr } from '../Manager/TakeGobletAudioMgr';
- import { GlobalConfig } from 'db://assets/start/Config/GlobalConfig';
- import { AdvertMgr } from 'db://assets/core_tgx/base/ad/AdvertMgr';
- const { ccclass, property } = _decorator;
- //暂存杯状态 默认 接水 倒水
- export enum TempCupState {
- Default,
- Pick,
- PourWater
- }
- @ccclass('TempCup')
- export class TempCup extends Component {
- @property({ type: Enum(CupHeight), displayName: '杯高度' })
- cupHeight: CupHeight = CupHeight.One
- @property(Node)
- waters: Node = null!; //水节点
- @property(sp.Skeleton)
- colorB: sp.Skeleton = null!; //水流骨骼
- @property(sp.Skeleton)
- cupSkeleton: sp.Skeleton = null!; //杯骨骼
- @property(Node)
- adNode: Node = null!;
- private _currentColor: WaterColors = WaterColors.Blue;
- private _isFull: boolean = false;
- get isFull(): boolean {
- return this._isFull;
- }
- get currentColor(): WaterColors {
- return this._currentColor;
- }
- get iconAd(): boolean {
- return this.adNode.active;
- }
- start() {
- this.node.on(Node.EventType.TOUCH_END, () => {
- this.onTouchEndAdCup();
- });
- }
- private onTouchEndAdCup() {
- if (this.iconAd) {
- if (!GlobalConfig.isDebug) {
- AdvertMgr.instance.showReawardVideo(() => {
- this.adNode.active = false;
- })
- } else {
- this.adNode.active = false;
- }
- }
- }
- /**暂存杯 接水动画*/
- async fill(color: WaterColors) {
- if (this._isFull) return;
- const waterNode = this.waters.children[0];
- if (waterNode && waterNode.getComponent(sp.Skeleton)) {
- waterNode.active = true;
- this._currentColor = color;
- let cupColor = new Color(WaterColorHex[color]);
- let waterSpine = waterNode.getComponent(sp.Skeleton)!;
- // console.log(`暂存水的颜色:${WaterColorHex[color]}`)
- this.colorB.color = cupColor;
- waterSpine.color = cupColor;
- this.playAnimation(TempCupState.Pick);
- this._isFull = true;
- await GameUtil.delay(0.5);
- }
- }
- playAnimation(state: TempCupState) {
- let animaStr = state === TempCupState.Pick ? 'pick_01' :
- state === TempCupState.PourWater ? 'pour_01' : 'idle';
- const waterNode = this.waters.children[0];
- if (waterNode && waterNode.getComponent(sp.Skeleton)) {
- let waterSpine = waterNode.getComponent(sp.Skeleton)!;
- waterSpine.setAnimation(0, animaStr, false);
- this.colorB.setAnimation(0, animaStr, false);
- this.cupSkeleton.setAnimation(0, animaStr, false);
- }
- }
- //设置spine 时间缩放率
- setSpineTimeScale(timeScale: number = 1) {
- if (!this.node) return;
- const spineComponents = this.node.getComponentsInChildren(sp.Skeleton);
- spineComponents.forEach(spine => {
- spine.timeScale = timeScale;
- });
- }
- /**暂存杯 倒水动画*/
- pour() {
- TakeGobletAudioMgr.playOneShot(TakeGobletAudioMgr.getMusicIdName(4), 1.0);
- this.setSpineTimeScale(1.5);
- this.playAnimation(TempCupState.PourWater);
- }
- reset() {
- this._currentColor = WaterColors.White;
- let cupColor = new Color(WaterColorHex[this.currentColor]);
- let waterNode = this.waters.children[0];
- let waterSpine = waterNode.getComponent(sp.Skeleton)!;
- this.colorB.color = cupColor;
- waterSpine.color = cupColor;
- this._isFull = false;
- this.playAnimation(TempCupState.Default);
- }
- public getColors(): WaterColors[] {
- return [this.currentColor];
- }
- public isEmpty(): boolean {
- return this.waters.children.every(node => !node.active);
- }
- }
|