Exemplo n.º 1
0
        IEnumerator LoadDepInfo()
        {
            string depFile = string.Format("{0}/{1}", pathResolver.BundleCacheDir, pathResolver.DependFileName);

            //编辑器模式下测试AB_MODE,直接读取
#if UNITY_EDITOR
            depFile = pathResolver.GetBundleSourceFile(pathResolver.DependFileName, false);
#endif

            if (File.Exists(depFile))
            {
                FileStream fs = new FileStream(depFile, FileMode.Open, FileAccess.Read);
                Init(fs, null);
                fs.Close();
            }
            else
            {
                string srcURL = pathResolver.GetBundleSourceFile(pathResolver.DependFileName);
                WWW    w      = new WWW(srcURL);
                yield return(w);

                if (w.error == null)
                {
                    Init(new MemoryStream(w.bytes), null);
                    File.WriteAllBytes(depFile, w.bytes);
                }
                else
                {
                    Debug.LogError(string.Format("{0} not exist!", depFile));
                }
            }
            this.InitComplete();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 其它都准备好了,加载AssetBundle
        /// 注意:这个方法只能被 AssetBundleManager 调用
        /// 由 Manager 统一分配加载时机,防止加载过卡
        /// </summary>
        override public void LoadBundle()
        {
            _assetBundleCachedFile = string.Format("{0}/{1}", AssetBundlePathResolver.BundleCacheDir, bundleName);
            _assetBundleSourceFile = AssetBundlePathResolver.GetBundleSourceFile(bundleName);

            if (File.Exists(_assetBundleCachedFile))
            {
                bundleManager.StartCoroutine(LoadFromCachedFile());
            }
            else
            {
                bundleManager.StartCoroutine(LoadFromPackage());
            }
        }
Exemplo n.º 3
0
        protected override IEnumerator LoadFromPackage()
        {
            //兼容低版本API
#if UNITY_4 || UNITY_4_6 || UNITY_5_1 || UNITY_5_2
            _bundle = AssetBundle.CreateFromFile(_assetBundleSourceFile);
            yield return(null);
#else
            _assetBundleSourceFile = AssetBundlePathResolver.GetBundleSourceFile(bundleName, false);
            AssetBundleCreateRequest req = AssetBundle.LoadFromFileAsync(_assetBundleSourceFile);
            yield return(req);

            _bundle = req.assetBundle;
#endif
            this.Complete();
        }