|
|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, Component, Node, Prefab, instantiate, Vec3, EventTouch, Vec2, UITransform, find, Rect, Label, Color, Size, Sprite, SpriteFrame, resources, Button, Collider2D } from 'cc';
|
|
|
+import { _decorator, Component, Node, Prefab, instantiate, Vec3, EventTouch, Vec2, UITransform, find, Rect, Label, Color, Size, Sprite, SpriteFrame, resources, Button, Collider2D, Material } from 'cc';
|
|
|
import { ConfigManager, WeaponConfig } from '../Core/ConfigManager';
|
|
|
import { SaveDataManager } from '../LevelSystem/SaveDataManager';
|
|
|
import { LevelSessionManager } from '../Core/LevelSessionManager';
|
|
|
@@ -1365,6 +1365,8 @@ export class BlockManager extends Component {
|
|
|
console.log(`[BlockManager] 设置方块稀有度颜色: ${rarity}`, color);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 加载武器图标
|
|
|
private loadWeaponIcon(block: Node, weaponConfig: WeaponConfig) {
|
|
|
// 根据预制体结构:WeaponBlock -> B1 -> Weapon
|
|
|
@@ -1426,12 +1428,88 @@ export class BlockManager extends Component {
|
|
|
spriteFrame && spriteFrame.isValid) {
|
|
|
weaponSprite.spriteFrame = spriteFrame;
|
|
|
|
|
|
- // 根据武器类型和方块形状旋转图片
|
|
|
+ // 应用武器图标的位置偏移和旋转
|
|
|
this.rotateWeaponIconByShape(weaponNode, blockShapeId, weaponConfig.id);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // 武器类型和方块形状组合的位置偏移配置(相对于方块中心的偏移量)
|
|
|
+ private readonly WEAPON_SHAPE_POSITION_OFFSETS: { [weaponId: string]: { [shapeId: string]: { x: number, y: number } } } = {
|
|
|
+ 'pea_shooter': {
|
|
|
+ 'I': { x: 3, y: -3 }, // 毛豆射手竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 5 }, // 毛豆射手横条形状,居中
|
|
|
+ 'L': { x: 1, y: -10 }, // 毛豆射手L型,轻微向左下偏移
|
|
|
+ 'S': { x: 5, y: -1 }, // 毛豆射手S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 3, y: -1 } // 毛豆射手倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'sharp_carrot': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 尖胡萝卜竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 尖胡萝卜横条形状,居中
|
|
|
+ 'L': { x: -1, y: -5 }, // 尖胡萝卜L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 尖胡萝卜S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -1 } // 尖胡萝卜倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'saw_grass': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 锯齿草竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 锯齿草横条形状,居中
|
|
|
+ 'L': { x: -1, y: -1 }, // 锯齿草L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 锯齿草S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -5 } // 锯齿草倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'watermelon_bomb': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 西瓜炸弹竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 西瓜炸弹横条形状,居中
|
|
|
+ 'L': { x: -1, y: -1 }, // 西瓜炸弹L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 西瓜炸弹S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -7 } // 西瓜炸弹倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'boomerang_plant': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 回旋镖植物竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 回旋镖植物横条形状,居中
|
|
|
+ 'L': { x: -1, y: -8 }, // 回旋镖植物L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 回旋镖植物S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: -10, y: -13 } // 回旋镖植物倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'hot_pepper': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 辣椒竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 辣椒横条形状,居中
|
|
|
+ 'L': { x: -1, y: -1 }, // 辣椒L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 辣椒S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -1 } // 辣椒倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'cactus_shotgun': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 仙人掌霰弹枪竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 仙人掌霰弹枪横条形状,居中
|
|
|
+ 'L': { x: -1, y: -1 }, // 仙人掌霰弹枪L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 仙人掌霰弹枪S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -1 } // 仙人掌霰弹枪倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'okra_missile': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 秋葵导弹竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 秋葵导弹横条形状,居中
|
|
|
+ 'L': { x: -1, y: -1 }, // 秋葵导弹L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 秋葵导弹S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -1 } // 秋葵导弹倒T型,轻微向下偏移
|
|
|
+ },
|
|
|
+ 'mace_club': {
|
|
|
+ 'I': { x: 0, y: -1 }, // 狼牙棒竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 狼牙棒横条形状,居中
|
|
|
+ 'L': { x: -1, y: -1 }, // 狼牙棒L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // 狼牙棒S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -1 } // 狼牙棒倒T型,轻微向下偏移
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 默认位置偏移配置(当武器类型未配置时使用)
|
|
|
+ private readonly DEFAULT_SHAPE_POSITION_OFFSETS: { [key: string]: { x: number, y: number } } = {
|
|
|
+ 'I': { x: 0, y: -1 }, // 竖条形状,轻微向下偏移
|
|
|
+ 'H-I': { x: 0, y: 0 }, // 横I型,居中
|
|
|
+ 'L': { x: -1, y: -1 }, // L型,轻微向左下偏移
|
|
|
+ 'S': { x: 1, y: -1 }, // S型,轻微向右下偏移
|
|
|
+ 'D-T': { x: 0, y: -1 } // 倒T型,轻微向下偏移
|
|
|
+ };
|
|
|
+
|
|
|
// 武器类型和方块形状组合的旋转角度配置
|
|
|
private readonly WEAPON_SHAPE_ROTATION_ANGLES: { [weaponId: string]: { [shapeId: string]: number } } = {
|
|
|
'pea_shooter': {
|
|
|
@@ -1443,7 +1521,7 @@ export class BlockManager extends Component {
|
|
|
},
|
|
|
'sharp_carrot': {
|
|
|
'I': 0, // 尖胡萝卜竖条形状
|
|
|
- 'H-I': 90, // 尖胡萝卜横条形状,旋转适配水平方向
|
|
|
+ 'H-I': 0, // 尖胡萝卜横条形状,旋转适配水平方向
|
|
|
'L': -15, // 尖胡萝卜L型,轻微调整
|
|
|
'S': 15, // 尖胡萝卜S型,轻微调整
|
|
|
'D-T': 0 // 尖胡萝卜倒T型
|
|
|
@@ -1466,8 +1544,8 @@ export class BlockManager extends Component {
|
|
|
'I': 0, // 回旋镖植物竖条形状
|
|
|
'H-I': 90, // 回旋镖植物横条形状,旋转适配飞行方向
|
|
|
'L': -30, // 回旋镖植物L型
|
|
|
- 'S': 45, // 回旋镖植物S型,适配回旋轨迹
|
|
|
- 'D-T': 0 // 回旋镖植物倒T型
|
|
|
+ 'S': -10, // 回旋镖植物S型,适配回旋轨迹
|
|
|
+ 'D-T': -80 // 回旋镖植物倒T型
|
|
|
},
|
|
|
'hot_pepper': {
|
|
|
'I': 0, // 辣椒竖条形状
|
|
|
@@ -1508,24 +1586,31 @@ export class BlockManager extends Component {
|
|
|
'D-T': 0 // 倒T型,保持原始方向
|
|
|
};
|
|
|
|
|
|
- // 根据武器类型和方块形状旋转武器图标
|
|
|
+ // 根据武器类型和方块形状调整武器图标位置和旋转
|
|
|
private rotateWeaponIconByShape(weaponNode: Node, shapeId: string | null, weaponId?: string) {
|
|
|
if (!weaponNode || !shapeId) return;
|
|
|
|
|
|
let rotationAngle = 0;
|
|
|
+ let positionOffset = { x: 0, y: 0 };
|
|
|
|
|
|
- // 如果提供了武器ID,尝试获取特定武器的旋转角度
|
|
|
+ // 如果提供了武器ID,尝试获取特定武器的配置
|
|
|
if (weaponId && this.WEAPON_SHAPE_ROTATION_ANGLES[weaponId]) {
|
|
|
rotationAngle = this.WEAPON_SHAPE_ROTATION_ANGLES[weaponId][shapeId] || 0;
|
|
|
- console.log(`为武器 ${weaponId} 形状 ${shapeId} 设置特定旋转角度: ${rotationAngle}度`);
|
|
|
+ positionOffset = this.WEAPON_SHAPE_POSITION_OFFSETS[weaponId]?.[shapeId] || { x: 0, y: 0 };
|
|
|
+ console.log(`为武器 ${weaponId} 形状 ${shapeId} 设置特定配置: 旋转${rotationAngle}度, 偏移(${positionOffset.x}, ${positionOffset.y})`);
|
|
|
} else {
|
|
|
- // 使用默认旋转角度配置
|
|
|
+ // 使用默认配置
|
|
|
rotationAngle = this.DEFAULT_SHAPE_ROTATION_ANGLES[shapeId] || 0;
|
|
|
- console.log(`为形状 ${shapeId} 设置默认旋转角度: ${rotationAngle}度`);
|
|
|
+ positionOffset = this.DEFAULT_SHAPE_POSITION_OFFSETS[shapeId] || { x: 0, y: 0 };
|
|
|
+ console.log(`为形状 ${shapeId} 设置默认配置: 旋转${rotationAngle}度, 偏移(${positionOffset.x}, ${positionOffset.y})`);
|
|
|
}
|
|
|
|
|
|
// 应用旋转
|
|
|
weaponNode.setRotationFromEuler(0, 0, rotationAngle);
|
|
|
+
|
|
|
+ // 应用位置偏移
|
|
|
+ const currentPos = weaponNode.position;
|
|
|
+ weaponNode.setPosition(currentPos.x + positionOffset.x, currentPos.y + positionOffset.y, currentPos.z);
|
|
|
}
|
|
|
|
|
|
// 设置特定武器和形状的旋转角度
|
|
|
@@ -1543,6 +1628,21 @@ export class BlockManager extends Component {
|
|
|
console.log(`已更新默认形状 ${shapeId} 的旋转角度为: ${angle}度`);
|
|
|
}
|
|
|
|
|
|
+ // 设置特定武器和形状的位置偏移
|
|
|
+ public setWeaponShapePositionOffset(weaponId: string, shapeId: string, offset: { x: number, y: number }) {
|
|
|
+ if (!this.WEAPON_SHAPE_POSITION_OFFSETS[weaponId]) {
|
|
|
+ this.WEAPON_SHAPE_POSITION_OFFSETS[weaponId] = {};
|
|
|
+ }
|
|
|
+ this.WEAPON_SHAPE_POSITION_OFFSETS[weaponId][shapeId] = offset;
|
|
|
+ console.log(`已更新武器 ${weaponId} 形状 ${shapeId} 的位置偏移为: (${offset.x}, ${offset.y})`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置默认形状的位置偏移
|
|
|
+ public setDefaultShapePositionOffset(shapeId: string, offset: { x: number, y: number }) {
|
|
|
+ this.DEFAULT_SHAPE_POSITION_OFFSETS[shapeId] = offset;
|
|
|
+ console.log(`已更新默认形状 ${shapeId} 的位置偏移为: (${offset.x}, ${offset.y})`);
|
|
|
+ }
|
|
|
+
|
|
|
// 获取特定武器和形状的旋转角度
|
|
|
public getWeaponShapeRotationAngle(weaponId: string, shapeId: string): number {
|
|
|
if (this.WEAPON_SHAPE_ROTATION_ANGLES[weaponId]) {
|
|
|
@@ -1556,7 +1656,34 @@ export class BlockManager extends Component {
|
|
|
return this.DEFAULT_SHAPE_ROTATION_ANGLES[shapeId] || 0;
|
|
|
}
|
|
|
|
|
|
- // 重新应用所有已放置方块的武器图标旋转
|
|
|
+ // 获取特定武器和形状的位置偏移
|
|
|
+ public getWeaponShapePositionOffset(weaponId: string, shapeId: string): { x: number, y: number } {
|
|
|
+ if (this.WEAPON_SHAPE_POSITION_OFFSETS[weaponId]) {
|
|
|
+ return this.WEAPON_SHAPE_POSITION_OFFSETS[weaponId][shapeId] || { x: 0, y: 0 };
|
|
|
+ }
|
|
|
+ return { x: 0, y: 0 };
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取默认形状的位置偏移
|
|
|
+ public getDefaultShapePositionOffset(shapeId: string): { x: number, y: number } {
|
|
|
+ return this.DEFAULT_SHAPE_POSITION_OFFSETS[shapeId] || { x: 0, y: 0 };
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同时设置特定武器和形状的位置偏移和旋转角度
|
|
|
+ public setWeaponShapeTransform(weaponId: string, shapeId: string, offset: { x: number, y: number }, angle: number) {
|
|
|
+ this.setWeaponShapePositionOffset(weaponId, shapeId, offset);
|
|
|
+ this.setWeaponShapeRotationAngle(weaponId, shapeId, angle);
|
|
|
+ console.log(`已更新武器 ${weaponId} 形状 ${shapeId} 的完整变换: 偏移(${offset.x}, ${offset.y}), 旋转${angle}度`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同时设置默认形状的位置偏移和旋转角度
|
|
|
+ public setDefaultShapeTransform(shapeId: string, offset: { x: number, y: number }, angle: number) {
|
|
|
+ this.setDefaultShapePositionOffset(shapeId, offset);
|
|
|
+ this.setDefaultShapeRotationAngle(shapeId, angle);
|
|
|
+ console.log(`已更新默认形状 ${shapeId} 的完整变换: 偏移(${offset.x}, ${offset.y}), 旋转${angle}度`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重新应用所有已放置方块的武器图标位置和旋转
|
|
|
public refreshAllWeaponIconRotations() {
|
|
|
// 遍历所有已放置的方块
|
|
|
if (this.placedBlocksContainer) {
|