IEnumerator Monster001() { yield return 1; #if UNITY_IPHONE string path = "file://" + Application.dataPath + "/Raw/"; #elif UNITY_STANDALONE_WIN string path = "file://" + Application.dataPath + "/StreamingAssets/"; #else string path = "jar:file://" + Application.dataPath + "!/assets/"; #endif Debug.Log(path + "monster001.assetBundles"); ABLoad load = new ABLoad(path + "monster001.assetBundles"); while(true) { if (load.bundle.isDone) break; yield return 1; } Debug.Log(load); //GameObject res = load.LoadGameObject("monster001"); GameObject res = load.Load<GameObject>("monster001"); Debug.Log(res); Instantiate(res); load.Close(); }
IEnumerator Scene() { yield return 1; #if UNITY_IPHONE string path = "file://" + Application.dataPath + "/Raw/"; #elif UNITY_STANDALONE_WIN string path = "file://" + Application.dataPath + "/StreamingAssets/"; #else string path = "jar:file://" + Application.dataPath + "!/assets/"; #endif Debug.Log(path + "110101.assetBundles"); ABLoad load = new ABLoad(path + "110101.assetBundles"); while (true) { if (load.bundle.isDone) break; yield return 1; } // 加载场景 GameObject res = load.Load<GameObject>("110101"); Instantiate(res); // 加载LightMap ArrayList texlist = new ArrayList();// Texture2D Object[] objects = load.LoadAll(); foreach (Object e in objects) { if (!e.name.StartsWith("LightmapFar-")) continue; if (e.GetType() == typeof(Texture2D)) texlist.Add(e); } texlist.Sort(); // 数据集数量 int lmDataSetCount = (texlist.Count + 1) / 2; int lmDataIndex = 0; LightmapData[] lmDataSet = new LightmapData[lmDataSetCount]; for (int i = 0; i < texlist.Count; ++i) { LightmapData lmData = new LightmapData(); lmData.lightmapFar = (Texture2D)texlist[i]; if ((++i) != texlist.Count) lmData.lightmapNear = (Texture2D)texlist[i]; lmDataSet[lmDataIndex] = lmData; } LightmapSettings.lightmapsMode = LightmapsMode.Dual; LightmapSettings.lightmaps = lmDataSet; load.Close(); }
public IEnumerator CallBackSync(ABLoad mAB, string url, string resname, System.Type type, ABDataType abtype) { //Debuger.Log("AssetBundleUti.CallBack " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString()); Count++; callbackerror = string.Empty; bCallback = true; do { if (!mAB.Create(url)) { callbackerror = "ABLoad Create Error " + url; bCallback = false; break; } yield return StartCoroutine(mAB.Waiting()); //Debuger.Log("Waiting End "); while (true) { if (mAB.IsWWW()) break; yield return null; } //Debuger.Log("Error " + mAB.Error()); if (mAB.Error()) { //Debuger.LogError(mAB.GetErrorMsg()); callbackerror = mAB.GetErrorMsg(); bCallback = false; break; } else { if (typeof(AudioClip) == type) { AudioClip ac = mAB.Load(resname); //Debuger.Log(resname + " " + ac.length + " " + ac.samples + " " + ac.isReadyToPlay + " " + ac.channels); //Debuger.Log(ac.isReadyToPlay); if (ac != null) { while (true) { if (ac.isReadyToPlay) break; yield return null; } ac.name = resname; mAB.Pair(resname, ac, type); // 返回 if (OnFinishLoading != null) { //Debuger.Log("AssetBundleUti.OnFinishLoading " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString()); OnFinishLoading(url, resname, type, true); } } else { Debuger.LogError("Load " + resname + " in " + url); callbackerror = mAB.GetErrorMsg(); bCallback = false; break; } } else { AssetBundle ab = mAB.GetAb(); if (ab == null) { callbackerror = "AssetBundle == null"; bCallback = false; break; } AssetBundleRequest request = ab.LoadAsync(resname, type); if (request == null) { callbackerror = "LoadAsync AssetBundleRequest == null"; bCallback = false; break; } while (true) { if (request.isDone) break; yield return null; } mAB.Pair(resname, request.asset, type); // 返回 if (OnFinishLoading == null) { //Debuger.Log("AssetBundleUti.OnFinishLoading " + System.IO.Path.GetFileName(url) + " " + resname + " " + type.ToString()); callbackerror = "OnFinishLoading == null"; bCallback = false; break; } OnFinishLoading(url, resname, type, true); } } } while (false); if (!bCallback) { Debuger.LogError("Error " + mAB.Error() + " callbackerror: " + callbackerror); MessageBox(callbackerror + " \r\n " + OnFinishLoading.ToString()); OnFinishLoading(url, resname, type, false, callbackerror); if (mAB != null) { mAB.Dispose(); mAB = null; } } else { releaseQueue.Enqueue(mAB); } Count--; if (Count <= 0) { Count = 0; releaseAllBundles(); } }