WeaponBlockTestScene.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { _decorator, Component, Node, Prefab, Canvas, UITransform, Vec3, director } from 'cc';
  2. import { ConfigManager } from '../Core/ConfigManager';
  3. const { ccclass, property } = _decorator;
  4. /**
  5. * 武器方块测试场景
  6. * 用于测试武器配置系统的完整示例
  7. */
  8. @ccclass('WeaponBlockTestScene')
  9. export class WeaponBlockTestScene extends Component {
  10. start() {
  11. console.log('=== 武器方块测试场景启动 ===');
  12. this.setupTestScene();
  13. }
  14. private async setupTestScene() {
  15. // 等待配置管理器加载完成
  16. const configManager = ConfigManager.getInstance();
  17. // 等待配置加载
  18. await new Promise<void>((resolve) => {
  19. const checkConfig = () => {
  20. if (configManager.isConfigLoaded()) {
  21. resolve();
  22. } else {
  23. this.scheduleOnce(checkConfig, 0.1);
  24. }
  25. };
  26. checkConfig();
  27. });
  28. console.log('✅ 配置管理器已加载');
  29. // 显示可用武器信息
  30. this.displayWeaponInfo();
  31. // 创建测试说明
  32. this.createTestInstructions();
  33. }
  34. private displayWeaponInfo() {
  35. const configManager = ConfigManager.getInstance();
  36. const allWeapons = configManager.getAllWeapons();
  37. console.log('📋 可用武器列表:');
  38. allWeapons.forEach(weapon => {
  39. console.log(` - ${weapon.name} (${weapon.id}) - ${weapon.rarity}`);
  40. });
  41. // 按稀有度统计
  42. const rarityCount = {
  43. common: configManager.getWeaponsByRarity('common').length,
  44. uncommon: configManager.getWeaponsByRarity('uncommon').length,
  45. rare: configManager.getWeaponsByRarity('rare').length,
  46. epic: configManager.getWeaponsByRarity('epic').length
  47. };
  48. console.log('📊 武器稀有度统计:');
  49. console.log(` 普通: ${rarityCount.common}个`);
  50. console.log(` 稀有: ${rarityCount.uncommon}个`);
  51. console.log(` 史诗: ${rarityCount.rare}个`);
  52. console.log(` 传说: ${rarityCount.epic}个`);
  53. }
  54. private createTestInstructions() {
  55. console.log('🎯 武器方块测试说明:');
  56. console.log('1. WeaponBlockExample 会自动创建5个不同稀有度的武器方块');
  57. console.log('2. 方块会显示对应的植物图标和稀有度颜色');
  58. console.log('3. 点击方块可以查看武器详细信息');
  59. console.log('4. 检查控制台输出查看加载状态');
  60. }
  61. }
  62. /**
  63. * 武器方块设置指南
  64. */
  65. export class WeaponBlockSetupGuide {
  66. /**
  67. * 在Cocos Creator编辑器中的设置步骤:
  68. *
  69. * 1. 创建场景节点结构:
  70. * Canvas
  71. * ├── ConfigManager (挂载 ConfigManager.ts)
  72. * ├── TestScene (挂载 WeaponBlockTestScene.ts)
  73. * └── WeaponTest
  74. * ├── WeaponBlockExample (挂载 WeaponBlockExample.ts)
  75. * └── BlockContainer (空节点,用于容纳生成的武器方块)
  76. *
  77. * 2. 创建武器方块预制体:
  78. * - 创建一个Node,命名为 WeaponBlock
  79. * - 添加Sprite组件 (用于显示武器图标)
  80. * - 添加UITransform组件,设置合适的尺寸 (如 100x100)
  81. * - 可选: 添加Button组件用于点击交互
  82. * - 保存为预制体
  83. *
  84. * 3. 配置WeaponBlockExample组件:
  85. * - Block Prefab: 拖入刚创建的武器方块预制体
  86. * - Block Container: 拖入BlockContainer节点
  87. *
  88. * 4. 运行测试:
  89. * - 播放场景
  90. * - 查看控制台输出
  91. * - 观察生成的武器方块
  92. */
  93. }