public ABLoad Add(string url, int version, ABDataType abtype) { string keyName = url + version.ToString(); ABLoad bl = null; switch (abtype) { case ABDataType.Normal: bl = new ABLoadFile(version, true); break; case ABDataType.Mpq: bl = new ABLoadMpq(version, true); break; } mABLoads[keyName] = bl; return bl; }
public override IEnumerator Waiting() { float begintime = Time.realtimeSinceStartup; yield return loadAdapter.Waiting(); Debuger.Log("Waiting End "); while (true) { if (loadAdapter.IsWWW()) break; yield return null; } // _Waiting(); //} //private void _Waiting() //{ ErrorMsg = loadAdapter.GetErrorMsg(); if (string.IsNullOrEmpty(ErrorMsg)) { { Pair(mResName, loadAdapter.GetAb().Load(mResName + ABLoadScene.GameObject, typeof(GameObject)), typeof(GameObject)); } { Pair(ABLoadScene.Lightmap, loadAdapter.GetAb().Load(ABLoadScene.Lightmap, typeof(Texture2D)), typeof(Texture2D)); } { Pair(mResName + ABLoadScene.Material, loadAdapter.GetAb().Load(mResName + ABLoadScene.Material, typeof(StringPrefab)), typeof(StringPrefab)); } { Pair(ABLoadScene.Nav, loadAdapter.GetAb().Load(mResName + ABLoadScene.Nav, typeof(GameObject)), typeof(GameObjectNav)); } { if (asset != null) { foreach (StringPrefabMaterial e in asset.material) { //Debuger.Log("assetbundlePath " + e.assetbundlePath); float counttime = Time.realtimeSinceStartup; #if 异步 AssetBundleRequest R = (AssetBundleRequest)mAssetBundleRequestObject[e.assetbundlePath]; #else Material R = (Material)mMaterialObject[e.assetbundlePath]; #endif if (R == null) { string fileurl = System.IO.Path.GetDirectoryName(mUrl) + "/" + e.assetbundlePath; ABLoad loadAdapterTmp = null; switch (mABDataType) { case ABDataType.Mpq: loadAdapterTmp = new ABLoadMpq(mVersion); break; case ABDataType.Normal: loadAdapterTmp = new ABLoadFile(mVersion); break; } loadAdapterTmp.Create(fileurl); { yield return loadAdapterTmp.Waiting(); while (true) { if (loadAdapterTmp.IsWWW()) break; yield return null; } } if (string.IsNullOrEmpty(loadAdapterTmp.GetErrorMsg())) { bool success = true; do { if (loadAdapterTmp.GetAb() == null) { Debuger.LogError("loadAdapterTmp.GetAb() == null" + " fileurl: " + fileurl + " mUrl: " + mUrl); success = false; ErrorMsg = "loadAdapterTmp.GetAb() == null"; break; } //string resname = System.IO.Path.GetFileName(e.meshrendererGameObject); //Debuger.Log("3 " + resname); #if 异步 AssetBundleRequest requestMat = loadAdapterTmp.GetAb().LoadAsync(e.assetname, typeof(Material)); mAssetBundleRequestObject[e.assetbundlePath] = requestMat; while (true) { if (requestMat.isDone) break; yield return null; } //Debuger.Log("4 " + request); if (requestMat.asset == null) { Debuger.LogError("requestMat.asset == null" + " fileurl: " + fileurl + " mUrl: " + mUrl); ErrorMsg = "requestMat.asset == null"; success = false; break; } #else Material m = (Material)loadAdapterTmp.GetAb().Load(e.assetname, typeof(Material)); mMaterialObject[e.assetbundlePath] = m; #endif mAbLoadObject.Add(loadAdapterTmp); } while (false); if (!success) { loadAdapterTmp.Dispose(); loadAdapterTmp = null; } } else { Debuger.LogError(loadAdapterTmp.GetErrorMsg() + " fileurl: " + fileurl + " mUrl: " + mUrl); ErrorMsg = loadAdapterTmp.GetErrorMsg(); } } R = null; Debuger.Log("\t\tAssetBundleEditor.ABLoadScene " + (Time.realtimeSinceStartup - counttime).ToString("f5") + " File: " + e.assetbundlePath); } } else { ErrorMsg = "asset == null"; Debuger.LogError("asset == null"); } } } Debuger.Log("AssetBundleEditor.ABLoadScene " + (Time.realtimeSinceStartup - begintime).ToString("f5") + " Count: " + asset.material.Length); }