Browse Source

json统一加载

181404010226 2 months ago
parent
commit
47ca69f721

+ 11 - 113
assets/Scenes/GameLevel.scene

@@ -57,7 +57,7 @@
     },
     "autoReleaseAssets": false,
     "_globals": {
-      "__id__": 1340
+      "__id__": 1334
     },
     "_id": "29694223-a59c-44b3-acb0-80ab92d103f5"
   },
@@ -1191,10 +1191,6 @@
     "heartLabelNode": {
       "__id__": 28
     },
-    "wallConfigAsset": {
-      "__uuid__": "71dc77dd-c50c-494a-b13b-147806cd8357",
-      "__expectedType__": "cc.JsonAsset"
-    },
     "_id": "d2nxVfNqhJvJR+mYpynwO5"
   },
   {
@@ -2119,10 +2115,6 @@
     "heartLabelNode": {
       "__id__": 28
     },
-    "wallConfigAsset": {
-      "__uuid__": "71dc77dd-c50c-494a-b13b-147806cd8357",
-      "__expectedType__": "cc.JsonAsset"
-    },
     "_id": "d1AYer++BKAYWznVt2BYDC"
   },
   {
@@ -12993,10 +12985,6 @@
     "placedBlocksContainer": {
       "__id__": 255
     },
-    "ballControllerConfig": {
-      "__uuid__": "6251555c-8fac-4a81-a760-6ec36a78de4a",
-      "__expectedType__": "cc.JsonAsset"
-    },
     "bulletPrefab": {
       "__uuid__": "54638943-4461-43b1-b351-a0380e1f30ce",
       "__expectedType__": "cc.Prefab"
@@ -20978,10 +20966,6 @@
     "upgradeNextHpLabel": {
       "__id__": 633
     },
-    "wallConfigAsset": {
-      "__uuid__": "71dc77dd-c50c-494a-b13b-147806cd8357",
-      "__expectedType__": "cc.JsonAsset"
-    },
     "battleBtn": {
       "__id__": 647
     },
@@ -31016,7 +31000,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 11.744140624999998,
+      "x": 11.744140625000002,
       "y": 0,
       "z": 0
     },
@@ -31143,7 +31127,7 @@
     "_right": 0,
     "_top": 4.062999999999998,
     "_bottom": 0.37195384615384625,
-    "_horizontalCenter": 0.06382685122282608,
+    "_horizontalCenter": 0.0638268512228261,
     "_verticalCenter": 0,
     "_isAbsLeft": true,
     "_isAbsRight": true,
@@ -33626,10 +33610,6 @@
     "diamondAmountLabel": {
       "__id__": 983
     },
-    "shopConfigAsset": {
-      "__uuid__": "5de09f6f-2384-4f2e-b209-d7445ecf6a42",
-      "__expectedType__": "cc.JsonAsset"
-    },
     "billSpriteNode": {
       "__id__": 935
     },
@@ -35814,10 +35794,6 @@
     "cameraNode": {
       "__id__": 3
     },
-    "weaponsConfig": {
-      "__uuid__": "b0dff099-9502-41f9-8678-6126d42ddd68",
-      "__expectedType__": "cc.JsonAsset"
-    },
     "addBallPriceNode": {
       "__id__": 1064
     },
@@ -45228,15 +45204,6 @@
       },
       {
         "__id__": 1331
-      },
-      {
-        "__id__": 1334
-      },
-      {
-        "__id__": 1336
-      },
-      {
-        "__id__": 1338
       }
     ],
     "nestedPrefabInstanceRoots": [
@@ -45521,100 +45488,31 @@
       "acB1uRv+ZI4aBLZfk/IrYy"
     ]
   },
-  {
-    "__type__": "cc.TargetOverrideInfo",
-    "source": {
-      "__id__": 438
-    },
-    "sourceInfo": null,
-    "propertyPath": [
-      "skillButtons",
-      "0"
-    ],
-    "target": {
-      "__id__": 289
-    },
-    "targetInfo": {
-      "__id__": 1335
-    }
-  },
-  {
-    "__type__": "cc.TargetInfo",
-    "localID": [
-      "9bckw8VnJAVJfh+LK/5rLp"
-    ]
-  },
-  {
-    "__type__": "cc.TargetOverrideInfo",
-    "source": {
-      "__id__": 438
-    },
-    "sourceInfo": null,
-    "propertyPath": [
-      "skillButtons",
-      "1"
-    ],
-    "target": {
-      "__id__": 337
-    },
-    "targetInfo": {
-      "__id__": 1337
-    }
-  },
-  {
-    "__type__": "cc.TargetInfo",
-    "localID": [
-      "9bckw8VnJAVJfh+LK/5rLp"
-    ]
-  },
-  {
-    "__type__": "cc.TargetOverrideInfo",
-    "source": {
-      "__id__": 438
-    },
-    "sourceInfo": null,
-    "propertyPath": [
-      "skillButtons",
-      "2"
-    ],
-    "target": {
-      "__id__": 385
-    },
-    "targetInfo": {
-      "__id__": 1339
-    }
-  },
-  {
-    "__type__": "cc.TargetInfo",
-    "localID": [
-      "9bckw8VnJAVJfh+LK/5rLp"
-    ]
-  },
   {
     "__type__": "cc.SceneGlobals",
     "ambient": {
-      "__id__": 1341
+      "__id__": 1335
     },
     "shadows": {
-      "__id__": 1342
+      "__id__": 1336
     },
     "_skybox": {
-      "__id__": 1343
+      "__id__": 1337
     },
     "fog": {
-      "__id__": 1344
+      "__id__": 1338
     },
     "octree": {
-      "__id__": 1345
+      "__id__": 1339
     },
     "skin": {
-      "__id__": 1346
+      "__id__": 1340
     },
     "lightProbeInfo": {
-      "__id__": 1347
+      "__id__": 1341
     },
     "postSettings": {
-      "__id__": 1348
+      "__id__": 1342
     },
     "bakedWithStationaryMainLight": false,
     "bakedWithHighpLightmap": false

+ 4 - 12
assets/scripts/CombatSystem/BallController.ts

@@ -8,7 +8,7 @@ import { BallControllerConfig } from '../Core/ConfigManager';
 import { WeaponInfo } from './BlockSelection/WeaponInfo';
 import { BlockInfo } from './BlockSelection/BlockInfo';
 import { BallAni } from '../Animations/BallAni';
-import { BundleLoader } from '../Core/BundleLoader';
+import { JsonConfigLoader } from '../Core/JsonConfigLoader';
 const { ccclass, property } = _decorator;
 
 @ccclass('BallController')
@@ -199,17 +199,9 @@ export class BallController extends Component {
     // 加载配置
     private async loadConfig(): Promise<void> {
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const ballControllerData = await bundleLoader.loadDataJson('ballController');
-            
-            if (ballControllerData && ballControllerData.json) {
-                this.config = ballControllerData.json as BallControllerConfig;
-                this.applyConfig();
-                console.log('[BallController] ✅ 配置文件通过BundleLoader加载成功:', this.config);
-            } else {
-                console.warn('[BallController] ⚠️ 配置文件加载失败,使用默认值');
-                this.useDefaultConfig();
-            }
+            this.config = await JsonConfigLoader.getInstance().loadConfig('ballController') as BallControllerConfig;
+            this.applyConfig();
+            console.log('[BallController] ✅ 配置文件通过JsonConfigLoader加载成功:', this.config);
         } catch (error) {
             console.error('[BallController] 加载配置文件失败:', error);
             this.useDefaultConfig();

+ 3 - 7
assets/scripts/CombatSystem/BlockSelection/GameBlockSelection.ts

@@ -8,7 +8,7 @@ import { WeaponInfo } from './WeaponInfo';
 import { SkillManager } from '../SkillSelection/SkillManager';
 import { Audio } from '../../AudioManager/AudioManager';
 import { AdManager } from '../../Ads/AdManager';
-import { BundleLoader } from '../../Core/BundleLoader';
+import { JsonConfigLoader } from '../../Core/JsonConfigLoader';
 
 import EventBus, { GameEvents } from '../../Core/EventBus';
 const { ccclass, property } = _decorator;
@@ -277,9 +277,7 @@ export class GameBlockSelection extends Component {
     private async initializeComponent() {
         // 异步加载小球价格配置
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const ballPriceConfigAsset = await bundleLoader.loadDataJson('ball_price_config');
-            this.ballPriceConfigData = ballPriceConfigAsset.json;
+            this.ballPriceConfigData = await JsonConfigLoader.getInstance().loadConfig('ballPrice');
             console.log('[GameBlockSelection] 小球价格配置加载成功:', this.ballPriceConfigData);
         } catch (error) {
             console.warn('[GameBlockSelection] 小球价格配置加载失败:', error);
@@ -288,9 +286,7 @@ export class GameBlockSelection extends Component {
         
         // 异步加载武器配置
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const weaponsConfigAsset = await bundleLoader.loadDataJson('weapons');
-            this.weaponsConfigData = weaponsConfigAsset.json;
+            this.weaponsConfigData = await JsonConfigLoader.getInstance().loadConfig('weapons');
             console.log('[GameBlockSelection] 武器配置加载成功:', this.weaponsConfigData);
         } catch (error) {
             console.warn('[GameBlockSelection] 武器配置加载失败:', error);

+ 3 - 8
assets/scripts/CombatSystem/EnemyInstance.ts

@@ -1,5 +1,5 @@
 import { _decorator, Component, Node, ProgressBar, Label, Vec3, find, UITransform, Collider2D, Contact2DType, IPhysics2DContact, instantiate, resources, Prefab, JsonAsset, RigidBody2D, ERigidBody2DType, BoxCollider2D, CircleCollider2D } from 'cc';
-import { BundleLoader } from '../Core/BundleLoader';
+import { JsonConfigLoader } from '../Core/JsonConfigLoader';
 import { sp } from 'cc';
 import { DamageNumberAni } from '../Animations/DamageNumberAni';
 import { HPBarAnimation } from '../Animations/HPBarAnimation';
@@ -101,15 +101,10 @@ export class EnemyInstance extends Component {
         if (EnemyInstance.enemyDatabase) return;
         
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const enemyData = await bundleLoader.loadDataJson('enemies');
-            
-            if (!enemyData) {
+            EnemyInstance.enemyDatabase = await JsonConfigLoader.getInstance().loadConfig('enemies');
+            if (!EnemyInstance.enemyDatabase) {
                 throw new Error('敌人配置文件内容为空');
             }
-            
-            // JsonAsset对象,需要访问.json属性获取实际数据
-            EnemyInstance.enemyDatabase = enemyData.json;
         } catch (error) {
             console.error('[EnemyInstance] 加载敌人配置失败:', error);
             throw error;

+ 10 - 16
assets/scripts/CombatSystem/Wall.ts

@@ -1,7 +1,7 @@
 import { _decorator, Component, Node, Label, find, JsonAsset } from 'cc';
 import { SaveDataManager } from '../LevelSystem/SaveDataManager';
 import EventBus, { GameEvents } from '../Core/EventBus';
-import { BundleLoader } from '../Core/BundleLoader';
+import { JsonConfigLoader } from '../Core/JsonConfigLoader';
 
 import { SkillManager } from './SkillSelection/SkillManager';
 const { ccclass, property } = _decorator;
@@ -43,23 +43,17 @@ export class Wall extends Component {
      */
     private async loadWallConfig(): Promise<void> {
         try {
-            const wallData = await BundleLoader.getInstance().loadDataJson('wall');
-            if (wallData) {
-                this.wallConfig = wallData;
-                if (this.wallConfig && this.wallConfig.wallConfig && this.wallConfig.wallConfig.healthByLevel) {
-                    // 转换字符串键为数字键
-                    const healthByLevel = this.wallConfig.wallConfig.healthByLevel;
-                    this.wallHpMap = {};
-                    for (const level in healthByLevel) {
-                        this.wallHpMap[parseInt(level)] = healthByLevel[level];
-                    }
-                    console.log('[Wall] 墙体配置加载成功:', this.wallHpMap);
-                } else {
-                    console.warn('[Wall] 配置文件格式错误,使用默认配置');
-                    this.useDefaultConfig();
+            this.wallConfig = await JsonConfigLoader.getInstance().loadConfig('wall');
+            if (this.wallConfig && this.wallConfig.wallConfig && this.wallConfig.wallConfig.healthByLevel) {
+                // 转换字符串键为数字键
+                const healthByLevel = this.wallConfig.wallConfig.healthByLevel;
+                this.wallHpMap = {};
+                for (const level in healthByLevel) {
+                    this.wallHpMap[parseInt(level)] = healthByLevel[level];
                 }
+                console.log('[Wall] 墙体配置加载成功:', this.wallHpMap);
             } else {
-                console.warn('[Wall] wall.json加载失败,使用默认配置');
+                console.warn('[Wall] 配置文件格式错误,使用默认配置');
                 this.useDefaultConfig();
             }
         } catch (error) {

+ 4 - 3
assets/scripts/CombatSystem/WeaponBullet.ts

@@ -1,4 +1,5 @@
 import { _decorator, Component, Node, Vec2, Vec3, RigidBody2D, Collider2D, Contact2DType, IPhysics2DContact, find, Prefab, instantiate, UITransform, resources, sp, JsonAsset, Sprite, SpriteFrame, math } from 'cc';
+import { JsonConfigLoader } from '../Core/JsonConfigLoader';
 import { BundleLoader } from '../Core/BundleLoader';
 import { BulletCount, BulletSpawnInfo } from './BulletEffects/BulletCount';
 import { BulletTrajectory } from './BulletEffects/BulletTrajectory';
@@ -74,14 +75,14 @@ export class WeaponBullet extends Component {
         }
         
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const weaponData = await bundleLoader.loadDataJson('weapons');
+            const jsonConfigLoader = JsonConfigLoader.getInstance();
+            const weaponData = await jsonConfigLoader.loadConfig('weapons');
             
             if (!weaponData) {
                 throw new Error('武器配置文件内容为空');
             }
             
-            WeaponBullet.weaponsData = weaponData.json;
+            WeaponBullet.weaponsData = weaponData;
         } catch (error) {
             console.error('[WeaponBullet] 武器配置文件加载失败:', error);
             throw error;

+ 3 - 19
assets/scripts/Core/ConfigManager.ts

@@ -1,6 +1,6 @@
 import { _decorator, resources, JsonAsset } from 'cc';
 import { BaseSingleton } from './BaseSingleton';
-import { BundleLoader } from './BundleLoader';
+import { JsonConfigLoader } from './JsonConfigLoader';
 const { ccclass, property } = _decorator;
 
 // 局内金币花费配置接口
@@ -300,15 +300,7 @@ export class ConfigManager extends BaseSingleton {
         console.log('[ConfigManager] 开始加载武器配置...');
         
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const weaponData = await bundleLoader.loadDataJson('weapons');
-            
-            if (!weaponData) {
-                throw new Error('武器配置文件内容为空');
-            }
-            
-            // JsonAsset对象,需要访问.json属性获取实际数据
-            this.weaponsConfig = weaponData.json;
+            this.weaponsConfig = await JsonConfigLoader.getInstance().loadConfig('weapons');
             
             // 验证配置完整性
             console.log('[ConfigManager] 验证武器配置完整性...');
@@ -338,15 +330,7 @@ export class ConfigManager extends BaseSingleton {
         console.log('[ConfigManager] 开始加载敌人配置...');
         
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const enemyData = await bundleLoader.loadDataJson('enemies');
-            
-            if (!enemyData) {
-                throw new Error('敌人配置文件内容为空');
-            }
-            
-            // JsonAsset对象,需要访问.json属性获取实际数据
-            this.enemiesConfig = enemyData.json;
+            this.enemiesConfig = await JsonConfigLoader.getInstance().loadConfig('enemies');
             console.log('[ConfigManager] ✅ 敌人配置加载成功');
         } catch (error) {
             console.error('[ConfigManager] 敌人配置文件加载失败:', error);

+ 136 - 0
assets/scripts/Core/JsonConfigLoader.ts

@@ -0,0 +1,136 @@
+import { BundleLoader } from './BundleLoader';
+
+/**
+ * 统一的JSON配置加载器
+ * 提供类型安全的JSON配置加载功能
+ */
+export class JsonConfigLoader {
+    private static instance: JsonConfigLoader;
+    private configCache: Map<string, any> = new Map();
+    
+    // JSON文件路径映射
+    private static readonly CONFIG_PATHS = {
+        shop: 'shop',
+        weapons: 'weapons',
+        wall: 'wall',
+        skills: 'skill',
+        skillConfig: 'skill_config',
+        enemies: 'enemies',
+        ballPrice: 'ball_price_config',
+        ballController: 'ballController'
+    } as const;
+    
+    public static getInstance(): JsonConfigLoader {
+        if (!JsonConfigLoader.instance) {
+            JsonConfigLoader.instance = new JsonConfigLoader();
+        }
+        return JsonConfigLoader.instance;
+    }
+    
+    /**
+     * 加载JSON配置文件
+     * @param configType 配置类型
+     * @param useCache 是否使用缓存
+     * @returns 配置数据
+     */
+    public async loadConfig<T = any>(
+        configType: keyof typeof JsonConfigLoader.CONFIG_PATHS,
+        useCache: boolean = true
+    ): Promise<T | null> {
+        try {
+            // 检查缓存
+            if (useCache && this.configCache.has(configType)) {
+                return this.configCache.get(configType) as T;
+            }
+            
+            const configPath = JsonConfigLoader.CONFIG_PATHS[configType];
+            const bundleLoader = BundleLoader.getInstance();
+            const asset = await bundleLoader.loadDataJson(configPath);
+            
+            if (asset && asset.json) {
+                const config = asset.json as T;
+                
+                // 缓存配置
+                if (useCache) {
+                    this.configCache.set(configType, config);
+                }
+                
+                console.log(`[JsonConfigLoader] ${configType}.json 加载成功`);
+                return config;
+            } else {
+                throw new Error(`配置文件 ${configType}.json 数据为空`);
+            }
+        } catch (error) {
+            console.error(`[JsonConfigLoader] ${configType}.json 加载失败:`, error);
+            return null;
+        }
+    }
+    
+    /**
+     * 预加载多个配置文件
+     * @param configTypes 配置类型数组
+     */
+    public async preloadConfigs(
+        configTypes: (keyof typeof JsonConfigLoader.CONFIG_PATHS)[]
+    ): Promise<void> {
+        const loadPromises = configTypes.map(type => this.loadConfig(type));
+        await Promise.all(loadPromises);
+    }
+    
+    /**
+     * 清除缓存
+     * @param configType 可选,指定清除某个配置的缓存
+     */
+    public clearCache(configType?: keyof typeof JsonConfigLoader.CONFIG_PATHS): void {
+        if (configType) {
+            this.configCache.delete(configType);
+        } else {
+            this.configCache.clear();
+        }
+    }
+    
+    /**
+     * 重新加载配置
+     * @param configType 配置类型
+     */
+    public async reloadConfig<T = any>(
+        configType: keyof typeof JsonConfigLoader.CONFIG_PATHS
+    ): Promise<T | null> {
+        this.clearCache(configType);
+        return this.loadConfig<T>(configType, true);
+    }
+    
+    /**
+     * 获取已缓存的配置
+     * @param configType 配置类型
+     * @returns 缓存的配置数据,如果不存在则返回null
+     */
+    public getCachedConfig<T = any>(
+        configType: keyof typeof JsonConfigLoader.CONFIG_PATHS
+    ): T | null {
+        return this.configCache.get(configType) as T || null;
+    }
+    
+    /**
+     * 检查配置是否已缓存
+     * @param configType 配置类型
+     * @returns 是否已缓存
+     */
+    public isCached(configType: keyof typeof JsonConfigLoader.CONFIG_PATHS): boolean {
+        return this.configCache.has(configType);
+    }
+    
+    /**
+     * 获取所有可用的配置类型
+     * @returns 配置类型数组
+     */
+    public getAvailableConfigTypes(): (keyof typeof JsonConfigLoader.CONFIG_PATHS)[] {
+        return Object.keys(JsonConfigLoader.CONFIG_PATHS) as (keyof typeof JsonConfigLoader.CONFIG_PATHS)[];
+    }
+}
+
+// 导出类型定义
+export type ConfigType = keyof typeof JsonConfigLoader['CONFIG_PATHS'];
+
+// 导出单例实例的便捷方法
+export const jsonConfigLoader = JsonConfigLoader.getInstance();

+ 9 - 0
assets/scripts/Core/JsonConfigLoader.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "e31ed097-0000-4f01-91da-5e72281a122e",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 4 - 6
assets/scripts/Core/LevelSessionManager.ts

@@ -49,13 +49,11 @@ export class LevelSessionManager {
       const resourcePath = `levels/Level${levelId}`;
       console.log(`[LevelSessionManager] 尝试从data Bundle加载关卡配置: ${resourcePath}`);
       
-      const bundleLoader = BundleLoader.getInstance();
-      const asset = await bundleLoader.loadDataJson(resourcePath);
+      const levelConfig = await BundleLoader.getInstance().loadDataJson(resourcePath);
       
-      const levelConfig = asset.json;
-      if (levelConfig && typeof levelConfig.initialCoins === 'number') {
-        console.log(`[LevelSessionManager] 关卡${levelId}初始金币配置: ${levelConfig.initialCoins}`);
-        return levelConfig.initialCoins;
+      if (levelConfig && levelConfig.json && typeof levelConfig.json.initialCoins === 'number') {
+        console.log(`[LevelSessionManager] 关卡${levelId}初始金币配置: ${levelConfig.json.initialCoins}`);
+        return levelConfig.json.initialCoins;
       } else {
         console.warn(`[LevelSessionManager] 关卡${levelId}配置中未找到initialCoins字段,使用默认值45`);
         return 45; // 默认值

+ 4 - 4
assets/scripts/FourUI/ShopSystem/ShopController.ts

@@ -4,7 +4,7 @@ import EventBus, { GameEvents } from '../../Core/EventBus';
 import { TopBarController } from '../TopBarController';
 import { MoneyAni } from '../../Animations/MoneyAni';
 import { AdManager } from '../../Ads/AdManager';
-import { BundleLoader } from '../../Core/BundleLoader';
+import { JsonConfigLoader } from '../../Core/JsonConfigLoader';
 
 const { ccclass, property } = _decorator;
 
@@ -100,9 +100,9 @@ export class ShopController extends Component {
     
     private async loadShopConfig() {
         try {
-            const shopDataAsset = await BundleLoader.getInstance().loadDataJson('shop');
-            if (shopDataAsset && shopDataAsset.json) {
-                this.shopConfig = shopDataAsset.json as ShopConfig;
+            const shopData = await JsonConfigLoader.getInstance().loadConfig('shop');
+            if (shopData) {
+                this.shopConfig = shopData as ShopConfig;
                 console.log('[ShopController] shop.json加载成功:', this.shopConfig);
                 this.updateUI();
             } else {

+ 3 - 4
assets/scripts/FourUI/SkillSystem/SkillConfigManager.ts

@@ -1,5 +1,5 @@
 import { _decorator, Component, resources, JsonAsset } from 'cc';
-import { BundleLoader } from '../../Core/BundleLoader';
+import { JsonConfigLoader } from '../../Core/JsonConfigLoader';
 const { ccclass, property } = _decorator;
 
 /**
@@ -67,8 +67,7 @@ export class SkillConfigManager extends Component {
      */
     private async loadSkillConfig() {
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const skillConfigData = await bundleLoader.loadDataJson('skill_config');
+            const skillConfigData = await JsonConfigLoader.getInstance().loadConfig('skillConfig');
             
             if (!skillConfigData) {
                 console.error('技能配置文件内容为空');
@@ -76,7 +75,7 @@ export class SkillConfigManager extends Component {
                 return;
             }
 
-            this._skillConfig = skillConfigData.json as SkillConfig;
+            this._skillConfig = skillConfigData as SkillConfig;
             this._isLoaded = true;
             console.log('技能配置加载成功:', this._skillConfig);
         } catch (error) {

+ 2 - 9
assets/scripts/FourUI/UpgradeSystem/UpgradeAni.ts

@@ -1,5 +1,5 @@
 import { _decorator, Component, Node, Tween, tween, Vec3, Material, Sprite, resources, Label, JsonAsset } from 'cc';
-import { BundleLoader } from '../../Core/BundleLoader';
+import { JsonConfigLoader } from '../../Core/JsonConfigLoader';
 import { Audio } from '../../AudioManager/AudioManager';
 
 const { ccclass, property } = _decorator;
@@ -254,14 +254,7 @@ export class UpgradeAni extends Component {
      */
     public async loadWeaponsConfig(): Promise<void> {
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const weaponData = await bundleLoader.loadDataJson('weapons');
-            
-            if (!weaponData) {
-                throw new Error('武器配置文件内容为空');
-            }
-            
-            this.weaponsConfig = weaponData.json;
+            this.weaponsConfig = await JsonConfigLoader.getInstance().loadConfig('weapons');
             console.log('[UpgradeAni] 武器配置加载成功:', this.weaponsConfig);
         } catch (error) {
             console.error('[UpgradeAni] 加载武器配置失败:', error);

+ 4 - 7
assets/scripts/FourUI/UpgradeSystem/UpgradeController.ts

@@ -1,4 +1,5 @@
 import { _decorator, Component, Node, Button, Label, Sprite, SpriteFrame, Texture2D, resources, ScrollView, Layout, Prefab, instantiate, find, UIOpacity, Color } from 'cc';
+import { JsonConfigLoader } from '../../Core/JsonConfigLoader';
 import { BundleLoader } from '../../Core/BundleLoader';
 import { SaveDataManager, WeaponData } from '../../LevelSystem/SaveDataManager';
 import EventBus, { GameEvents } from '../../Core/EventBus';
@@ -148,10 +149,7 @@ export class UpgradeController extends Component {
      */
     private async loadWeaponsConfig() {
         try {
-            const bundleLoader = BundleLoader.getInstance();
-            const jsonAsset = await bundleLoader.loadDataJson('weapons');
-            
-            this.weaponsConfig = jsonAsset.json;
+            this.weaponsConfig = await JsonConfigLoader.getInstance().loadConfig('weapons');
             console.log('[UpgradeController] 武器配置加载成功:', this.weaponsConfig);
         } catch (error) {
             console.error('[UpgradeController] 加载武器配置失败:', error);
@@ -164,16 +162,15 @@ export class UpgradeController extends Component {
     private async loadLevelConfigs() {
         try {
             this.levelConfigs = [];
-            const bundleLoader = BundleLoader.getInstance();
             
             // 加载Level1到Level5的配置
             for (let i = 1; i <= 5; i++) {
                 try {
-                    const levelData = await bundleLoader.loadDataJson(`levels/Level${i}`);
+                    const levelData = await BundleLoader.getInstance().loadDataJson(`levels/Level${i}`);
                     
                     this.levelConfigs.push({
                         level: i,
-                        ...levelData.json
+                        ...levelData
                     });
                 } catch (error) {
                     console.warn(`加载Level${i}配置失败:`, error);