用户报告 BallController.ts 似乎没有应用 ballController.json 中的配置数据。
通过代码检查发现以下问题:
BallControllerConfig 接口缺少 maxAttempts 参数定义BallController.ts 中的默认配置缺少 maxAttempts 参数positionBallRandomly 方法中硬编码了 maxAttempts = 50,没有使用配置值maxAttempts 的 getter 方法文件: assets/scripts/Core/ConfigManager.ts
BallControllerConfig 接口中添加 maxAttempts: number 参数文件: assets/scripts/CombatSystem/BallController.ts
maxAttempts: 50 参数文件: assets/scripts/CombatSystem/BallController.ts
get maxAttempts() 方法,使用 getConfigValue 获取配置值文件: assets/scripts/CombatSystem/BallController.ts
positionBallRandomly 方法中的硬编码 maxAttempts = 50 改为 this.maxAttempts当前 ballController.json 包含以下19个配置参数:
| 参数名 | 类型 | 当前值 | 说明 |
|---|---|---|---|
| baseSpeed | number | 30 | 球的基础移动速度 |
| maxReflectionRandomness | number | 0.2 | 反弹随机偏移最大角度 |
| antiTrapTimeWindow | number | 5 | 防围困时间窗口 |
| antiTrapHitThreshold | number | 5 | 防围困撞击阈值 |
| deflectionAttemptThreshold | number | 3 | 偏移尝试阈值 |
| antiTrapDeflectionMultiplier | number | 3 | 防围困偏移倍数 |
| FIRE_COOLDOWN | number | 0.05 | 子弹发射冷却时间 |
| ballRadius | number | 25 | 球的半径 |
| gravityScale | number | 0 | 重力缩放 |
| linearDamping | number | 0 | 线性阻尼 |
| angularDamping | number | 0 | 角阻尼 |
| colliderGroup | number | 1 | 碰撞组 |
| colliderTag | number | 1 | 碰撞标签 |
| friction | number | 0 | 摩擦力 |
| restitution | number | 1 | 弹性系数 |
| safeDistance | number | 20 | 安全距离 |
| edgeOffset | number | 20 | 边缘偏移 |
| sensor | boolean | false | 传感器模式 |
| maxAttempts | number | 50 | 最大尝试次数 |
loadConfig() 方法在 start() 时调用applyConfig() 方法将配置值赋给类属性getConfigValue() 获取配置值✅ 配置应用验证通过:
ballController.json 文件拖拽到 BallController 组件的 ballControllerConfig 属性中ballController.json 中的参数值后,重新运行游戏即可生效true 或 false