/// <summary> /// �����غõ�bundle���浽�ڴ��ֵ�ȴ����� /// </summary> /// <param name="task"></param> /// <param name="bundle"></param> public void AddBundleToDict(BundleDownloadTask task, AssetBundle bundle) { switch (task.bundleType) { case BundleType.GameData: gameDataAssetBundleDict.Add(task.name, bundle); break; case BundleType.Atlas: atlasAssetBundleDict.Add(task.name, bundle); break; } LogManager.Log("DownLoad bundle Success!" + task.name); task.isDownloaded = true; var lMessage = new Message(); lMessage.Type = GameEvent.DOWNLOAD_ASSETBUNDLE_SUCCESS; lMessage.Data = new DownloadAssetbundleSuccessArgs { task = task }; lMessage.Sender = this; MessageDispatcher.SendMessage(lMessage); //CheckDownloadStatus(); }
public IEnumerator DownloadAssetBundle(BundleDownloadTask task) { string bundleName; //if (Application.platform == RuntimePlatform.WindowsEditor) //{ // bundleName = string.Format("file://{0}/{1}", AssetbundlePathURL, task.name.ToLower()); //} //else bundleName = AssetbundlePathURL + task.name.ToLower(); LogManager.Log("DownLoadAssetBundle" + bundleName); //using (WWW www = WWW.LoadFromCacheOrDownload(bundleName, task.version)) using (var www = new WWW(bundleName)) { // abRef.www.threadPriority = ThreadPriority.Low; while (!www.isDone) { yield return(null); } if (www.error != null) { LogManager.LogError("Load www.error: " + www.error); } else { // Tools.CreateFile(task.name, www.bytes); AddBundleToDict(task, www.assetBundle); } } //return null; }
/* * public void LoadLocalAssetBundle(string name, int version) * { * string keyName = name + version.ToString(); * if (dictAssetBundleRefs.ContainsKey(keyName)) * { * return; * } * AssetBundleRef abRef = new AssetBundleRef(name, version); * string bundleName = name + ".unity3d"; * abRef.assetBundle = (AssetBundle)Resources.Load(bundleName, typeof(AssetBundle)); * dictAssetBundleRefs.Add(keyName, abRef); * statusDict[name].isDownloaded = true; * Debug.Log("Local Load Success!" + name); * CheckDownloadStatus(); * } */ /// <summary> /// �ӱ��ؼ���bundle /// </summary> /// <param name="task"></param> /// <returns></returns> private IEnumerator LoadLocalAssetBundle(BundleDownloadTask task) { //AssetBundle bundle = GetAssetBundle(task.keyName, task.bundleType); //if (bundle != null) //{ // AddBundleToDict(task, bundle); // yield return null; //} //else { string bundleName; if (Application.platform != RuntimePlatform.Android) { //bundleName = "file://" + string.Format("{0}/{1}", AssetbundlePathURL, task.name.ToLower()); if (AssetbundlePathURL.Contains("file") || AssetbundlePathURL.Contains("http")) { bundleName = AssetbundlePathURL + task.name.ToLower(); } else { bundleName = "file://" + string.Format("{0}/{1}", AssetbundlePathURL, task.name.ToLower()); } } else { bundleName = AssetbundlePathURL + task.name.ToLower(); } LogManager.Log("LoadLocalAssetBundle" + bundleName); task.reDownloadTimesLeft--; task.startDownloadTime = DateTime.Now; //using (WWW www = WWW.LoadFromCacheOrDownload(bundleName, task.version)) using (var www = new WWW(bundleName)) { // abRef.www.threadPriority = ThreadPriority.Low; while (!www.isDone) { if (DateTime.Now > task.startDownloadTime.AddSeconds(15) && task.reDownloadTimesLeft > 0) { StartCoroutine(LoadLocalAssetBundle(task)); } //LoadLocalAssetBundle(task); else { yield return(null); } } if (www.error != null) { LogManager.LogError("Local Load www.error: " + www.error); if (task.reDownloadTimesLeft > 0) { StartCoroutine(LoadLocalAssetBundle(task)); } // LoadLocalAssetBundle(task); } else { // Tools.CreateFile(task.name, www.bytes); AddBundleToDict(task, www.assetBundle); } } } }