Esempio n. 1
0
        protected bool CreateAssetBundleAsync(string assetbundleName, bool isIndependent = false)
        {
            #if UNITY_EDITOR
//            EditorApplication.isPaused = true;
            #endif


            if (IsAssetBundleLoaded(assetbundleName) || webRequesting.ContainsKey(assetbundleName))
            {
                return(false);
            }

            var creater = ResourceWebRequester.Get();
            var url     = AssetBundleUtility.GetAssetBundleFileUrl(assetbundleName);
            if (!manifest.GetAssetBundleHash(assetbundleName).isValid&& idpManifest.GetAssetBundleHash(assetbundleName).isValid)
            {
                url = AssetBundleUtility.GetIndependentAssetBundleFileUrl(assetbundleName);
            }
            creater.Init(assetbundleName, url);
            webRequesting.Add(assetbundleName, creater);
            webRequesterQueue.Enqueue(creater);
            // 创建器持有的引用:创建器对每个ab来说是全局唯一的
            IncreaseReferenceCount(assetbundleName);
            return(true);
        }
Esempio n. 2
0
        public List <string> CompareTo(Manifest otherManifest)
        {
            List <string> ret_list = new List <string>();

            if (otherManifest == null || otherManifest.assetbundleManifest == null)
            {
                return(ret_list);
            }

            string[] other_name_list = otherManifest.GetAllAssetBundleNames();
            string[] self_name_list  = GetAllAssetBundleNames();
            foreach (string name in other_name_list)
            {
                int idx = System.Array.FindIndex(self_name_list, element => element.Equals(name));
                if (idx == -1)
                {
                    //对方有、自己无
                    ret_list.Add(name);
                }
                else if (!GetAssetBundleHash(self_name_list[idx]).Equals(otherManifest.GetAssetBundleHash(name)))
                {
                    //对方有,自己有,但是hash不同
                    ret_list.Add(name);
                }
                else
                {
                    //对方有,自己有,且hash相同:什么也不做
                    //donothing
                }
            }
            return(ret_list);
        }
 public bool IsVersionCached(string bundleName)
 {
     if (useHash)
     {
         bundleName = GetHashedBundleName(bundleName);
     }
     return(Caching.IsVersionCached(bundleName, Manifest.GetAssetBundleHash(bundleName)));
 }
Esempio n. 4
0
 /// <summary>
 ///     Check to see if a specific asset bundle is cached or needs to be downloaded.
 /// </summary>
 public bool IsVersionCached(string bundleName)
 {
     if (Manifest == null)
     {
         return(false);
     }
     if (useHash)
     {
         bundleName = GetHashedBundleName(bundleName);
     }
     if (string.IsNullOrEmpty(bundleName))
     {
         return(false);
     }
     return(Caching.IsVersionCached(bundleName, Manifest.GetAssetBundleHash(bundleName)));
 }
Esempio n. 5
0
        /// <summary>
        ///     Downloads an AssetBundle or returns a cached AssetBundle if it has already been downloaded.
        ///     Remember to call <see cref="UnloadBundle(UnityEngine.AssetBundle,bool)" /> for every bundle you download once you
        ///     are done with it.
        /// </summary>
        /// <param name="bundleName">Name of the bundle to download.</param>
        /// <param name="onComplete">Action to perform when the bundle has been successfully downloaded.</param>
        /// <param name="downloadSettings">
        ///     Tell the function to use a previously downloaded version of the bundle if available.
        ///     Important!  If the bundle is currently "active" (it has not been unloaded) then the active bundle will be used
        ///     regardless of this setting.  If it's important that a new version is downloaded then be sure it isn't active.
        /// </param>
        public void GetBundle(string bundleName, Action <AssetBundle> onComplete, DownloadSettings downloadSettings)
        {
            if (Initialized == false)
            {
                Debug.LogError("AssetBundleManager must be initialized before you can get a bundle.");
                onComplete(null);
                return;
            }

            if (useHash)
            {
                bundleName = GetHashedBundleName(bundleName);
            }

            AssetBundleContainer active;

            if (activeBundles.TryGetValue(bundleName, out active))
            {
                active.References++;
                onComplete(active.AssetBundle);
                return;
            }

            DownloadInProgressContainer inProgress;

            if (downloadsInProgress.TryGetValue(bundleName, out inProgress))
            {
                inProgress.References++;
                inProgress.OnComplete += onComplete;
                return;
            }

            downloadsInProgress.Add(bundleName, new DownloadInProgressContainer(onComplete));

            var mainBundle = new AssetBundleDownloadCommand {
                BundleName = bundleName,
                Hash       = downloadSettings == DownloadSettings.UseCacheIfAvailable ? Manifest.GetAssetBundleHash(bundleName) : default(Hash128),
                OnComplete = bundle => OnDownloadComplete(bundleName, bundle)
            };

            var dependencies           = Manifest.GetDirectDependencies(bundleName);
            var dependenciesToDownload = new List <string>();

            for (int i = 0; i < dependencies.Length; i++)
            {
                if (activeBundles.TryGetValue(dependencies[i], out active))
                {
                    active.References++;
                }
                else
                {
                    dependenciesToDownload.Add(dependencies[i]);
                }
            }

            if (dependenciesToDownload.Count > 0)
            {
                var dependencyCount = dependenciesToDownload.Count;
                Action <AssetBundle> onDependenciesComplete = dependency => {
                    if (--dependencyCount == 0)
                    {
                        handler.Handle(mainBundle);
                    }
                };

                for (int i = 0; i < dependenciesToDownload.Count; i++)
                {
                    var dependencyName = dependenciesToDownload[i];
                    if (useHash)
                    {
                        dependencyName = GetUnhashedBundleName(dependencyName);
                    }
                    GetBundle(dependencyName, onDependenciesComplete);
                }
            }
            else
            {
                handler.Handle(mainBundle);
            }
        }