|
|
@@ -30,6 +30,8 @@ export class BulletLifecycle extends Component {
|
|
|
* 初始化生命周期
|
|
|
*/
|
|
|
public init(config: BulletLifecycleConfig, startPos: Vec3) {
|
|
|
+ console.log(`[BulletLifecycle] 初始化子弹生命周期 - 节点: ${this.node.name}, 配置类型: ${config.type}, 最大生命: ${config.maxLifetime}, 最大射程: ${config.maxRange}`);
|
|
|
+
|
|
|
this.config = { ...config };
|
|
|
|
|
|
this.state = {
|
|
|
@@ -44,7 +46,8 @@ export class BulletLifecycle extends Component {
|
|
|
returnTimer: config.returnDelay || 0
|
|
|
};
|
|
|
|
|
|
- this.lastPosition = this.node.worldPosition.clone();
|
|
|
+ this.lastPosition = startPos.clone();
|
|
|
+ console.log(`[BulletLifecycle] 子弹生命周期初始化完成 - 节点: ${this.node.name}, 起始位置: (${startPos.x}, ${startPos.y}), 当前位置: (${this.node.worldPosition.x}, ${this.node.worldPosition.y}), lastPosition: (${this.lastPosition.x}, ${this.lastPosition.y})`);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -216,7 +219,10 @@ export class BulletLifecycle extends Component {
|
|
|
}
|
|
|
|
|
|
update(dt: number) {
|
|
|
- if (!this.config || !this.state) return;
|
|
|
+ if (!this.config || !this.state) {
|
|
|
+ console.log(`[BulletLifecycle] update跳过 - 节点: ${this.node.name}, config存在: ${!!this.config}, state存在: ${!!this.state}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
this.state.elapsedTime += dt;
|
|
|
|
|
|
@@ -231,6 +237,7 @@ export class BulletLifecycle extends Component {
|
|
|
|
|
|
// 如果需要销毁,执行销毁
|
|
|
if (this.state.shouldDestroy) {
|
|
|
+ console.log(`[BulletLifecycle] 准备销毁子弹 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime}`);
|
|
|
this.destroyBullet();
|
|
|
}
|
|
|
}
|
|
|
@@ -241,6 +248,7 @@ export class BulletLifecycle extends Component {
|
|
|
private updateTravelDistance() {
|
|
|
const currentPos = this.node.worldPosition;
|
|
|
const distance = Vec3.distance(this.lastPosition, currentPos);
|
|
|
+ console.log(`[BulletLifecycle] 更新飞行距离 - 节点: ${this.node.name}, 上次位置: (${this.lastPosition.x}, ${this.lastPosition.y}), 当前位置: (${currentPos.x}, ${currentPos.y}), 本次距离: ${distance}, 总距离: ${this.state.travelDistance} -> ${this.state.travelDistance + distance}`);
|
|
|
this.state.travelDistance += distance;
|
|
|
this.lastPosition.set(currentPos);
|
|
|
}
|
|
|
@@ -249,19 +257,25 @@ export class BulletLifecycle extends Component {
|
|
|
* 检查销毁条件
|
|
|
*/
|
|
|
private checkDestroyConditions() {
|
|
|
+ console.log(`[BulletLifecycle] 检查销毁条件 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime}, 最大生命: ${this.config.maxLifetime}, 飞行距离: ${this.state.travelDistance}, 最大射程: ${this.config.maxRange}`);
|
|
|
+
|
|
|
// 检查时间限制
|
|
|
if (this.state.elapsedTime >= this.config.maxLifetime) {
|
|
|
+ console.log(`[BulletLifecycle] 子弹因超时被销毁 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime} >= 最大生命: ${this.config.maxLifetime}`);
|
|
|
this.state.shouldDestroy = true;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// === 射程限制逻辑优化 ===
|
|
|
if (this.config.maxRange && this.state.travelDistance >= this.config.maxRange) {
|
|
|
+ console.log(`[BulletLifecycle] 子弹达到最大射程 - 节点: ${this.node.name}, 飞行距离: ${this.state.travelDistance} >= 最大射程: ${this.config.maxRange}, 类型: ${this.config.type}`);
|
|
|
if (this.config.type === 'range_limit') {
|
|
|
+ console.log(`[BulletLifecycle] 子弹因射程限制被销毁 - 节点: ${this.node.name}`);
|
|
|
this.state.shouldDestroy = true;
|
|
|
} else if (this.config.type === 'return_trip') {
|
|
|
// 回旋镖:首次超距时开始返回;返回途中不再因射程销毁
|
|
|
if (this.state.phase === 'active') {
|
|
|
+ console.log(`[BulletLifecycle] 回旋镖开始返回 - 节点: ${this.node.name}`);
|
|
|
this.startReturn();
|
|
|
}
|
|
|
}
|
|
|
@@ -270,10 +284,14 @@ export class BulletLifecycle extends Component {
|
|
|
}
|
|
|
|
|
|
// 检查越界
|
|
|
- if (this.checkOutOfBounds()) {
|
|
|
+ const outOfBounds = this.checkOutOfBounds();
|
|
|
+ console.log(`[BulletLifecycle] 越界检查结果 - 节点: ${this.node.name}, 是否越界: ${outOfBounds}, 位置: (${this.node.worldPosition.x}, ${this.node.worldPosition.y})`);
|
|
|
+ if (outOfBounds) {
|
|
|
if (this.config.type === 'return_trip' && this.state.phase === 'active') {
|
|
|
+ console.log(`[BulletLifecycle] 回旋镖因越界开始返回 - 节点: ${this.node.name}`);
|
|
|
this.startReturn();
|
|
|
} else {
|
|
|
+ console.log(`[BulletLifecycle] 子弹因越界被销毁 - 节点: ${this.node.name}, 位置: (${this.node.worldPosition.x}, ${this.node.worldPosition.y})`);
|
|
|
this.state.shouldDestroy = true;
|
|
|
}
|
|
|
return;
|
|
|
@@ -333,6 +351,7 @@ export class BulletLifecycle extends Component {
|
|
|
const tr = gameArea.getComponent(UITransform);
|
|
|
if (tr) {
|
|
|
bounding = tr.getBoundingBoxToWorld();
|
|
|
+ console.log(`[BulletLifecycle] 使用GameArea边界 - 节点: ${this.node.name}, 边界: (${bounding.xMin}, ${bounding.yMin}) 到 (${bounding.xMax}, ${bounding.yMax})`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -343,28 +362,38 @@ export class BulletLifecycle extends Component {
|
|
|
const tr = canvas.getComponent(UITransform);
|
|
|
if (tr) {
|
|
|
bounding = tr.getBoundingBoxToWorld();
|
|
|
+ console.log(`[BulletLifecycle] 使用Canvas边界 - 节点: ${this.node.name}, 边界: (${bounding.xMin}, ${bounding.yMin}) 到 (${bounding.xMax}, ${bounding.yMax})`);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 若无法获取区域,则不做越界销毁
|
|
|
- if (!bounding) return false;
|
|
|
+ if (!bounding) {
|
|
|
+ console.log(`[BulletLifecycle] 无法获取边界信息 - 节点: ${this.node.name}, 不进行越界检查`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
// 允许一定的 margin
|
|
|
const margin = 300; // 扩大容差,防止大速度时瞬移出界
|
|
|
const pos = this.node.worldPosition;
|
|
|
-
|
|
|
- return pos.x < bounding.xMin - margin ||
|
|
|
- pos.x > bounding.xMax + margin ||
|
|
|
- pos.y < bounding.yMin - margin ||
|
|
|
- pos.y > bounding.yMax + margin;
|
|
|
+
|
|
|
+ const outOfBounds = pos.x < bounding.xMin - margin ||
|
|
|
+ pos.x > bounding.xMax + margin ||
|
|
|
+ pos.y < bounding.yMin - margin ||
|
|
|
+ pos.y > bounding.yMax + margin;
|
|
|
+
|
|
|
+ console.log(`[BulletLifecycle] 越界详细检查 - 节点: ${this.node.name}, 位置: (${pos.x}, ${pos.y}), 边界(含margin): (${bounding.xMin - margin}, ${bounding.yMin - margin}) 到 (${bounding.xMax + margin}, ${bounding.yMax + margin}), 结果: ${outOfBounds}`);
|
|
|
+
|
|
|
+ return outOfBounds;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 销毁子弹
|
|
|
*/
|
|
|
private destroyBullet() {
|
|
|
+ console.log(`[BulletLifecycle] 执行销毁子弹 - 节点: ${this.node.name}, 存活时间: ${this.state.elapsedTime}, 飞行距离: ${this.state.travelDistance}`);
|
|
|
this.node.destroy();
|
|
|
+ console.log(`[BulletLifecycle] 子弹已销毁 - 节点: ${this.node.name}`);
|
|
|
}
|
|
|
|
|
|
/**
|