| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import { _decorator, Component, Node, Prefab, Canvas, UITransform, Vec3, director } from 'cc';
- import { ConfigManager } from '../Core/ConfigManager';
- const { ccclass, property } = _decorator;
- /**
- * 武器方块测试场景
- * 用于测试武器配置系统的完整示例
- */
- @ccclass('WeaponBlockTestScene')
- export class WeaponBlockTestScene extends Component {
- start() {
- console.log('=== 武器方块测试场景启动 ===');
- this.setupTestScene();
- }
- private async setupTestScene() {
- // 等待配置管理器加载完成
- const configManager = ConfigManager.getInstance();
-
- // 等待配置加载
- await new Promise<void>((resolve) => {
- const checkConfig = () => {
- if (configManager.isConfigLoaded()) {
- resolve();
- } else {
- this.scheduleOnce(checkConfig, 0.1);
- }
- };
- checkConfig();
- });
- console.log('✅ 配置管理器已加载');
-
- // 显示可用武器信息
- this.displayWeaponInfo();
-
- // 创建测试说明
- this.createTestInstructions();
- }
- private displayWeaponInfo() {
- const configManager = ConfigManager.getInstance();
- const allWeapons = configManager.getAllWeapons();
-
- console.log('📋 可用武器列表:');
- allWeapons.forEach(weapon => {
- console.log(` - ${weapon.name} (${weapon.id}) - ${weapon.rarity}`);
- });
- // 按稀有度统计
- const rarityCount = {
- common: configManager.getWeaponsByRarity('common').length,
- uncommon: configManager.getWeaponsByRarity('uncommon').length,
- rare: configManager.getWeaponsByRarity('rare').length,
- epic: configManager.getWeaponsByRarity('epic').length
- };
- console.log('📊 武器稀有度统计:');
- console.log(` 普通: ${rarityCount.common}个`);
- console.log(` 稀有: ${rarityCount.uncommon}个`);
- console.log(` 史诗: ${rarityCount.rare}个`);
- console.log(` 传说: ${rarityCount.epic}个`);
- }
- private createTestInstructions() {
- console.log('🎯 武器方块测试说明:');
- console.log('1. WeaponBlockExample 会自动创建5个不同稀有度的武器方块');
- console.log('2. 方块会显示对应的植物图标和稀有度颜色');
- console.log('3. 点击方块可以查看武器详细信息');
- console.log('4. 检查控制台输出查看加载状态');
- }
- }
- /**
- * 武器方块设置指南
- */
- export class WeaponBlockSetupGuide {
-
- /**
- * 在Cocos Creator编辑器中的设置步骤:
- *
- * 1. 创建场景节点结构:
- * Canvas
- * ├── ConfigManager (挂载 ConfigManager.ts)
- * ├── TestScene (挂载 WeaponBlockTestScene.ts)
- * └── WeaponTest
- * ├── WeaponBlockExample (挂载 WeaponBlockExample.ts)
- * └── BlockContainer (空节点,用于容纳生成的武器方块)
- *
- * 2. 创建武器方块预制体:
- * - 创建一个Node,命名为 WeaponBlock
- * - 添加Sprite组件 (用于显示武器图标)
- * - 添加UITransform组件,设置合适的尺寸 (如 100x100)
- * - 可选: 添加Button组件用于点击交互
- * - 保存为预制体
- *
- * 3. 配置WeaponBlockExample组件:
- * - Block Prefab: 拖入刚创建的武器方块预制体
- * - Block Container: 拖入BlockContainer节点
- *
- * 4. 运行测试:
- * - 播放场景
- * - 查看控制台输出
- * - 观察生成的武器方块
- */
- }
|