Ejemplo n.º 1
0
        // open file stream (file must be listed in manifest)
        private void OpenBundle(UBundle bundle)
        {
            var filename = bundle.name;

            if (LoadBundleFile(bundle, _localPathRoot))
            {
                return;
            }
            if (_streamingAssets != null && _streamingAssets.Contains(bundle.name, bundle.checksum, bundle.size))
            {
                bundle.AddRef();
                JobScheduler.DispatchCoroutine(
                    _streamingAssets.LoadBundle(bundle.name, stream =>
                {
                    if (stream != null)
                    {
                        bundle.Load(stream);
                    }
                    else
                    {
                        PrintLog($"read from streamingassets failed: {bundle.name}");
                        DownloadBundleFile(bundle);
                    }
                    bundle.RemoveRef();
                })
                    );
                return;
            }
            DownloadBundleFile(bundle);
        }
Ejemplo n.º 2
0
        // open file stream (file must be listed in manifest)
        private void OpenBundle(UBundle bundle)
        {
            var filename = bundle.name;

            if (LoadBundleFile(bundle, _localPathRoot))
            {
                return;
            }
            // 无法打开现有文件, 下载新文件
            bundle.AddRef();
            AddDownloadTask(DownloadTask.Create(
                                bundle.name, bundle.checksum, bundle.size, bundle.priority,
                                _urls,
                                _localPathRoot,
                                -1,
                                10,
                                self =>
            {
                _tasks.Remove(self);
                _runningTasks--;
                Schedule();
                if (!LoadBundleFile(bundle, _localPathRoot))
                {
                    bundle.Load(null);
                }
                bundle.RemoveRef();
            }));
        }
Ejemplo n.º 3
0
        private bool LoadBundleFile(UBundle bundle, string localPathRoot)
        {
            var fullPath   = Path.Combine(localPathRoot, bundle.name);
            var fileStream = Utils.Helpers.GetBundleStream(fullPath, bundle.bundleInfo);

            if (fileStream != null)
            {
                bundle.Load(fileStream); // 生命周期转由 UAssetBundleBundle 管理
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
 private void DownloadBundleFile(UBundle bundle)
 {
     // 无法打开现有文件, 下载新文件
     bundle.AddRef();
     AddDownloadTask(DownloadTask.Create(bundle.bundleInfo, _urls, _localPathRoot, -1, 10, self =>
     {
         RemoveDownloadTask(self);
         if (!LoadBundleFile(bundle, _localPathRoot))
         {
             bundle.Load(null);
         }
         bundle.RemoveRef();
     }), true);
 }
Ejemplo n.º 5
0
        private bool LoadBundleFile(UBundle bundle)
        {
            var fullPath   = Path.Combine(_localPathRoot, bundle.name);
            var fileStream = Utils.Helpers.GetBundleStream(fullPath, bundle.bundleInfo);

            if (fileStream != null)
            {
                // Stream 生命周期转由 UAssetBundleBundle 管理
                bundle.Load(Utils.Helpers.GetDecryptStream(fileStream, bundle.bundleInfo, _password));
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        private bool LoadBundleFile(UBundle bundle)
        {
            try
            {
                var fullPath   = Path.Combine(_localPathRoot, bundle.name);
                var fileStream = Utils.Helpers.GetBundleStream(fullPath, bundle.bundleInfo);
                if (fileStream != null)
                {
                    // Stream 生命周期转由 UAssetBundleBundle 管理
                    bundle.Load(Utils.Helpers.GetDecryptStream(fileStream, bundle.bundleInfo, _password));
                    return(true);
                }
            }
            catch (Exception exception)
            {
                Debug.LogErrorFormat("LoadBundleFile({0}) exception\n{1}", bundle.name, exception);
            }

            return(false);
        }