private AssetWrapper LoadRes(AssetBundleInfo info, System.Type assetType) { string assetPath = info.assetName; string bundleName = info.bundleName; if (info.dependencies != null) { foreach (string dep in info.dependencies) { if (m_bundleCache.ContainsKey(dep)) { m_bundleCache[dep].AddRefAsset(bundleName); continue; } else { if (string.IsNullOrEmpty(dep)) { Debugger.LogError("AB name " + bundleName + " 依赖名空!"); continue; } BundleWrapper loaded_bundle_bw = LoadBundle(dep); loaded_bundle_bw.AddRefAsset(bundleName); UnityEngine.Object temp = loaded_bundle_bw.GetBundle().mainAsset; if (temp != null) { Debugger.Log("dep_bundle mainAsset: " + temp.name); } } } } if (m_bundleCache.ContainsKey(bundleName)) { UnityEngine.Object obj = m_bundleCache[bundleName].GetBundle().LoadAsset(assetPath, assetType); AssetWrapper ret = new AssetWrapper(obj, assetPath, assetType, bundleName, IsSceneBundle(bundleName)); m_assetWrapperCache.Add(assetPath, ret); m_bundleCache[bundleName].AddRefAsset(assetPath); return(ret); } // load target bundle BundleWrapper target_bundle_bw = LoadBundle(bundleName); target_bundle_bw.AddRefAsset(assetPath); // load asset AssetWrapper ret_aw; if (IsSceneBundle(bundleName)) { ret_aw = new AssetWrapper(null, assetPath, assetType, bundleName, true); } else { string realPath = assetPath; //if (m_isLocalization) //{ // realPath = Regex.Replace(realPath, "^Assets/", "Assets/L10n/" + Const.L10n + "/"); //} UnityEngine.Object obj = target_bundle_bw.GetBundle().LoadAsset(realPath, assetType); if (obj == null) { Debugger.LogError("targetBundle Wrong!"); return(null); } ret_aw = new AssetWrapper(obj, assetPath, assetType, bundleName, false); } m_assetWrapperCache.Add(assetPath, ret_aw); return(ret_aw); }
private AssetWrapper LoadRes(string assetPath, System.Type assetType) { //寮濮嬪姞杞藉?搴旂殑璧勬簮鍖勭.assetbundle) string abName = _asset2Bundle[assetPath]; string[] dps; if (m_isLocalization) { dps = m_manifestL10n.GetAllDependencies(abName); } else { dps = m_manifest.GetAllDependencies(abName); } for (int i = 0; i < dps.Length; i++) { string dep_name = dps[i]; if (m_bundleCache.ContainsKey(dep_name)) { m_bundleCache[dep_name].AddRefAsset(assetPath); continue; } else { if (string.IsNullOrEmpty(dep_name)) { Log.PrintMsg("鏌ヤ竴涓娺" + abName + " 鐨刴anifest鏂囦欢锛屾湁渚濊禆鏄?┖鐨勩佱"); continue; } //string local_path = GetLocalFileUrl(dep_name); //byte[] dep_content = System.IO.File.ReadAllBytes(local_path); //AssetBundle dep_bundle = AssetBundle.CreateFromMemoryImmediate(dep_content); ////AssetBundle dep_bundle = AssetBundle.CreateFromFile(local_path); //鍦ㄦ煇浜涘钩鍙颁笂璇诲彇鍘嬬缉鏂囦欢浼氬穿婧冨緟鏂皏ersion瑙e喅 //Assert.IsNotNull<AssetBundle>(dep_bundle, "渚濊禆鎵撳寘璧勬簮鏈夐棶棰楖" + dep_name); //Object temp = dep_bundle.mainAsset; //if(temp!= null) // Debugger.Log("dep_bundle mainAsset:" + temp.name); //BundleWrapper loaded_bundle_bw = new BundleWrapper(dep_name, dep_bundle); //loaded_bundle_bw.AddRefAsset(assetPath); //m_bundleCache.Add(dep_name, loaded_bundle_bw); // keep in bundle cache BundleWrapper loaded_bundle_bw = LoadBundle(dep_name); loaded_bundle_bw.AddRefAsset(assetPath); Object temp = loaded_bundle_bw.GetBundle().mainAsset; if (temp != null) { Debugger.Log("dep_bundle mainAsset:" + temp.name); } } }//渚濊禆璧勬簮鍔犺浇瀹屾瘯; Lorry if (m_bundleCache.ContainsKey(abName)) {//宸茬粡瀛樺湪姝?undle鐨勭紦瀛橈紝浣嗘槸娌℃湁asset缂撳瓨锛岃瘉鏄庤祫婧愬寘宸茬粡鍔犺浇锛屽彧鏄?病鏈塴oad 姝_asset,鍦ㄧ壒娈婃儏鍐典笅鍑虹幇bug Object obj = m_bundleCache[abName].GetBundle().LoadAsset(assetPath, assetType); AssetWrapper ret = new AssetWrapper(obj, assetPath, assetType, abName, IsSceneBundle(abName)); m_assetWrapperCache.Add(assetPath, ret); //TODO:鑰冭檻缁檅undle娣诲姞寮曠敤,浣嗕及璁狓0%涓嶇敤閿姣?闇浠旂粏鑰冭檻 Lorry m_bundleCache[abName].AddRefAsset(assetPath); return(ret); } // load target bundle BundleWrapper target_bundle_bw = LoadBundle(abName); target_bundle_bw.AddRefAsset(assetPath); // load asset AssetWrapper ret_aw; if (IsSceneBundle(abName)) {//濡傛灉鏄?満鏅?紝assetBundle杞藉叆鍚庯紝閫氳繃loadlevel杩涘叆; ret_aw = new AssetWrapper(null, assetPath, assetType, abName, true); } else { // 璇诲彇鏈?湴鍖栬祫婧愭椂锛屽皢瀹為檯璺?緞涓?殑/L10n/xxx/琛ヤ笂; ly0464 string realPath = assetPath; if (m_isLocalization) { realPath = Regex.Replace(realPath, "^Assets/", "Assets/L10n/" + Const.L10n + "/"); } Object obj = target_bundle_bw.GetBundle().LoadAsset(realPath, assetType); if (obj == null) { Debugger.LogError("targetBundle Wrong!"); return(null); } ret_aw = new AssetWrapper(obj, assetPath, assetType, abName, false); // add bundle refs //AddBundleRefAsset(abName, assetPath); } m_assetWrapperCache.Add(assetPath, ret_aw); return(ret_aw); }