TempCup.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { _decorator, color, Color, Component, Enum, Node, sp } from 'cc';
  2. import { CupHeight, WaterColorHex, WaterColors } from '../TakeGobletGlobalInstance';
  3. import { Water } from './Water';
  4. import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
  5. import { GameEvent } from '../Enum/GameEvent';
  6. import { GameUtil } from '../GameUtil';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('TempCup')
  9. export class TempCup extends Component {
  10. @property({ type: Enum(CupHeight), displayName: '杯高度' })
  11. cupHeight: CupHeight = CupHeight.One
  12. @property(Node)
  13. waters: Node = null!; //水节点
  14. @property(sp.Skeleton)
  15. colorB: sp.Skeleton = null!; //水流骨骼
  16. @property(sp.Skeleton)
  17. cupSkeleton: sp.Skeleton = null!; //杯骨骼
  18. @property(Node)
  19. adNode: Node = null!;
  20. private _currentColor: WaterColors = WaterColors.Blue;
  21. private _isFull: boolean = false;
  22. get isFull(): boolean {
  23. return this._isFull;
  24. }
  25. get currentColor(): WaterColors {
  26. return this._currentColor;
  27. }
  28. get iconAd(): boolean {
  29. return this.adNode.active;
  30. }
  31. start() {
  32. this.node.on(Node.EventType.TOUCH_END, () => {
  33. this.onTouchEndAdCup();
  34. });
  35. }
  36. private onTouchEndAdCup() {
  37. if (this.iconAd) {
  38. this.adNode.active = false;
  39. console.log('关闭广告图标@@@@@');
  40. }
  41. }
  42. /**暂存杯 接水动画*/
  43. async fill(color: WaterColors) {
  44. if (this._isFull) return;
  45. const waterNode = this.waters.children[0];
  46. if (waterNode && waterNode.getComponent(sp.Skeleton)) {
  47. waterNode.active = true;
  48. this._currentColor = color;
  49. let cupColor = new Color(WaterColorHex[color]);
  50. let waterSpine = waterNode.getComponent(sp.Skeleton)!;
  51. console.log(`暂存水的颜色:${WaterColorHex[color]}`)
  52. this.colorB.color = cupColor;
  53. waterSpine.color = cupColor;
  54. waterSpine.setAnimation(0, 'pick_01', false);
  55. this.colorB.setAnimation(0, 'pick_01', false);
  56. this.cupSkeleton.setAnimation(0, 'pick_01', false);
  57. this._isFull = true;
  58. await GameUtil.delay(0.5);
  59. }
  60. }
  61. pour() {
  62. }
  63. reset() {
  64. this.waters.children[0].active = false;
  65. this._isFull = false;
  66. console.log('暂存杯已重置');
  67. }
  68. public getColors(): WaterColors[] {
  69. return [this.currentColor];
  70. }
  71. public isEmpty(): boolean {
  72. return this.waters.children.every(node => !node.active);
  73. }
  74. }