static public IEnumerator AssetbundleSendRequest(UnityWebRequest request, string assetBundleName) { if (request == null) yield break; stDownloadingWWWs downloadwww = new stDownloadingWWWs(); yield return request.SendWebRequest(); downloadwww.www = request; downloadwww.referenceCount = 1; downloadwww.startTime = Time.realtimeSinceStartup; Debug.Log(string.Format("Start Send GetAssetBundle : url ({0}), startTime ({1})", downloadwww.www.url, downloadwww.startTime)); m_DownloadingWWWs.Add(assetBundleName, downloadwww); }
// Where we actuall call WWW to download the assetBundle. static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest) { // Already loaded. LoadedAssetBundle bundle = null; m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle != null) { bundle.m_ReferencedCount++; return true; } // @TODO: Do we need to consider the referenced count of WWWs? // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync(). // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs. // I think, Duplicate WWWs doesn't need to consider. because normally, most developer doesn't design the same name. if (m_DownloadingWWWs.ContainsKey(assetBundleName)) { stDownloadingWWWs downloadwwws = m_DownloadingWWWs[assetBundleName]; downloadwwws.referenceCount++; m_DownloadingWWWs[assetBundleName] = downloadwwws; return true; } //WWW download = null; UnityWebRequest download = null; string url = m_BaseDownloadingURL + assetBundleName; // For manifest assetbundle, always download it as we don't have hash for it. if (isLoadingAssetBundleManifest) { url = m_BaseCDNURL + assetBundleName; Debug.Log ("LoadAssetBundleInternal : isLoadingManifest : " + url); download = UnityWebRequestAssetBundle.GetAssetBundle(URLAntiCacheRandomizer(url));//new WWW(URLAntiCacheRandomizer(url)); } else { if (dicVersion == null) { if (VersionChecker.Instance != null) dicVersion = VersionChecker.Instance.AssetInfoDict; } else { if (dicVersion.Count == 0) { if (VersionChecker.Instance != null) dicVersion = VersionChecker.Instance.AssetInfoDict; } } int nVersion = 0; if (dicVersion.ContainsKey(assetBundleName)) { nVersion = (int)dicVersion[assetBundleName].Version; url = dicVersion[assetBundleName].URL + assetBundleName; } download = UnityWebRequestAssetBundle.GetAssetBundle(url, (uint)nVersion, 0);//WWW.LoadFromCacheOrDownload(url, nVersion); Debug.Log ("LoadAssetBundleInternal : LoadFromCacheOrDownload : " + url + ", ver: " + nVersion); } stDownloadingWWWs downloadwww = new stDownloadingWWWs(); AsyncOperation operation = download.SendWebRequest(); while (operation.isDone == false) continue; downloadwww.www = download; downloadwww.referenceCount = 1; downloadwww.startTime = Time.realtimeSinceStartup; Debug.Log(string.Format("Start Send GetAssetBundle : url ({0}), startTime ({1})", downloadwww.www.url, downloadwww.startTime)); m_DownloadingWWWs.Add(assetBundleName, downloadwww); //StartCoroutine(AssetbundleSendRequest(download, assetBundleName)); return false; }