Пример #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);
        }
Пример #2
0
 private void OnAssetCompleted(UAsset asset)
 {
     if (_state == SceneState.Loading && asset.isLoaded)
     {
         JobScheduler.DispatchCoroutine(_LoadAsync());
     }
 }
Пример #3
0
 public void Close()
 {
     if (!_closed)
     {
         _closed = true;
         JobScheduler.DispatchCoroutine(_OnClosing());
     }
 }
Пример #4
0
        protected void _LoadAsset(IEnumerator e)
        {
            if (_closed)
            {
                return;
            }

            _assetLoaders.AddLast(e);
            if (_assetLoaders.Count == 1)
            {
                JobScheduler.DispatchCoroutine(_AssetLoader());
            }
        }
Пример #5
0
        protected void _LoadBundle(IEnumerator e)
        {
            if (_closed)
            {
                return;
            }

            _bundleLoaders.AddLast(e);
            if (_bundleLoaders.Count == 1)
            {
                JobScheduler.DispatchCoroutine(_BundleLoader());
            }
        }
Пример #6
0
        // 下载包文件 (优先考虑从 StreamingAssets 载入, 无法载入时从网络下载)
        //NOTE: 调用此接口时已经确认本地包文件无效 (本地临时存储)
        private void DownloadBundleFile(Manifest.BundleInfo bundleInfo, Action callback)
        {
            var oldJob = _FindDownloadJob(bundleInfo.name);

            if (oldJob != null)
            {
                if (callback != null)
                {
                    oldJob.callback += callback;
                }

                return;
            }

            if (_streamingAssets.Contains(bundleInfo))
            {
                JobScheduler.DispatchCoroutine(
                    _streamingAssets.LoadStream(bundleInfo, stream =>
                {
                    if (stream != null)
                    {
                        var bundle = TryGetBundle(bundleInfo);
                        if (bundle != null)
                        {
                            bundle.Load(Utils.Helpers.GetDecryptStream(stream, bundle.bundleInfo, _password,
                                                                       _manifestObject.chunkSize));
                        }
                        else
                        {
                            stream.Close();
                        }

                        callback?.Invoke();
                    }
                    else
                    {
                        Debug.LogWarningFormat("read from streamingassets failed: {0}", bundleInfo.name);
                        _DownloadBundleFile(bundleInfo, callback, true);
                    }
                })
                    );
            }
            else
            {
                _DownloadBundleFile(bundleInfo, callback, true);
            }
        }
Пример #7
0
 public void UnloadScene()
 {
     if (_state != SceneState.Ready)
     {
         if (_state == SceneState.Loaded)
         {
             _state = SceneState.Unloading;
             JobScheduler.DispatchCoroutine(_UnloadAsync());
         }
         else
         {
             if (_asset.isLoaded)
             {
                 _state = SceneState.Unloading;
             }
             else
             {
                 _state = SceneState.Ready;
             }
         }
     }
 }
Пример #8
0
 public void OpenManifest(Action <StreamingAssetsLoader> callback)
 {
     JobScheduler.DispatchCoroutine(OpenManifestCo(callback));
 }