refactor(skill): 重构技能配置加载逻辑,将参数下沉至prefab配置
1. 新增SkillView组件属性runType/endType/speed/time,替换原配置表字段 2. 批量同步所有技能prefab的配置参数 3. 优化技能运行逻辑,优先使用prefab配置,配置表仅作兜底 4. 新增同步脚本用于批量迁移技能配置
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { v3, Vec3 ,Node} from "cc";
|
||||
import { v3, Vec3, Node } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { EType, RType, SkillSet } from "../common/config/SkillSet";
|
||||
import { SMoveDataComp } from "./SMoveComp";
|
||||
@@ -26,46 +26,46 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(SMoveDataComp, SkillView);
|
||||
}
|
||||
|
||||
|
||||
entityEnter(entity: ecs.Entity): void {
|
||||
const moveComp = entity.get(SMoveDataComp);
|
||||
const skillView = entity.get(SkillView);
|
||||
|
||||
|
||||
if (!moveComp || !skillView || !skillView.node) return;
|
||||
|
||||
|
||||
// 获取技能配置
|
||||
const skillConfig = SkillSet[moveComp.s_uuid];
|
||||
if (!skillConfig) {
|
||||
mLogger.warn(this.debugMode, 'SMoveSystem', `[SMoveSystem] 技能配置不存在: ${moveComp.s_uuid}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据配置设置移动速度与加速度
|
||||
if (skillConfig.speed > 0) {
|
||||
|
||||
// 移动参数由 prefab 的 SkillView @property 决定(speed<=0 时 Skill.load 已回退配置表值)
|
||||
if (moveComp.speed <= 0) {
|
||||
moveComp.speed = skillConfig.speed;
|
||||
}
|
||||
if (skillConfig.is_accel) {
|
||||
moveComp.isAccelerate = true;
|
||||
}
|
||||
|
||||
|
||||
// 根据runType设置初始位置
|
||||
this.initializePosition(moveComp, skillView);
|
||||
|
||||
|
||||
// 开始移动(除了固定位置类型)
|
||||
if (moveComp.runType !== RType.fixed && moveComp.runType !== RType.fixedEnd) {
|
||||
moveComp.startMove();
|
||||
}
|
||||
|
||||
|
||||
mLogger.log(this.debugMode, 'SMoveSystem', `[SMoveSystem] 技能 ${skillConfig.name} 开始移动,类型: ${moveComp.runType}`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据runType初始化技能位置
|
||||
*/
|
||||
private initializePosition(moveComp: SMoveDataComp, skillView: SkillView): void {
|
||||
const node = skillView.node;
|
||||
|
||||
switch(moveComp.runType) {
|
||||
|
||||
switch (moveComp.runType) {
|
||||
case RType.linear:
|
||||
// linear类型:根据atk_x和atk_y调整起始位置
|
||||
const adjustedStartPos = v3(
|
||||
@@ -73,35 +73,35 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
moveComp.startPos.y + moveComp.atk_y,
|
||||
moveComp.startPos.z
|
||||
);
|
||||
|
||||
|
||||
const originTargetPos = v3(
|
||||
moveComp.targetPos.x,
|
||||
moveComp.targetPos.y,
|
||||
moveComp.targetPos.z
|
||||
);
|
||||
|
||||
|
||||
const direction = new Vec3();
|
||||
Vec3.subtract(direction, originTargetPos, adjustedStartPos);
|
||||
|
||||
|
||||
// 延长终止点,统一消亡点的x坐标为 +-500
|
||||
const targetX = moveComp.scale > 0 ? 500 : -500;
|
||||
let targetY = originTargetPos.y;
|
||||
|
||||
|
||||
if (Math.abs(direction.x) > 0.01) {
|
||||
const slope = direction.y / direction.x;
|
||||
targetY = adjustedStartPos.y + slope * (targetX - adjustedStartPos.x);
|
||||
}
|
||||
|
||||
|
||||
const adjustedTargetPos = v3(
|
||||
targetX,
|
||||
targetY,
|
||||
originTargetPos.z
|
||||
);
|
||||
|
||||
|
||||
moveComp.startPos.set(adjustedStartPos);
|
||||
moveComp.targetPos.set(adjustedTargetPos);
|
||||
node.setPosition(adjustedStartPos);
|
||||
|
||||
|
||||
// 设置旋转角度
|
||||
const dirForAngle = new Vec3();
|
||||
Vec3.subtract(dirForAngle, adjustedTargetPos, adjustedStartPos);
|
||||
@@ -113,12 +113,12 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
node.angle = angle;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case RType.fixed:
|
||||
// 固定起始位置
|
||||
node.setPosition(moveComp.startPos.x, node.position.y, 0);
|
||||
break;
|
||||
|
||||
|
||||
case RType.fixedEnd:
|
||||
// 固定结束位置
|
||||
node.setPosition(moveComp.targetPos.x > 360 ? 300 : moveComp.targetPos.x, moveComp.targetPos.y, 0);
|
||||
@@ -154,26 +154,26 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
}
|
||||
|
||||
update(entity: ecs.Entity): void {
|
||||
if(!smc.mission.play ) return;
|
||||
if(smc.mission.pause) return
|
||||
if (!smc.mission.play) return;
|
||||
if (smc.mission.pause) return
|
||||
const moveComp = entity.get(SMoveDataComp);
|
||||
const skillView = entity.get(SkillView);
|
||||
|
||||
|
||||
if (!moveComp || !skillView || !skillView.node) return;
|
||||
|
||||
|
||||
// 更新移动进度
|
||||
const isMoving = moveComp.updateProgress(this.dt);
|
||||
|
||||
|
||||
if (isMoving) {
|
||||
// 更新节点位置
|
||||
skillView.node.setPosition(moveComp.currentPos);
|
||||
|
||||
|
||||
// 处理自动旋转(贝塞尔移动)
|
||||
if (moveComp.runType === RType.bezier) {
|
||||
this.updateRotation(skillView.node, moveComp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 检查移动完成
|
||||
if (moveComp.isCompleted && moveComp.autoDestroy) {
|
||||
// 根据结束类型决定是否销毁
|
||||
@@ -185,7 +185,7 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新节点旋转(用于贝塞尔移动)
|
||||
*/
|
||||
@@ -193,29 +193,29 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
if (moveComp.progress < 1) {
|
||||
// 计算下一帧的位置来确定方向
|
||||
const nextProgress = Math.min(moveComp.progress + 0.01, 1);
|
||||
const t = moveComp.isAccelerate ?
|
||||
(nextProgress * nextProgress * 0.7 + nextProgress * 0.3) :
|
||||
const t = moveComp.isAccelerate ?
|
||||
(nextProgress * nextProgress * 0.7 + nextProgress * 0.3) :
|
||||
nextProgress;
|
||||
const nextPos = v3(0, 0, 0);
|
||||
|
||||
|
||||
// 计算下一个位置
|
||||
const oneMinusT = 1 - t;
|
||||
const oneMinusTSquared = oneMinusT * oneMinusT;
|
||||
const tSquared = t * t;
|
||||
const twoOneMinusTt = 2 * oneMinusT * t;
|
||||
|
||||
nextPos.x = oneMinusTSquared * moveComp.startPos.x +
|
||||
twoOneMinusTt * moveComp.controlPoint.x +
|
||||
tSquared * moveComp.targetPos.x;
|
||||
|
||||
nextPos.y = oneMinusTSquared * moveComp.startPos.y +
|
||||
twoOneMinusTt * moveComp.controlPoint.y +
|
||||
tSquared * moveComp.targetPos.y;
|
||||
|
||||
|
||||
nextPos.x = oneMinusTSquared * moveComp.startPos.x +
|
||||
twoOneMinusTt * moveComp.controlPoint.x +
|
||||
tSquared * moveComp.targetPos.x;
|
||||
|
||||
nextPos.y = oneMinusTSquared * moveComp.startPos.y +
|
||||
twoOneMinusTt * moveComp.controlPoint.y +
|
||||
tSquared * moveComp.targetPos.y;
|
||||
|
||||
// 计算方向角度
|
||||
const direction = new Vec3();
|
||||
Vec3.subtract(direction, nextPos, moveComp.currentPos);
|
||||
|
||||
|
||||
if (direction.length() > 0.01) {
|
||||
let angle = Math.atan2(direction.y, direction.x) * (180 / Math.PI);
|
||||
if (moveComp.scale < 0) {
|
||||
@@ -236,15 +236,15 @@ export class SMoveHelper {
|
||||
*/
|
||||
static setupMoveForSkill(entity: ecs.Entity, startPos: Vec3, targetPos: Vec3, s_uuid: number): void {
|
||||
let moveComp = entity.get(SMoveDataComp);
|
||||
|
||||
|
||||
if (!moveComp) {
|
||||
moveComp = entity.add(SMoveDataComp);
|
||||
}
|
||||
|
||||
|
||||
moveComp.startPos.set(startPos);
|
||||
moveComp.targetPos.set(targetPos);
|
||||
moveComp.s_uuid = s_uuid;
|
||||
|
||||
|
||||
// 从技能配置获取默认参数
|
||||
const skillConfig = SkillSet[s_uuid];
|
||||
if (skillConfig) {
|
||||
@@ -253,7 +253,7 @@ export class SMoveHelper {
|
||||
if (skillConfig.is_accel) moveComp.isAccelerate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查技能是否正在移动
|
||||
*/
|
||||
@@ -261,7 +261,7 @@ export class SMoveHelper {
|
||||
const moveComp = entity.get(SMoveDataComp);
|
||||
return moveComp ? moveComp.isMoving : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取技能移动统计信息
|
||||
*/
|
||||
@@ -269,7 +269,7 @@ export class SMoveHelper {
|
||||
const moveComp = entity.get(SMoveDataComp);
|
||||
return moveComp ? moveComp.getMoveStats() : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 停止技能移动
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user