Exemplo n.º 1
0
        public override void Initialize()
        {
            var path = Helper.GetDataPath(name.ToLower());

            if (Bundles.IsInternal(name))
            {
                path = "file:///" + Helper.GetInternalPath(name);
            }
            _request = UnityWebRequestAssetBundle.GetAssetBundle(path, Bundles.GetHash128(name), 0);
            _request.SendWebRequest();
            if (_request == null)
            {
                error = name + " LoadFromFileAsync falied.";
            }
            var items = Bundles.GetBundleDependencies(name.ToLower());

            if (items != null && items.Length > 0)
            {
                for (int i = 0, I = items.Length; i < I; i++)
                {
                    var item = items[i];
                    if (Bundles.IsCyclicDependsLoaded(item))
                    {
                        Debug.LogWarning("Cyclic dependence " + name);
                    }
                    else
                    {
                        dependencies.Add(Bundles.LoadAsync(item));
                    }
                }
            }
        }
 public override IObservable <UnityWebRequest> Download(IProgress <float> progress = null)
 {
     return(Observable.Defer(() =>
     {
         var request = Hash.isValid
                                 ? UnityWebRequestAssetBundle.GetAssetBundle(Url, Hash, 0)
                                 : UnityWebRequestAssetBundle.GetAssetBundle(Url);
         return request.SendAsObservable(progress).Do(OnDownloaded);
     }));
 }
Exemplo n.º 3
0
        IObservable <AssetBundle> GetAssetBundleCore(string actualName)
        {
            ThrowIfManifestNotLoaded();
            string url     = RootUrl + actualName;
            var    hash    = Manifest.GetAssetBundleHash(actualName);
            var    request = hash.isValid
                                ? UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0)
                                : UnityWebRequestAssetBundle.GetAssetBundle(url);

            return(request.SendAsObservable().LoadAssetBundle());
        }
Exemplo n.º 4
0
        public virtual void Initialize()
        {
            var path = Helper.GetDataPath(name.ToLower());
            //使用了Caching的资源 AssetBundle.LoadFromFile 找不到路径,这里直接阻塞等待加载完成,
            //按照官方文档上说的,对已经Cache的资源UnityWebRequest.GetAssetBundle 和 AssetBundle.LoadFromFile 功能一样,都会立刻返回
            var _request = UnityWebRequestAssetBundle.GetAssetBundle(path, Bundles.GetHash128(name), 0);

            _request.SendWebRequest();
            while (!_request.isDone)
            {
                Thread.Yield();
            }
            _assetBundle = DownloadHandlerAssetBundle.GetContent(_request);

            _request.Dispose();

            if (_assetBundle == null)
            {
                error = name + " LoadFromFile failed.";
            }
            var items = Bundles.GetBundleDependencies(name.ToLower());

            if (items != null && items.Length > 0)
            {
                for (int i = 0, I = items.Length; i < I; i++)
                {
                    var item = items [i];
                    if (Bundles.IsCyclicDependsLoaded(item))
                    {
#if UNITY_EDITOR
                        Debug.LogWarning("Cyclic dependence " + name);
#endif
                    }
                    else
                    {
                        dependencies.Add(Bundles.Load(item));
                    }
                }
            }
        }
Exemplo n.º 5
0
        static IEnumerator Obtain(string sourceFile, string bundleName, Hash128 bundleHash, Action <string, float, bool> handle)
        {
            //List<Hash128> listOfCachedVersions = new List<Hash128>();
            //Caching.GetCachedVersions(bundleName, listOfCachedVersions);
            //foreach(var s in listOfCachedVersions){
            //    Debug.Log(sourceFile+" -> "+s);
            //}
            var request = UnityWebRequestAssetBundle.GetAssetBundle(sourceFile, bundleHash, 0);

            request.SendWebRequest();
            while (!request.isDone)
            {
                handle?.Invoke(bundleName, request.downloadProgress, false);
                yield return(new WaitForEndOfFrame());
            }
            if (bundleName.Contains(Helper.LogoLoadingPrefabName))
            {
                File.WriteAllBytes(Application.persistentDataPath + "/" + Helper.LogoLoadingPrefabName, request.downloadHandler.data);
            }
            //yield return request.Send();
            request.Dispose();
            request = null;
            handle?.Invoke(bundleName, 1.0f, true);
        }
Exemplo n.º 6
0
 static IObservable <ReqVerPair> SendManifestRequest(string url) => AssetLoader.WhenCacheReady(() =>
 {
     int version = PlayerPrefs.GetInt(ManifestVersionKey, 1);
     var hash    = VersionToHash(version);
     if (!Caching.IsVersionCached(url, hash))
     {
         return(UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0)
                .SendAsObservable().Select(req => CreateReqVerPair(req, version, true)));
     }
     return(UnityWebRequest.Head(url).SendAsObservable()
            .Catch((Exception __) => Observable.Return <UnityWebRequest>(null))
            .ContinueWith(head =>
     {
         if (head != null && head.GetETag() == PlayerPrefs.GetString(ManifestETagKey))
         {
             return UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0)
             .SendAsObservable().Select(req => CreateReqVerPair(req, version));
         }
         version = unchecked (version + 1);
         hash = VersionToHash(version);
         return UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0)
         .SendAsObservable().Select(req => CreateReqVerPair(req, version, true));
     }));
 });
Exemplo n.º 7
0
 public static UnityWebRequest GetAssetBundle(string uri)
 {
     return(UnityWebRequest.GetAssetBundle(uri, 0u));
 }