|
@@ -7,6 +7,8 @@ import { UnitAction } from "../UnitAction";
|
|
|
import { EventDispatcher } from "db://assets/core_tgx/easy_ui_framework/EventDispatcher";
|
|
|
import { GameEvent } from "../Enum/GameEvent";
|
|
|
import { LevelAction } from "../LevelAction";
|
|
|
+import { LayerAction } from "../LayerAction";
|
|
|
+import { CarColors } from "../CarColorsGlobalTypes";
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('UnitColorsSysterm')
|
|
@@ -21,6 +23,7 @@ export class UnitColorsSysterm extends Component {
|
|
|
|
|
|
registerEvent() {
|
|
|
EventDispatcher.instance.on(GameEvent.EVENT_MAGNET, this.onMagnet, this);
|
|
|
+ // EventDispatcher.instance.on(GameEvent.EVENT_REFRESH_PIN_COLORS, this.changePinColor, this);
|
|
|
}
|
|
|
|
|
|
private onMagnet() {
|
|
@@ -85,6 +88,82 @@ export class UnitColorsSysterm extends Component {
|
|
|
this.clearpinsCar();
|
|
|
}
|
|
|
|
|
|
+ // changePinColor() {
|
|
|
+ // let activeLayerPins: PinComponent[] = [];
|
|
|
+ // const level = CarColorsGlobalInstance.instance.levels.children[0];
|
|
|
+ // const layer_arr = level.getComponent(LevelAction)!.get_all_layer();
|
|
|
+
|
|
|
+ // // 当前剩余的所有颜色保存的数组
|
|
|
+ // const carSeats: CarColors[] = CarColorsGlobalInstance.instance.carSysterm.carSeats;
|
|
|
+ // const findAllCars: CarColors[] = this.findCanOutCars();
|
|
|
+
|
|
|
+ // // 获取显示层上所有钉子组件
|
|
|
+ // for (const layer of layer_arr) {
|
|
|
+ // if (layer.layer_status !== 1) continue; // 只检查当前显示的层级
|
|
|
+ // const pins = layer.getComponentsInChildren(PinComponent)!;
|
|
|
+ // activeLayerPins.push(...pins);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // 初始化一个颜色设置数组,优先从 findAllCars 取颜色
|
|
|
+ // let colorPool: CarColors[] = [...findAllCars];
|
|
|
+
|
|
|
+ // // 如果 findAllCars 的颜色不够,用 carSeats 的颜色补充,但排除 findAllCars 里已有的颜色
|
|
|
+ // for (const seatColor of carSeats) {
|
|
|
+ // if (!findAllCars.includes(seatColor)) {
|
|
|
+ // colorPool.push(seatColor);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // 给 activeLayerPins 逐个分配颜色
|
|
|
+ // activeLayerPins.forEach((pin, index) => {
|
|
|
+ // if (index < colorPool.length) {
|
|
|
+ // pin.pin_color = colorPool[index]; // 假设 PinComponent 有 setColor 方法
|
|
|
+ // } else {
|
|
|
+ // console.warn(`Not enough colors to assign to pin at index ${index}`);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ //返回所有可以出车的车辆和停车位车辆 所有车辆钉子数组
|
|
|
+ findCanOutCars() {
|
|
|
+ const canOutCar: CarColors[] = [];
|
|
|
+ const cars = find("Canvas/Scene/Levels").children[0].getComponentsInChildren(CarCarColorsComponent)!;
|
|
|
+ cars.forEach(car => {
|
|
|
+ const carComp = car.getComponent(CarCarColorsComponent);
|
|
|
+ const collider = carComp.checkCollision();
|
|
|
+
|
|
|
+ if (!collider) {
|
|
|
+ const remainSeat = carComp.getRemainSeat();
|
|
|
+ for (let i = 0; i < remainSeat; i++) {
|
|
|
+ canOutCar.push(carComp.carColor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const points = find("Canvas/Scene/Parkings").children
|
|
|
+ for (let i = points.length; i--;) {
|
|
|
+ if (points[i].name === "inuse" && points[i].children.length === 1) {
|
|
|
+ const carComp = points[i].children[0].getComponent(CarCarColorsComponent);
|
|
|
+ const remainSeat = carComp.getRemainSeat();
|
|
|
+ for (let i = 0; i < remainSeat; i++) {
|
|
|
+ canOutCar.push(carComp.carColor);
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if (points[i].name === "inuse" && points[i].children.length === 2) {
|
|
|
+ const carComp = points[i].children[1].getComponent(CarCarColorsComponent);
|
|
|
+ const remainSeat = carComp.getRemainSeat();
|
|
|
+ for (let i = 0; i < remainSeat; i++) {
|
|
|
+ canOutCar.push(carComp.carColor);
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return canOutCar;
|
|
|
+ }
|
|
|
+
|
|
|
clearpinsCar() {
|
|
|
this.selectedCar = null
|
|
|
this.findPins = []
|