Exemple #1
0
        void LoadNext()
        {
            if (requestList.Count < 1)
            {
                state       = BundleLoadState.Success;
                totalLength = 0;
                loadIndex   = 0;
                return;
            }
            BundleLoadInfo info = requestList[0];

            loadIndex++;
            state = BundleLoadState.InProgress;
            if (ZBundleManager.Instance.HasBundle(info.path))
            {
                if (info.completeFun != null)
                {
                    info.completeFun.Invoke(info.path, true);
                }
                RemoveLoadInfo(info.path);
                LoadNext();
            }
            else
            {
                if (info.IsWeb)
                {
                    StartCoroutine(LoadRemoteInspector(info));
                }
                else
                {
                    StartCoroutine(LoadLocalInspector(info));
                }
            }
        }
Exemple #2
0
 public void LoadBundles(BundleInfo[] list)
 {
     if (state == BundleLoadState.InProgress || list == null)
     {
         return;
     }
     ZLog.Log("LoadBundles ..................num = " + list.Length);
     state     = BundleLoadState.Failure;
     loadIndex = 0;
     requestList.Clear();
     for (int i = 0; i < list.Length; i++)
     {
         BundleInfo model = list[i];
         if (!HasLoadInfo(model.path))
         {
             BundleLoadInfo info = new BundleLoadInfo(model.path, model.type)
             {
                 id      = model.id,
                 downURL = model.url
             };
             requestList.Add(info);
         }
     }
     totalLength = requestList.Count;
     LoadNext();
 }
Exemple #3
0
 private void RemoveLoadInfo(string address)
 {
     for (int i = 0; i < requestList.Count; i++)
     {
         BundleLoadInfo mode = requestList[i];
         if (mode.path == address)
         {
             requestList.RemoveAt(i);
             break;
         }
     }
 }
Exemple #4
0
 private bool HasLoadInfo(string address)
 {
     if (string.IsNullOrEmpty(address))
     {
         return(false);
     }
     for (int i = 0; i < requestList.Count; i++)
     {
         BundleLoadInfo mode = requestList[i];
         if (mode.path == address)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
 public void Load(string path, BundleType type, UnityAction <string, bool> complete = null)
 {
     if (string.IsNullOrEmpty(path) || !File.Exists(path))
     {
         return;
     }
     if (!HasLoadInfo(path))
     {
         BundleLoadInfo info = new BundleLoadInfo(path, type)
         {
             completeFun = complete
         };
         requestList.Add(info);
     }
     totalLength = requestList.Count;
     if (state != BundleLoadState.InProgress)
     {
         LoadNext();
     }
 }
Exemple #6
0
        IEnumerator LoadLocalInspector(BundleLoadInfo info)
        {
            AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(info.path);

            yield return(request);

            if (request.isDone)
            {
                AssetBundle bundle = request.assetBundle;
                if (bundle != null)
                {
                    ZBundleManager.Instance.AddBundle(info.path, info.type, bundle);
                }
                if (info.completeFun != null)
                {
                    info.completeFun.Invoke(info.path, true);
                }
            }
            RemoveLoadInfo(info.path);
            yield return(null);

            LoadNext();
        }
Exemple #7
0
        IEnumerator LoadRemoteInspector(BundleLoadInfo info)
        {
            string dir = Path.GetDirectoryName(info.path);

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }
            if (File.Exists(info.path))
            {
                File.Delete(info.path);
            }
            yield return(null);

            UnityWebRequest downloader = UnityWebRequest.Get(info.downURL);

            downloader.disposeDownloadHandlerOnDispose = true;
            downloader.downloadHandler = new DownloadHandlerFile(info.path);
            downloader.SendWebRequest();
            while (!downloader.isDone)
            {
                yield return(null);
            }
            if (!string.IsNullOrEmpty(downloader.error) || downloader.isNetworkError || downloader.isHttpError)
            {
                ZLog.Warning("download asset bundle file failed!!!!" + downloader.error + "; url = " + info.downURL);
                if (info.completeFun != null)
                {
                    info.completeFun.Invoke(info.downURL, false);
                }
                downloader.Dispose();
                downloader = null;
            }
            else
            {
                ZLog.Warning("download asset bundle success that url = " + info.downURL);
                yield return(null);

                downloader.Abort();
                downloader.Dispose();
                downloader = null;
                Resources.UnloadUnusedAssets();
                yield return(null);

                if (info.completeFun != null)
                {
                    info.completeFun.Invoke(info.downURL, true);
                }
                AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(info.path);
                yield return(request);

                if (request.isDone)
                {
                    AssetBundle bundle = request.assetBundle;
                    ZLog.Warning("read asset bundle success that path = " + info.path);
                    if (bundle != null)
                    {
                        ZBundleManager.Instance.AddBundle(info.path, info.type, bundle);
                    }
                    if (info.completeFun != null)
                    {
                        info.completeFun.Invoke(info.path, true);
                    }
                }
            }
            RemoveLoadInfo(info.path);
            LoadNext();
        }