123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import { _decorator, BoxCollider2D, Button, CircleCollider2D, Collider2D, Component, find, instantiate, Node, NodeEventType, view } from 'cc';
- import { resLoader, ResLoader } from '../../core_tgx/base/ResLoader';
- import { CupHeight, TakeGobletGlobalInstance, WaterColors } from './TakeGobletGlobalInstance';
- import { OutArea } from './Component/OutArea';
- import { WaitArea } from './Component/WaitArea';
- import { CocktailCup } from './Component/CocktailCup';
- const { ccclass, property } = _decorator;
- @ccclass('LevelAction')
- export class LevelAction extends Component {
- @property(OutArea)
- outArea: OutArea = null!; // 直接引用OutArea组件
- @property(WaitArea)
- waitArea: WaitArea = null!; // 直接引用WaitArea组件
- @property(Node)
- tempCups: Node = null!; //临时杯
- @property(Node)
- goblets: Node = null!; //原浆区
- start() {
- this.registerListener();
- this.generateInitialCups(); // 自动初始化
- }
- registerListener() {
- }
- private async generateInitialCups() {
- const instance = TakeGobletGlobalInstance.instance;
- const configs = instance.getInitialCupsConfig();
- const allCups: Node[] = [];
- for (const config of configs) {
- for (let i = 0; i < config.count; i++) {
- const prefab = await instance.loadAsyncCocktail(config.height);
- const cupNode = instantiate(prefab);
- const cup = cupNode.getComponent(CocktailCup)!;
- // 设置颜色并重置水位
- cup.cupColor = instance.getRandomColor();
- cup.reset();
- allCups.push(cupNode);
- }
- }
- console.log('allCups: ', allCups.length);
- // 分配初始位置
- allCups.slice(0, 2).forEach(cup => this.outArea.addCup(cup));
- allCups.slice(2).forEach(cup => this.waitArea.addCup(cup));
- }
- // 当调酒区杯子被消除时调用
- public async handleCupsRemoved(count: number) {
- for (let i = 0; i < count; i++) {
- const cup = this.waitArea.takeCup();
- if (cup) {
- this.outArea.addCup(cup);
- }
- }
- }
- }
|