public bool Initialize()
 {
     _loadingResources   = new JWObjList <string>();
     _unbundledResources = new JWObjList <string>();
     _relatedResources   = new JWObjList <string>();
     _sInstance          = this;
     return(true);
 }
 /// <summary>
 /// 开始加载常驻的 AssetBundle
 /// </summary>
 /// <param name="completeCallBack"></param>
 public void StartResidentBundle(System.Action completeCallBack)
 {
     StartCoroutine(BundleMediator.GetInstance().LoadResidentBundles(delegate()
     {
         if (completeCallBack != null)
         {
             completeCallBack();
         }
     }));
 }
        private void OnLoadBundleCompleted(string filename, bool result)
        {
            _bundleFiles.RemoveAt(0);
            _bundleLoading = false;

            if (result)
            {
                BundleMediator.GetInstance().UnloadBundle(filename, true);
            }
        }
        public void Uninitialize()
        {
            StopAllCoroutines();

            _loadingResources.Clear();
            _loadingResources = null;
            _unbundledResources.Clear();
            _unbundledResources = null;
            _relatedResources.Clear();
            _relatedResources = null;
            _sInstance        = null;
        }
        /// 游戏更新检查后后启动
        public void StartAfterUpdate(Action <bool> allCompletedCallback)
        {
            _allCompletedCallback = allCompletedCallback;
#if USE_PACK_RES
            if (ResService.GetInstance().PackConfig == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : resource initialize failed");
                return;
            }
            //
            _bundleFiles   = BundleMediator.GetInstance().GetPreloadBundles();
            _bundleLoading = false;

            string filename = "main_shaders.ab";
            _shaderBundle = BundleService.GetInstance().GetBundle(filename);
            if (_shaderBundle == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : failed to get shader bundle");
            }

            ResPackInfo pi = ResService.GetInstance().PackConfig.GetPackInfo(filename);
            if (pi == null)
            {
                _shaderFilename = new JWArrayList <string>(0);
            }
            else
            {
                _shaderFilename = new JWArrayList <string>(pi.Resources.Count);
                for (int i = 0; i < pi.Resources.Count; i++)
                {
                    _shaderFilename.Add(pi.Resources[i].Path);
                }
            }
#else
            _bundleFiles    = new JWObjList <string>(0);
            _shaderBundle   = null;
            _shaderFilename = new JWArrayList <string>(0);
#endif

            //真正的开始预加载协成
            StartCoroutine(PreloadCoroutine());
        }
        private bool PreloadCoroutine_Bundle()
        {
            if (_bundleFiles == null)
            {
                return(false);
            }

            if (_bundleFiles.Count == 0)
            {
                return(true);
            }

            if (!_bundleLoading)
            {
                _bundleLoading = true;
                BundleMediator.GetInstance().LoadBundle(_bundleFiles[0], OnLoadBundleCompleted);
            }

            return(false);
        }
        public void Destroy()
        {
            if (_preloader != null)
            {
                _preloader.Uninitialize();
                _preloader.ExtDestroy();
                _preloader = null;
            }

            if (_loader != null)
            {
                _loader.Uninitialize();
                _loader.ExtDestroy();
                _loader = null;
            }
            if (_bundleMediator != null)
            {
                _bundleMediator.Uninitialize();
                _bundleMediator.ExtDestroy();
                _bundleMediator = null;
            }
        }
        public override bool Initialize()
        {
            _root = new GameObject("AssetService").transform;
            _root.gameObject.ExtDontDestroyOnLoad();

            _assetManager = new AssetManager();
            _assetManager.Create(_root);

            //必须先构建
            _bundleMediator = _root.gameObject.AddComponent <BundleMediator>();
            _bundleMediator.Initialize();
            //
            _loader = _root.gameObject.AddComponent <AssetLoader>();
            _loader.Initialize(_assetManager);
            //
            _preloader = _root.gameObject.AddComponent <AssetPreloader>();
            _preloader.Initialize(_loader);

            _tempList  = new JWArrayList <string>();
            _tempList2 = new JWArrayList <string>();

            return(true);
        }
Exemple #9
0
        private IEnumerator AsynchronousLoad_LoadAssetBundle(JWObjList <string> stringList, JWArrayList <AssetData> assetDataList)
        {
            while (true)
            {
                stringList.Clear();
                assetDataList.Clear();
                for (int i = 0; i < _data.Count;)
                {
                    AssetData data = _data[i];
                    if (data.Priority != _loadAssetBundlePriority)
                    {
                        ++i;
                        continue;
                    }

                    _data.RemoveAt(i);

                    if (_assetManager.GetCacheCount(data.Name) >= data.Count)
                    {
                        if (data.Callback != null)
                        {
                            assetDataList.Add(data);
                        }
                        continue;
                    }

                    LoadData loadData;
                    loadData.Data            = data;
                    loadData.LoadBundleState = LoadStateLoading;
                    loadData.Request         = null;

                    bool insert = false;
                    for (int j = _resourceRequesting.Count - 1; j >= 0; --j)
                    {
                        if (_resourceRequesting[j].Data.Priority <= data.Priority)
                        {
                            _resourceRequesting.Insert(j + 1, loadData);
                            insert = true;
                            break;
                        }
                    }

                    if (!insert)
                    {
                        _resourceRequesting.Insert(0, loadData);
                    }

                    stringList.Add(data.Filename);

                    if (_loadAssetBundlePriority >= LoadPriority.Preprocess)
                    {
                        break;
                    }
                }

                yield return(null);

                if (stringList.Count > 0)
                {
#if USE_PACK_RES
                    BundleMediator.GetInstance().LoadBundle(stringList, OnBundleLoadCompleted);
#else
                    OnBundleLoadCompleted(stringList, true);
#endif
                }

                yield return(null);

                for (int i = 0; i < assetDataList.Count; i++)
                {
                    AssetData data = assetDataList[i];
                    if (data.Callback != null)
                    {
                        data.Callback.OnLoadAssetCompleted(data.Name, AssetLoadResult.Success, null);
                        yield return(null);
                    }
                }

                yield return(InstructionEnd);
            }
        }