Example #1
0
 public void ClearOtherModule(string module)
 {
     Dictionary <string, ModuleAssetBundle> .Enumerator e = ModuleAssetBundles.GetEnumerator();
     while (e.MoveNext())
     {
         if (e.Current.Key == module)
         {
             continue;
         }
         if (e.Current.Value.bundles == null)
         {
             continue;
         }
         if (e.Current.Key != module)
         {
             ModuleAssetBundle moduleAssetBundle            = e.Current.Value;
             Dictionary <string, AssetBundle> .Enumerator m = moduleAssetBundle.bundles.GetEnumerator();
             while (m.MoveNext())
             {
                 m.Current.Value.Unload(true);
             }
             moduleAssetBundle.bundles.Clear();
             moduleAssetBundle.bundles = null;
             m.Dispose();
         }
     }
     e.Dispose();
 }
Example #2
0
        private T GetObject <T>(string module, string prefabName, string bundleName, string dir)
            where T : UnityEngine.Object
        {
            if (GameConfig.gameModel == GameModel.Editor)
            {
                return(DeepFind <T>(module, prefabName, dir));
            }
            ModuleAssetBundle moduleAssetBundle = null;

            if (ModuleAssetBundles.TryGetValue(module, out moduleAssetBundle))
            {
                bundleName = bundleName ?? prefabName;
                AssetBundle bundle = null;
                if (moduleAssetBundle.bundles.TryGetValue(bundleName.ToLower(), out bundle))
                {
                    return(bundle.LoadAsset <T>(prefabName));
                }
            }
            return(null);
        }
Example #3
0
        public void InitAssetBundle(string module, Action <float> progress, Action complete)
        {
            if (complete == null)
            {
                complete = () => { }
            }
            ;
            if (GameConfig.gameModel == GameModel.Editor)
            {
                complete();
                return;
            }
            ModuleAssetBundle moduleAssetBundle = null;

            if (ModuleAssetBundles.TryGetValue(module, out moduleAssetBundle))
            {
                if (moduleAssetBundle.bundles != null)
                {
                    complete();
                    return;
                }
            }
            StartCoroutine(Init(module, progress, complete));
        }
Example #4
0
        private IEnumerator Init(string module, Action <float> progress, Action complete)
        {
            string url = string.Format("{0}/{1}", Util.WWWDeviceResPath, GameConfig.module_name); //获得Modules的AssetBundle
            WWW    www = new WWW(url);

            yield return(www);

            if (www.error != null)
            {
                Debug.LogError(www.error);
                yield break;
            }
            AssetBundle         manifestBundle = www.assetBundle;
            AssetBundleManifest manifest       = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");

            manifestBundle.Unload(false); //释放没有使用的资源
            //获取依赖文件列表
            string[]          allBundles        = manifest.GetAllAssetBundles();
            ModuleAssetBundle moduleAssetBundle = new ModuleAssetBundle();

            moduleAssetBundle.bundles = new Dictionary <string, AssetBundle>();
            float count = allBundles.Length;
            float curr  = 0;

            for (int i = 0; i < allBundles.Length; i++)
            {
                curr++;
                if (progress != null)
                {
                    progress(curr / count);
                }
                string bundleName = allBundles[i];
                if (Path.GetDirectoryName(bundleName) != module.Trim().ToLower())
                {
                    continue;
                }
                string bundleUrl = string.Format("{0}/{1}", Util.WWWDeviceResPath, bundleName);
                WWW    bw        = new WWW(bundleUrl);
                yield return(bw);

                yield return(StartCoroutine(FindDependencies(manifest, bundleName,
                                                             (string key) => moduleAssetBundle.bundles.ContainsKey(key),
                                                             (string key, AssetBundle value) => moduleAssetBundle.bundles.Add(key, value))));

                if (bw.error != null)
                {
                    Debug.LogError("请检查  " + module + "  是否已经下载成功?" + bw.error);
                }
                else
                {
                    moduleAssetBundle.bundles.Add(Path.GetFileName(bundleName), bw.assetBundle);
                }
            }

            if (ModuleAssetBundles.ContainsKey(module))
            {
                ModuleAssetBundles[module] = moduleAssetBundle;
            }
            else
            {
                ModuleAssetBundles.Add(module, moduleAssetBundle);
            }
            complete();
        }