|
|
@@ -122,7 +122,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 如果已经初始化,重新设置事件监听器(因为onDisable时会移除)
|
|
|
this.setupEventListeners();
|
|
|
}
|
|
|
- this.initDebugDraw();
|
|
|
+ // this.initDebugDraw();
|
|
|
}
|
|
|
|
|
|
start() {
|
|
|
@@ -644,7 +644,7 @@ export class GameBlockSelection extends Component {
|
|
|
);
|
|
|
|
|
|
// 更新调试绘制
|
|
|
- this.updateDebugDraw();
|
|
|
+ // this.updateDebugDraw();
|
|
|
}, this);
|
|
|
|
|
|
block.on(Node.EventType.TOUCH_END, async (event: EventTouch) => {
|
|
|
@@ -677,7 +677,7 @@ export class GameBlockSelection extends Component {
|
|
|
if (collider) collider.enabled = true;
|
|
|
|
|
|
// 更新调试绘制
|
|
|
- this.updateDebugDraw();
|
|
|
+ // this.updateDebugDraw();
|
|
|
}
|
|
|
}, this);
|
|
|
|
|
|
@@ -694,7 +694,7 @@ export class GameBlockSelection extends Component {
|
|
|
if (collider) collider.enabled = true;
|
|
|
|
|
|
// 更新调试绘制
|
|
|
- this.updateDebugDraw();
|
|
|
+ // this.updateDebugDraw();
|
|
|
}
|
|
|
}, this);
|
|
|
}
|
|
|
@@ -987,94 +987,94 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 初始化调试绘制
|
|
|
private initDebugDraw() {
|
|
|
- if (!this.debugDrawSnapRange) return;
|
|
|
-
|
|
|
- // 创建调试绘制节点
|
|
|
- this.debugDrawNode = new Node('DebugDraw');
|
|
|
- this.debugGraphics = this.debugDrawNode.addComponent(Graphics);
|
|
|
-
|
|
|
- // 将调试绘制节点添加到场景中
|
|
|
- if (this.gridContainer && this.gridContainer.parent) {
|
|
|
- this.gridContainer.parent.addChild(this.debugDrawNode);
|
|
|
- }
|
|
|
-
|
|
|
- console.log('[GameBlockSelection] 调试绘制初始化完成');
|
|
|
+ // if (!this.debugDrawSnapRange) return;
|
|
|
+ //
|
|
|
+ // // 创建调试绘制节点
|
|
|
+ // this.debugDrawNode = new Node('DebugDraw');
|
|
|
+ // this.debugGraphics = this.debugDrawNode.addComponent(Graphics);
|
|
|
+ //
|
|
|
+ // // 将调试绘制节点添加到场景中
|
|
|
+ // if (this.gridContainer && this.gridContainer.parent) {
|
|
|
+ // this.gridContainer.parent.addChild(this.debugDrawNode);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // console.log('[GameBlockSelection] 调试绘制初始化完成');
|
|
|
}
|
|
|
|
|
|
// 绘制网格吸附范围
|
|
|
private drawGridSnapRanges() {
|
|
|
- if (!this.debugDrawSnapRange || !this.debugGraphics || !this.blockManager) return;
|
|
|
-
|
|
|
- this.debugGraphics.strokeColor = Color.GREEN;
|
|
|
- this.debugGraphics.lineWidth = 2;
|
|
|
-
|
|
|
- // 通过BlockManager获取网格信息来绘制吸附范围
|
|
|
- const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
|
|
|
- const snapRange = gridSpacing * 0.8; // 吸附范围
|
|
|
-
|
|
|
- // 遍历所有网格位置,绘制吸附范围
|
|
|
- for (let row = 0; row < 6; row++) {
|
|
|
- for (let col = 0; col < 11; col++) {
|
|
|
- // 计算网格世界坐标
|
|
|
- const gridWorldPos = this.blockManager.getGridWorldPosition(row, col);
|
|
|
- if (!gridWorldPos) continue;
|
|
|
-
|
|
|
- // 转换为调试绘制节点的本地坐标
|
|
|
- const localPos = new Vec3();
|
|
|
- this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(gridWorldPos, localPos);
|
|
|
-
|
|
|
- // 绘制网格吸附范围圆圈
|
|
|
- this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
|
|
|
- this.debugGraphics.stroke();
|
|
|
- }
|
|
|
- }
|
|
|
+ // if (!this.debugDrawSnapRange || !this.debugGraphics || !this.blockManager) return;
|
|
|
+ //
|
|
|
+ // this.debugGraphics.strokeColor = Color.GREEN;
|
|
|
+ // this.debugGraphics.lineWidth = 2;
|
|
|
+ //
|
|
|
+ // // 通过BlockManager获取网格信息来绘制吸附范围
|
|
|
+ // const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
|
|
|
+ // const snapRange = gridSpacing * 0.8; // 吸附范围
|
|
|
+ //
|
|
|
+ // // 遍历所有网格位置,绘制吸附范围
|
|
|
+ // for (let row = 0; row < 6; row++) {
|
|
|
+ // for (let col = 0; col < 11; col++) {
|
|
|
+ // // 计算网格世界坐标
|
|
|
+ // const gridWorldPos = this.blockManager.getGridWorldPosition(row, col);
|
|
|
+ // if (!gridWorldPos) continue;
|
|
|
+ //
|
|
|
+ // // 转换为调试绘制节点的本地坐标
|
|
|
+ // const localPos = new Vec3();
|
|
|
+ // this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(gridWorldPos, localPos);
|
|
|
+ //
|
|
|
+ // // 绘制网格吸附范围圆圈
|
|
|
+ // this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
|
|
|
+ // this.debugGraphics.stroke();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
// 绘制方块吸附范围
|
|
|
private drawBlockSnapRange(block: Node) {
|
|
|
- if (!this.debugDrawSnapRange || !this.debugGraphics || !block || !this.blockManager) return;
|
|
|
-
|
|
|
- // 绘制方块吸附点
|
|
|
- this.debugGraphics.strokeColor = Color.RED;
|
|
|
- this.debugGraphics.fillColor = Color.RED;
|
|
|
- this.debugGraphics.lineWidth = 3;
|
|
|
-
|
|
|
- const blockParts = this.blockManager.getBlockParts(block);
|
|
|
- const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
|
|
|
- const snapRange = gridSpacing * 0.6; // 吸附范围
|
|
|
-
|
|
|
- blockParts.forEach(part => {
|
|
|
- const worldPos = part.node.getWorldPosition();
|
|
|
- const localPos = new Vec3();
|
|
|
- this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(worldPos, localPos);
|
|
|
-
|
|
|
- // 绘制红色十字标记吸附点
|
|
|
- const crossSize = 10;
|
|
|
- this.debugGraphics.moveTo(localPos.x - crossSize, localPos.y);
|
|
|
- this.debugGraphics.lineTo(localPos.x + crossSize, localPos.y);
|
|
|
- this.debugGraphics.moveTo(localPos.x, localPos.y - crossSize);
|
|
|
- this.debugGraphics.lineTo(localPos.x, localPos.y + crossSize);
|
|
|
- this.debugGraphics.stroke();
|
|
|
-
|
|
|
- // 绘制吸附范围圆圈
|
|
|
- this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
|
|
|
- this.debugGraphics.stroke();
|
|
|
- });
|
|
|
+ // if (!this.debugDrawSnapRange || !this.debugGraphics || !block || !this.blockManager) return;
|
|
|
+ //
|
|
|
+ // // 绘制方块吸附点
|
|
|
+ // this.debugGraphics.strokeColor = Color.RED;
|
|
|
+ // this.debugGraphics.fillColor = Color.RED;
|
|
|
+ // this.debugGraphics.lineWidth = 3;
|
|
|
+ //
|
|
|
+ // const blockParts = this.blockManager.getBlockParts(block);
|
|
|
+ // const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
|
|
|
+ // const snapRange = gridSpacing * 0.6; // 吸附范围
|
|
|
+ //
|
|
|
+ // blockParts.forEach(part => {
|
|
|
+ // const worldPos = part.node.getWorldPosition();
|
|
|
+ // const localPos = new Vec3();
|
|
|
+ // this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(worldPos, localPos);
|
|
|
+ //
|
|
|
+ // // 绘制红色十字标记吸附点
|
|
|
+ // const crossSize = 10;
|
|
|
+ // this.debugGraphics.moveTo(localPos.x - crossSize, localPos.y);
|
|
|
+ // this.debugGraphics.lineTo(localPos.x + crossSize, localPos.y);
|
|
|
+ // this.debugGraphics.moveTo(localPos.x, localPos.y - crossSize);
|
|
|
+ // this.debugGraphics.lineTo(localPos.x, localPos.y + crossSize);
|
|
|
+ // this.debugGraphics.stroke();
|
|
|
+ //
|
|
|
+ // // 绘制吸附范围圆圈
|
|
|
+ // this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
|
|
|
+ // this.debugGraphics.stroke();
|
|
|
+ // });
|
|
|
}
|
|
|
|
|
|
// 更新调试绘制
|
|
|
private updateDebugDraw() {
|
|
|
- if (!this.debugDrawSnapRange || !this.debugGraphics) return;
|
|
|
-
|
|
|
- this.debugGraphics.clear();
|
|
|
-
|
|
|
- // 绘制网格吸附范围
|
|
|
- this.drawGridSnapRanges();
|
|
|
-
|
|
|
- // 如果有正在拖拽的方块,绘制其吸附范围
|
|
|
- if (this.currentDragBlock) {
|
|
|
- this.drawBlockSnapRange(this.currentDragBlock);
|
|
|
- }
|
|
|
+ // if (!this.debugDrawSnapRange || !this.debugGraphics) return;
|
|
|
+ //
|
|
|
+ // this.debugGraphics.clear();
|
|
|
+ //
|
|
|
+ // // 绘制网格吸附范围
|
|
|
+ // this.drawGridSnapRanges();
|
|
|
+ //
|
|
|
+ // // 如果有正在拖拽的方块,绘制其吸附范围
|
|
|
+ // if (this.currentDragBlock) {
|
|
|
+ // this.drawBlockSnapRange(this.currentDragBlock);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
// 清理调试绘制
|
|
|
@@ -1090,11 +1090,11 @@ export class GameBlockSelection extends Component {
|
|
|
public setDebugDrawSnapRange(enabled: boolean) {
|
|
|
this.debugDrawSnapRange = enabled;
|
|
|
|
|
|
- if (enabled) {
|
|
|
- this.initDebugDraw();
|
|
|
- } else {
|
|
|
- this.cleanupDebugDraw();
|
|
|
- }
|
|
|
+ // if (enabled) {
|
|
|
+ // this.initDebugDraw();
|
|
|
+ // } else {
|
|
|
+ // this.cleanupDebugDraw();
|
|
|
+ // }
|
|
|
|
|
|
console.log(`[GameBlockSelection] 调试绘制已${enabled ? '开启' : '关闭'}`);
|
|
|
}
|