public static void DownloadAssetBundle(AssetBundleRef assetBundleRef, Action <bool> isSuccess)
 {
     if (CheckAssetBundleIsLoaded(assetBundleRef.name))
     {
         Debug.Log(assetBundleRef.name + " has been loaded in dictionary.");
     }
     else
     {
         LWUtilities.StaticCoroutine.SingleTon.StartCoroutine(downloadAssetBundle(assetBundleRef, isSuccess));
     }
 }
Beispiel #2
0
        private void GetAssetBundle(string bundleName, Action <bool> callback)
        {
            Hash128 hash = new Hash128();

            Debug.Log(bundleName);
            string bundleNameTransfered = LWAssetBundleParser.TransferItemIdToBundleName(bundleName);

            Console.text += bundleName + "\r\n";
            AssetBundleRef requestAB = new AssetBundleRef(bundleNameTransfered, hash);

            AssetBundleManager.DownloadAssetBundle(requestAB, callback);
        }
        public static IEnumerator downloadAssetBundle(AssetBundleRef assetBundleRef, Action <bool> isSuccess)
        {
            Debug.Log("Get Assetbundle Name: " + assetBundleRef.name);
            Hash128 version = assetBundleRef.version;

            while (!Caching.ready)
            {
                yield return(null);
            }

            if (manifest == null)
            {
                using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(System.IO.Path.Combine(assetBundlePath, "StandaloneWindows")))
                {
                    yield return(www.SendWebRequest());

                    if (www.isNetworkError || www.isHttpError)
                    {
                        Debug.Log(www.error);
                        if (isSuccess != null)
                        {
                            isSuccess(false);
                        }
                    }
                    else
                    {
                        AssetBundle manifestBundle = DownloadHandlerAssetBundle.GetContent(www);
                        manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");
                        manifestBundle.Unload(false);
                    }
                    www.Dispose();
                }
            }

            string[] dependentAssetBundles = manifest.GetAllDependencies(assetBundleRef.name);
            assetBundleRef.Dependencies = dependentAssetBundles;
            Debug.Log("DependentAssetBundles Count: " + dependentAssetBundles.Length);
            AssetBundle[] abs = new AssetBundle[dependentAssetBundles.Length];
            for (int i = 0; i < dependentAssetBundles.Length; i++)
            {
                string dependentAssetBundlePath = assetBundlePath + "/" + dependentAssetBundles[i];
                Debug.Log("Get DependentAssetBundle: " + dependentAssetBundles[i] + " , Path = " + dependentAssetBundlePath);
                using (UnityWebRequest wwwDependent = UnityWebRequestAssetBundle.GetAssetBundle(dependentAssetBundlePath, version, 0))
                {
                    yield return(wwwDependent.SendWebRequest());

                    abs[i] = DownloadHandlerAssetBundle.GetContent(wwwDependent);

                    if (abs[i] != null)
                    {
                        AssetBundleLoadedDict.Add(dependentAssetBundles[i], new AssetBundleRef(abs[i].name, version, abs[i]));
                        Debug.Log("Add " + abs[i].name + " to loaded dictionary");
                    }

                    wwwDependent.Dispose();
                }
            }

            using (UnityWebRequest wwwAssetBundle = UnityWebRequestAssetBundle.GetAssetBundle(assetBundlePath + "/" + assetBundleRef.name, version, 0))
            {
                yield return(wwwAssetBundle.SendWebRequest());

                if (wwwAssetBundle.isNetworkError || wwwAssetBundle.isHttpError)
                {
                    Debug.Log(wwwAssetBundle.error);
                    if (isSuccess != null)
                    {
                        isSuccess(false);
                    }
                }
                else
                {
                    AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(wwwAssetBundle);
                    assetBundleRef.assetBundle = bundle;
                    Debug.Log("Success! Add " + assetBundleRef.name + " to dictionary");
                    AssetBundleLoadedDict.Add(assetBundleRef.name, assetBundleRef);
                    if (isSuccess != null)
                    {
                        isSuccess(true);
                    }

                    wwwAssetBundle.Dispose();
                }
            }
        }