using SimpleJSON; using UnityEngine; using System.Collections.Generic; using ET; using GFG.HotUpdate.LubanConfig; using GFGGame; public static class CommonDataManager { public static cfg.Tables Tables; private static Dictionary _jsonCache = new Dictionary(); private static int _totalFilesToLoad; private static int _loadedFilesCount; public static void InitAllAsync(System.Action onComplete) { // 所有需要加载的配置表文件列表 var filesToLoad = LubanConfigFiles.GetFilesToLoad(); _totalFilesToLoad = filesToLoad.Count; _loadedFilesCount = 0; foreach (var file in filesToLoad) { LoadJsonFile(file, () => { _loadedFilesCount++; if (_loadedFilesCount == _totalFilesToLoad) { // 所有文件加载完成后初始化Tables Tables = new cfg.Tables(GetCachedJson); onComplete?.Invoke(); } }); } } public static void InitOneAsync(System.Action onComplete) { LoadJsonFile("gfgcfg_tblfunctionopencfg", () => { // 所有文件加载完成后初始化Tables Tables = new cfg.Tables(GetCachedJson); onComplete?.Invoke(); }); } private static void LoadJsonFile(string file, System.Action onLoaded) { var url = GetFileUrl(file); HttpTool.Instance.Get(url, (string data) => { if (string.IsNullOrEmpty(data)) { Debug.LogError($"Load luban json failed: {file}"); onLoaded?.Invoke(); return; } lock (_jsonCache) { _jsonCache[file] = JSON.Parse(data); } onLoaded?.Invoke(); }); } private static string GetFileUrl(string fileName) { // 根据你的实际URL规则构造文件URL return $"{LauncherConfig.launcherRootUrl}webglconfig/{fileName}.json?t={TimeHelper.ClientNow()}"; } private static JSONNode GetCachedJson(string file) { lock (_jsonCache) { if (_jsonCache.TryGetValue(file, out var json)) { return json; } //Debug.LogError($"Cached json not found: {file}"); return null; } } }