public BundleLoadStatus GetBundleStatus(string urlFromBundles, bool enforceUnityBundle) { if (enforceUnityBundle) { properPath(ref urlFromBundles); } BundleLoadStatus status = BundleLoadStatus.UNKNOWN; if (bundleDict.ContainsKey(urlFromBundles)) { if (bundleDict[urlFromBundles] == null) { status = BundleLoadStatus.NOTLOADED; bundleDict.Remove(urlFromBundles); Debug.Log(urlFromBundles + " was not loaded."); } else { status = BundleLoadStatus.LOADED; } } else if (loadingDict.ContainsKey(urlFromBundles)) { status = BundleLoadStatus.LOADING; } return(status); }
public AssetBundleItem(string bundleName, Action <bool, string> loadCallbcak) { BundleName = bundleName; abRelation = new ABRelation(bundleName); LoadCallback = loadCallbcak; BundleLoadStatus = BundleLoadStatus.WAIT_LOAD; _ABDownLoadPath = PathTool.GetWWWPath() + "/" + bundleName; }
/// <summary> /// 强制释放,不安全 /// </summary> public void DisposeAll() { BundleLoadStatus = BundleLoadStatus.DISPOSED; if (assetBundle != null) { assetBundle.Unload(true); } _AssetLoader = null; }
public void LoadAssetBundleSync() { assetBundle = AssetBundle.LoadFromFile(_ABDownLoadPath); if (assetBundle == null) { Debug.LogError(GetType() + "LoadAssetBundle失败:" + _ABDownLoadPath); LoadCallback(false, BundleName); } else { _AssetLoader = new AssetLoader(assetBundle); BundleLoadStatus = BundleLoadStatus.LOADED; if (LoadCallback != null) { LoadCallback(true, BundleName); } } }
public IEnumerator LoadAssetBundle() { using (UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(_ABDownLoadPath)) { request.SendWebRequest(); while (!request.isDone) { //Debug.Log(_ABDownLoadPath + "下载中(" + request.downloadProgress * 100 + "%)"); yield return(null); } //取得ab的方式1 //AssetBundle ab_prefab = DownloadHandlerAssetBundle.GetContent(request); //取得ab的方式2 assetBundle = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle; if (BundleLoadStatus != BundleLoadStatus.DISPOSED) { if (assetBundle == null) { Debug.LogError(GetType() + "LoadAssetBundle失败:" + _ABDownLoadPath); BundleLoadStatus = BundleLoadStatus.LOAD_FAIL; LoadCallback(false, BundleName); } else { Debug.Log(assetBundle.name + "异步加载加载完成"); _AssetLoader = new AssetLoader(assetBundle); BundleLoadStatus = BundleLoadStatus.LOADED; if (LoadCallback != null) { LoadCallback(true, BundleName); } } } else { if (assetBundle != null) { assetBundle.Unload(false); } } } }