Пример #1
0
        private void UnloadAssetBundleInternal(string assetBundleName)
        {
            CachedAssetBundle ret = null;

            if (cachedAssetBundles.TryGetValue(assetBundleName, out ret))
            {
                if (ret.AssetBundle.State == CachedState.Cached)
                {
                    ret.ReferencedCount--;
                    if (ret.ReferencedCount == 0)
                    {
                        ret.AssetBundle.Value.Unload(true);
                    }
                }
                else if (ret.AssetBundle.State == CachedState.Caching)
                {
                    ret.ReferencedCount--;
                    if (ret.ReferencedCount == 0)
                    {
                        ret.AssetBundle.Abort();
                    }
                }
                if (ret.ReferencedCount == 0)
                {
                    cachedAssetBundles.Remove(assetBundleName);
                }
            }
        }
Пример #2
0
        private AsyncTask LoadAssetBundleInternal(string assetBundleName, bool isManifest, System.Action <UnityEngine.AssetBundle> onSuccess = null, System.Action <System.Exception> onFail = null)
        {
            CachedAssetBundle ret = null;

            if (cachedAssetBundles.TryGetValue(assetBundleName, out ret))
            {
                if (ret.AssetBundle.State == CachedState.Cached)
                {
                    onSuccess(ret.AssetBundle.Value);
                    return(AsyncTaskInternal.Complete());
                }
                else
                {
                    var task = ret.AssetBundle.WaitForValueCreated(
                        this,
                        onSuccess,
                        onFail
                        );
                    return(task);
                }
            }
            else
            {
                CachedAssetBundle cachedAssetBundle = new CachedAssetBundle(
                    (s, f) => {
                    string assetbundleUri         = System.IO.Path.Combine(BaseUri.AbsoluteUri, assetBundleName);
                    AsyncTaskInternal downloading = new AsyncTaskInternal(assetbundleUri);
                    Http http = null;
                    if (!isManifest)
                    {
                        http = Http.GetAssetBundle(assetbundleUri, manifest.GetAssetBundleHash(assetBundleName), 0,
                                                   (www) => {
                            AssetBundle assetBundle = www.ToAssetBundle();
                            s(assetBundle);
                        },
                                                   f
                                                   );
                    }
                    else
                    {
                        http = Http.GetAssetBundle(assetbundleUri, 0, (www) => {
                            AssetBundle assetBundle = www.ToAssetBundle();
                            s(assetBundle);
                        }, f);
                    }
                    if (downloadingTask.Count == 0)
                    {
                        StartCoroutine(LoadAssetBundleQueue());
                    }
                    downloadingTask.Add(new KeyValuePair <Http, AsyncTaskInternal> (http, downloading));
                    return(downloading);
                },
                    onSuccess,
                    (ex) => {
                    cachedAssetBundles.Remove(assetBundleName);
                }
                    );
                cachedAssetBundles.Add(assetBundleName, cachedAssetBundle);
                return(cachedAssetBundle.AssetBundle.AsyncResult);
            }
        }