feat(skill): 优化技能碰撞检测逻辑并添加移动数据组件

- 新增 StimeDataComp 组件用于存储技能移动相关数据
- 修改 SMoveSystem 中距离结束和碰撞结束时的销毁逻辑,增加关闭碰撞体操作
- 重构 SkillView 的碰撞检测启用逻辑,提取为 enable_collider_safely 方法确保安全性
- 修复攻击帧事件中碰撞检测的启用条件,避免无效操作
This commit is contained in:
walkpan
2026-03-15 23:02:24 +08:00
parent ad9799d938
commit 9c21ab748e
4 changed files with 44 additions and 7 deletions

View File

@@ -136,7 +136,11 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
// 检查移动完成
if (moveComp.isCompleted && moveComp.autoDestroy) {
// 根据结束类型决定是否销毁
if (moveComp.endType === EType.timeEnd || moveComp.endType === EType.collision) {
if (
moveComp.endType === EType.distanceEnd ||
moveComp.endType === EType.collision
) {
skillView.close_collider();
entity.destroy();
}
}
@@ -229,4 +233,4 @@ export class SMoveHelper {
moveComp.stopMove();
}
}
}
}

View File

@@ -0,0 +1,25 @@
import { Vec3, v3, Node } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { RType, EType, SkillSet } from "../common/config/SkillSet";
import { BoxSet } from "../common/config/GameSet";
import { SkillView } from "./SkillView";
import { smc } from "../common/SingletonModuleComp";
/**
* ==================== 技能移动数据组件 ====================
*
* 用途:
* - 存储技能实体的移动相关数据
* - 管理移动状态和参数
* - 支持多种移动类型(线性、贝塞尔、固定位置等)
*/
@ecs.register('StimeDataComp')
export class StimeDataComp extends ecs.Comp {
/** 技能UUID */
s_uuid: number = 0;
reset() {
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"f39d7998-2039-4411-9dd2-77db452d0a6d","files":[],"subMetas":{},"userData":{}}

View File

@@ -103,11 +103,7 @@ export class SkillView extends CCComp {
// //动画帧事件 atk 触发
public atk(args:any){
this.attackFrameCount++;
// 开启碰撞检测
if(this.collider) {
this.pendingDisableCollider = false;
this.collider.enabled = true;
if (this.enable_collider_safely()) {
mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf?.name}] 第${this.attackFrameCount}次攻击帧开启碰撞检测`);
}
@@ -175,6 +171,17 @@ export class SkillView extends CCComp {
this.isDisposing = true;
this.close_collider();
}
private enable_collider_safely(): boolean {
if (!this.collider || !this.collider.isValid) return false;
if (this.isDisposing) return false;
if (!this.node || !this.node.isValid || !this.node.activeInHierarchy) return false;
this.pendingDisableCollider = false;
this.collider.group = this.group;
this.collider.off(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
this.collider.enabled = true;
return true;
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
// 清理碰撞体事件监听