|
@@ -10,7 +10,8 @@ import { tgxUIMgr } from '../../core_tgx/tgx';
|
|
|
import { UI_BattleResult } from '../../scripts/UIDef';
|
|
|
import { LevelManager } from './Manager/LevelMgr';
|
|
|
import { CarBoxComponent } from './Components/CarBoxComponent';
|
|
|
-import { CarColors } from './CarColorsGlobalTypes';
|
|
|
+import { CarColors, CarTypes } from './CarColorsGlobalTypes';
|
|
|
+import { GameUtil } from './GameUtil';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
enum ParkingStatus {
|
|
@@ -47,7 +48,7 @@ export class LevelAction extends Component {
|
|
|
return hole_num;
|
|
|
}
|
|
|
|
|
|
- public init_level() {
|
|
|
+ async init_level() {
|
|
|
for (let i = 0; i < this.node.children.length; i++) {
|
|
|
const temp = this.node.children[i];
|
|
|
if (temp.getComponent(CarCarColorsComponent) || temp.getComponent(CarBoxComponent)) {
|
|
@@ -61,9 +62,9 @@ export class LevelAction extends Component {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ await GameUtil.delay(0.2);
|
|
|
CarColorsGlobalInstance.instance.carSysterm.sortCarSeatsByDifficulty();
|
|
|
const color_pin_arr = CarColorsGlobalInstance.instance.carSysterm.carSeats;
|
|
|
- console.log(color_pin_arr);
|
|
|
this.node.children.forEach(unit_node => {
|
|
|
if (unit_node.getComponent(UnitAction)) {
|
|
|
unit_node.getComponent(UnitAction)!.init_pin(color_pin_arr);
|
|
@@ -72,9 +73,9 @@ export class LevelAction extends Component {
|
|
|
|
|
|
this.init_parking();
|
|
|
//默认隐藏一些
|
|
|
- this.scheduleOnce(() => {
|
|
|
- this.set_default_layer();
|
|
|
- }, 0.2)
|
|
|
+ await GameUtil.delay(0.2);
|
|
|
+ this.set_default_layer();
|
|
|
+ // this.set_pin_color();
|
|
|
}
|
|
|
|
|
|
init_parking() {
|
|
@@ -134,7 +135,8 @@ export class LevelAction extends Component {
|
|
|
if (show_num <= default_show_layer_num) {
|
|
|
if (layer_action.layer_status != 1) {
|
|
|
layer_action.set_status(1);
|
|
|
- // EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_PIN_COLORS);
|
|
|
+ this.check_pins_block();
|
|
|
+ // this.set_pin_color();
|
|
|
}
|
|
|
} else if (show_num == (default_show_layer_num + 1)) {
|
|
|
if (layer_action.layer_status != 2) {
|
|
@@ -144,10 +146,59 @@ export class LevelAction extends Component {
|
|
|
layer_action.set_status(0);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ //动态给钉子上色
|
|
|
+ private async set_pin_color() {
|
|
|
+ const carSysterm = CarColorsGlobalInstance.instance.carSysterm;
|
|
|
+ let layer_arr = this.get_all_layer();
|
|
|
+ let canOutCars = carSysterm.findCanOutCars(); // 找到所有无障碍物的车子
|
|
|
+
|
|
|
+ if (canOutCars.length === 0) {
|
|
|
+ console.warn("没有可以开出的车,无法分配颜色");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let allPins: any[] = [];
|
|
|
+
|
|
|
+ // 获取所有可见钉子
|
|
|
+ layer_arr.forEach(layer => {
|
|
|
+ if (layer.layer_status === 1) {
|
|
|
+ let pinArr: any[] = [];
|
|
|
+ layer.get_pin_color(pinArr);
|
|
|
+ allPins.push(...pinArr);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log("总可见钉子数量:", allPins.length);
|
|
|
+ if (allPins.length === 0) return;
|
|
|
+
|
|
|
+ let pinIndex = 0; // 记录当前分配到哪个钉子
|
|
|
+ for (let car of canOutCars) {
|
|
|
+ let carComp = car.getComponent(CarCarColorsComponent);
|
|
|
+ let carColor = carComp.carColor;
|
|
|
+ let seatCount = this.getCarSeatCount(carComp.carType); // 获取车的载客量
|
|
|
|
|
|
- this.check_pins_block();
|
|
|
+ // 遍历当前车的座位数,依次给钉子赋值
|
|
|
+ for (let i = 0; i < seatCount; i++) {
|
|
|
+ if (pinIndex >= allPins.length) return; // 说明钉子已经全部分配完毕
|
|
|
+ allPins[pinIndex].pin_color = carColor;
|
|
|
+ pinIndex++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /** 根据车辆类型获取对应的载客量 */
|
|
|
+ private getCarSeatCount(carType: CarTypes): number {
|
|
|
+ switch (carType) {
|
|
|
+ case CarTypes.Sedan: return 4; // 4座
|
|
|
+ case CarTypes.Minivan: return 6; // 6座
|
|
|
+ case CarTypes.Bus: return 8; // 8座
|
|
|
+ default: return 4; // 默认最小
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//每个钉子检测是否被遮挡
|
|
|
private async check_pins_block() {
|
|
|
let layer_arr = this.get_all_layer();
|
|
@@ -260,7 +311,7 @@ export class LevelAction extends Component {
|
|
|
}
|
|
|
|
|
|
//检测游戏是否结束
|
|
|
- checkGameOver() {
|
|
|
+ async checkGameOver() {
|
|
|
const checkOver = () => {
|
|
|
const { isEnd } = LevelManager.instance.levelModel;
|
|
|
if (isEnd) return;
|