Example #1
0
        /// <summary>
        /// 加载本地资源包信息
        /// </summary>
        /// <param name="path">指定的路径</param>
        private void LoadLocalBundlesInfoFile(string path)
        {
            //Profiler.BeginSample("Load Bundle (JsonData)");
            string packId = System.IO.Path.GetFileName(AssetUtils.AssetBundlePath);

            EB.Loader.OverridePath(System.IO.Path.GetDirectoryName(AssetUtils.AssetBundlePath) + System.IO.Path.DirectorySeparatorChar);
            EB.Loader.OverridePath(packId, AssetUtils.AssetBundlePath + System.IO.Path.DirectorySeparatorChar);

            if (System.IO.File.Exists(path))
            {
                System.IO.StreamReader sr = new System.IO.StreamReader(path);

                if (sr == null)
                {
                    EB.Debug.LogError("Can not read local bundles info file: {0}", path);
                }
                else
                {
                    //Profiler.BeginSample("Initialize Bundle (JsonData)");
#if UNITY_EDITOR || UNITY_IOS
                    DataContractJsonSerializer deseralizer      = new DataContractJsonSerializer(typeof(List <BundleInfo>));
                    List <BundleInfo>          localBundlesList = (List <BundleInfo>)deseralizer.ReadObject(sr.BaseStream);
#else
                    List <BundleInfo> localBundlesList = LitJson.JsonMapper.ToObject <List <BundleInfo> >(sr.ReadToEnd());
#endif
                    if (localBundlesList != null)
                    {
                        EB.Debug.LogCoreAsset("<color=#00ff00>初始化Bundle资源数据, path : {0}, AssetBundlePath : {1}, localBundlesList.Count : {2}</color>", path, AssetUtils.AssetBundlePath, localBundlesList.Count);
                        for (int i = 0; i < localBundlesList.Count; ++i)
                        {
                            mLocalBundlesDict.Add(localBundlesList[i].BundleName, localBundlesList[i]);

                            BundleInfo bundleInfo            = localBundlesList[i];
                            EB.Assets.AssetBundleInfo bundle = new EB.Assets.AssetBundleInfo();
                            bundle.packId       = packId;
                            bundle.id           = bundleInfo.BundleName.ToLower();
                            bundle.uncompressed = true;
                            bundle.paths        = bundleInfo.Paths.Where(include => !string.IsNullOrEmpty(include)).Select(include => include.Replace("Assets/Resources/", string.Empty).Replace("Assets/", string.Empty).ToLower());
                            bundle.parent       = bundleInfo.Parent;
                            bundle.size         = bundleInfo.Size;
                            bundle.hash         = bundleInfo.Version;
                            EB.Assets.AddAssetBundleInfo(bundle);
                        }
                    }
                    //Profiler.EndSample();

                    localBundlesList.Clear();
                    localBundlesList = null;

                    sr.Close();
                    sr.Dispose();
                    sr = null;
                    System.GC.Collect();
                }
            }
            //Profiler.EndSample();
            mReady = true;
        }
Example #2
0
        /// <summary>
        /// Adds the local bundle info.
        /// If the local bundle info with the same bundle name exists, replace it.
        /// </summary>
        /// <param name="bundleInfo">Bundle info.</param>
        public void AddLocalBundleInfo(BundleInfo bundleInfo)
        {
            mLocalBundlesDict[bundleInfo.BundleName] = bundleInfo;

            // whenever download an assetbundle succeeded, save the bundle local file
            EB.Coroutines.ClearTimeout(mSaveHandle);
            mSaveHandle = EB.Coroutines.SetTimeout(SaveLocalBundlesInfoFile, 3000);

            EB.Assets.AssetBundleInfo bundle = new EB.Assets.AssetBundleInfo();
            bundle.packId       = System.IO.Path.GetFileName(GM.AssetUtils.AssetBundlePath);
            bundle.id           = bundleInfo.BundleName.ToLower();
            bundle.uncompressed = true;
            bundle.paths        = bundleInfo.Paths.Where(include => !string.IsNullOrEmpty(include)).Select(include => include.Replace("Assets/Resources/", string.Empty).Replace("Assets/", string.Empty).ToLower());
            bundle.parent       = bundleInfo.Parent;
            bundle.size         = bundleInfo.Size;
            bundle.hash         = bundleInfo.Version;
            EB.Assets.AddAssetBundleInfo(bundle);
        }