TempCup.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { _decorator, Component, Enum, Node } from 'cc';
  2. import { CupHeight, WaterColors } from '../TakeGobletGlobalInstance';
  3. import { Water } from './Water';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('TempCup')
  6. export class TempCup extends Component {
  7. @property({ type: Enum(CupHeight), displayName: '杯高度' })
  8. cupHeight: CupHeight = CupHeight.One
  9. @property(Node)
  10. waters: Node = null!; //水节点
  11. private _currentColor: WaterColors = WaterColors.Blue;
  12. private _isFull: boolean = false;
  13. get isFull(): boolean {
  14. return this._isFull;
  15. }
  16. get currentColor(): WaterColors {
  17. return this._currentColor;
  18. }
  19. start() {
  20. }
  21. update(deltaTime: number) {
  22. }
  23. fill(color: WaterColors) {
  24. if (this._isFull) return;
  25. const waterNode = this.waters.children[0];
  26. if (waterNode) {
  27. const water = waterNode.getComponent(Water)!;
  28. water.color = color;
  29. waterNode.active = true;
  30. this._currentColor = color;
  31. this._isFull = true;
  32. }
  33. }
  34. reset() {
  35. this.waters.children[0].active = false;
  36. this._isFull = false;
  37. }
  38. }