コード例 #1
0
        IEnumerator DownLoadAssetBundle(string url, string dstpath)
        {
            _cacherequest = UnityWebRequest.Get(url);

            yield return(_cacherequest.Send());

            if (!string.IsNullOrEmpty(_cacherequest.error))
            {
                Debug.LogError(_cacherequest.error);
            }
            else if (_cacherequest.responseCode != 200)
            {
                Debug.LogErrorFormat("Error :{0} Info: {1}", _cacherequest.url, _cacherequest.downloadHandler.text);
            }
            else
            {
                var dirname = Path.GetDirectoryName(dstpath);
                if (Directory.Exists(dirname) == false)
                {
                    Directory.CreateDirectory(dirname);
                }

                File.WriteAllBytes(dstpath, _cacherequest.downloadHandler.data);

                if (AssetBundleConfig.IsDetail())
                {
                    Debug.LogFormat("DownLoad Finish:{0}", _cacherequest.url);
                }
            }

            IsDone = true;
        }
コード例 #2
0
        public void DownLoad(ref AssetDownloadInfo downloadInfo)
        {
            if (!downloadInfo.IsDone)
            {
                if (!downloadInfo.IsDownloading)
                {
                    if (AssetBundleConfig.IsDetail())
                    {
                        Debug.LogFormat("Start DownLoad :{0}", downloadInfo.Url);
                    }

                    GUpdater.mIns.StartCoroutine(DownLoadAssetBundle(downloadInfo.Url, downloadInfo.DstPath));
                    downloadInfo.IsDownloading = true;
                }
            }

            if (_cacherequest != null)
            {
                downloadInfo.IsDone   = _cacherequest.isDone;
                downloadInfo.Progress = _cacherequest.downloadProgress;

                if (_cacherequest.isDone)
                {
                    downloadInfo.HasError      = !string.IsNullOrEmpty(_cacherequest.error) || _cacherequest.responseCode != 0;
                    downloadInfo.IsDownloading = false;
                    _cacherequest.Dispose();
                    _cacherequest = null;
                }
            }
        }
コード例 #3
0
 protected override void AddAssetSystems()
 {
     if (AssetBundleConfig.IsSimulator())
     {
         foreach (var systype in AssetBundleConfig.SimulatorLoadSystems)
         {
             IAssetBundleSystem sys = System.Activator.CreateInstance(systype) as IAssetBundleSystem;
             if (sys != null)
             {
                 Systems.Add(sys);
             }
         }
     }
     else
     {
         foreach (var systype in AssetBundleConfig.LoadSystems)
         {
             IAssetBundleSystem sys = System.Activator.CreateInstance(systype) as IAssetBundleSystem;
             if (sys != null)
             {
                 Systems.Add(sys);
             }
         }
     }
 }
コード例 #4
0
 public int Execute(ref AssetBundleContext context, AssetEvent assetEvent)
 {
     if (assetEvent == AssetEvent.Update && AssetBundleConfig.IsProfiler())
     {
         if (context.ProfilerData.IsProfilering)
         {
             CaptureFrame(ref context);
         }
     }
     return(0);
 }
コード例 #5
0
        public bool IsDone(ref AssetBundleContext context, out GameAssetBundle assetBundle)
        {
            if (context.Cache.GetAssetBundle(AssetBundleName, out assetBundle))
            {
                //异步请求还未完成
                if (assetBundle.LoadRequest != null || assetBundle.LoadAssetRequest != null ||
                    assetBundle.SceneRequest != null || assetBundle.UnloadSceneRequest != null)
                {
                    return(false);
                }

                if (AssetBundleConfig.IsSimulator())
                {
                    return(true);
                }

                ///被预加载pin住的
                if (IsPreLoad() && PinTime > 0)
                {
                    if (FinishTime > CreateTime)
                    {
                        return(Time.realtimeSinceStartup - FinishTime > PinTime);
                    }
                    return(false);
                }
                //正在下载的
                if (AssetBundleFunction.InDowloading(ref context, ref this))
                {
                    return(false);
                }
                //加载异常
                if (AssetBundleConfig.SafeMode && assetBundle.IsException())
                {
                    return(true);
                }
                else if (assetBundle.AssetStatus.HasEnum(AssetBundleStatus.InMemory))  //加载正常
                {
                    int finish;
                    int total;
                    return(IsSubAllDone(ref context, out finish, out total));
                }
                //else if(assetBundle.AssetStatus == AssetBundleStatus.None)//啥事也没干的task
                //{
                //    return true;
                //}
            }
            else
            {
                return(true);
            }
            return(false);
        }
コード例 #6
0
        protected virtual void Load(ref AssetBundleContext context, ref AssetBundleTask task,
                                    ref GameAssetBundle gameAssetBundle, ref bool retcode, bool mainloadrequest = false)
        {
            if (gameAssetBundle.IsException())
            {
                return;
            }

            if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
            {
                Debug.LogFormat("Load --- {0}", task);
            }

            gameAssetBundle.AssetStatus |= AssetBundleStatus.Loading;
            //not loaded
            if (gameAssetBundle.AssetBundle == null && gameAssetBundle.LoadRequest == null && gameAssetBundle.LoadAssetRequest == null)
            {
                if (IsEnableLoadAssetBunlde(ref context, ref task, ref gameAssetBundle))
                {
                    string assetfilename = AssetBundleConfig.Convert(task.AssetBundleName);
                    string path          = AssetBundleHelper.GetBundlePersistentPath(assetfilename);
                    bool   fileExist     = File.Exists(path);

                    string url;
                    bool   indownloadcache = context.Cache.TryGetDownloadUrl(new IgnoreCaseString(task.AssetBundleName), out url);
                    bool   canload         = false;
                    if (indownloadcache && !fileExist)
                    {
                        AssetDownloadInfo downloadInfo = new AssetDownloadInfo();
                        downloadInfo.AssetPath       = task.AssetPath;
                        downloadInfo.AssetBundleName = task.AssetBundleName;
                        if (!context.DownLoadQueue.Contains(downloadInfo))
                        {
                            downloadInfo.DstPath = path;
                            downloadInfo.Url     = url;
                            downloadInfo.TaskId  = task.TaskId;
                            context.DownLoadQueue.Add(downloadInfo);
                        }
                    }
                    else if (fileExist)
                    {
                        canload = true;
                    }
                    else if (!fileExist)
                    {
                        string streampath = AssetBundleHelper.GetBundleStreamPath(assetfilename);
                        if (File.Exists(streampath))
                        {
                            canload = true;
                            path    = streampath;
                        }
                    }

                    if (canload)
                    {
                        if (task.IsAsync())
                        {
                            gameAssetBundle.LoadRequest = AssetBundle.LoadFromFileAsync(path);
                            if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                            {
                                Debug.LogFormat("LoadFromFileAsync AssetBundle :{0} ", task.AssetBundleName);
                            }
                        }
                        else
                        {
                            gameAssetBundle.AssetBundle = AssetBundle.LoadFromFile(path);
                            if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                            {
                                Debug.LogFormat("LoadFromFile AssetBundle :{0} ", task.AssetBundleName);
                            }

                            AfterLoadAssetBundle(ref context, ref task, ref gameAssetBundle, ref retcode, ref mainloadrequest);
                        }
                    }
                    else if (!indownloadcache)
                    {
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.FileNotExist;
                        AddException(ref context, task.AssetPath);
                        Debug.LogError(string.Format("cant load :{0}", task));
                    }
                }
            }
            else if (gameAssetBundle.LoadRequest != null)// in asyncing Load AssetBundle
            {
                if (gameAssetBundle.LoadRequest.isDone)
                {
                    if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                    {
                        Debug.LogFormat("Async Task for Load AssetBundle is Done :{0} ", task);
                    }
                    gameAssetBundle.AssetBundle = gameAssetBundle.LoadRequest.assetBundle;

                    AfterLoadAssetBundle(ref context, ref task, ref gameAssetBundle, ref retcode, ref mainloadrequest);
                    gameAssetBundle.LoadRequest = null;
                }
            }
            else if (gameAssetBundle.LoadAssetRequest != null && mainloadrequest)// Load Asset
            {
                if (gameAssetBundle.LoadAssetRequest.isDone)
                {
                    var loadfinishasset = gameAssetBundle.LoadAssetRequest.asset;

                    if (loadfinishasset != null)
                    {
                        if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail))
                        {
                            Debug.LogFormat("Async Task Add Asset :{0} ", task);
                        }
                        gameAssetBundle.AddAsset(task.AssetPath, gameAssetBundle.LoadAssetRequest.asset);
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.InMemory;
                        if (task.Result.ProgresCallback != null)
                        {
                            ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true);
                            task.Result.ProgresCallback(ref progressArgs);
                        }
                        task.FinishTime = Time.realtimeSinceStartup;
                        retcode         = true;
                    }
                    else
                    {
                        Debug.LogErrorFormat("{0} has 0 Assets", gameAssetBundle.AssetBundle);
                        gameAssetBundle.AssetStatus |= AssetBundleStatus.NotInMemory;
                    }

                    gameAssetBundle.LoadAssetRequest = null;
                }
            }
            else
            {
                if (mainloadrequest)
                {
                    LoadMainAsset(ref context, ref task, ref gameAssetBundle, ref retcode);
                }
            }
        }