//创建bundle数据 BundleData CreateBdlData(string bundle_id) { BdlCfgInfo bdlCfg = AbsResConfig.GetBdlCfg(bundle_id); string url = bdlCfg.path; //修正路径(已经是小写) //url = url.ToLower(); AssetData data; if (m_url2data.TryGetValue(url, out data)) { return(data as BundleData); } BundleData bdlData = new BundleData(); bdlData.Init(url); if (bdlCfg.depends != null) { //有依赖项 BundleData dpData; for (int i = 0; i < bdlCfg.depends.Length; ++i) { dpData = CreateBdlData(bdlCfg.depends[i].id); bdlData.AddDepend(dpData); } } bdlData.active_time = DateUtil.TimeFromStart; m_url2data[url] = bdlData; return(bdlData); }
/// <summary> /// 读入配置文件 /// </summary> /// <param name="www_"></param> public static void ReadFromFile(WWW www_) { BdlNodeMap nodeMap = JsonUtility.FromJson <BdlNodeMap>(Encoding.UTF8.GetString(www_.bytes)); Dictionary <string, BdlNode> id2bdlNode = new Dictionary <string, BdlNode>(); BdlCfgInfo bdlCfg; foreach (BdlNode bdlNode in nodeMap.bdlNodes) { bdlCfg = new BdlCfgInfo(); bdlCfg.id = bdlNode.bundleId; m_id2bdl[bdlCfg.id] = bdlCfg; id2bdlNode[bdlNode.bundleId] = bdlNode; } foreach (var kvp in m_id2bdl) { bdlCfg = kvp.Value; BdlNode bdlNode = id2bdlNode[bdlCfg.id]; //确定加载路径 bdlCfg.path = bdlCfg.isPatch ? Path.Combine(AssetCacheBdl.PATCH_PATH, bdlNode.bundleName) : Path.Combine(AssetCacheBdl.BUNDLE_PATH, bdlNode.bundleName); //关联依赖 string[] dependIds = bdlNode.depends; if (dependIds.Length > 0) { bdlCfg.depends = new BdlCfgInfo[dependIds.Length]; for (int i = 0; i < dependIds.Length; ++i) { bdlCfg.depends[i] = m_id2bdl[dependIds[i]]; } } } ResCfgInfo resCfg; foreach (ResNode resNode in nodeMap.resNodes) { resCfg = new ResCfgInfo(); resCfg.path = resNode.path; resCfg.suffix = resNode.suffix; resCfg.bundle = m_id2bdl[resNode.bundleId]; } }