コード例 #1
0
        /// <summary>
        /// 加载BundleInfo文件
        /// </summary>
        private void LoadProtoBundleInfos()
        {
            ProtoBundleInfos bundleInfos       = null;
            ProtoBundleInfos serverBundleInfos = null;

            if (UseLocalBundle)
            {
                string url = string.Format(@"{0}/{1}", StreamingAssetsPathPreDir, UtilConstVal.ProtoBundleInfoRelativePath);
                bundleInfos       = ProtoBundleInfos.Parser.ParseFrom(ReadAllBytes(url));
                serverBundleInfos = ProtoBundleInfos.Parser.ParseFrom(ReadAllBytes(url));
            }
            else
            {
                byte[] btsData = null;
                string url     = string.Format(@"{0}/{1}", PersistentPathPreDir, UtilConstVal.ProtoBundleInfoRelativePath);
                btsData     = ReadAllBytes(url);
                bundleInfos = ProtoBundleInfos.Parser.ParseFrom(btsData);
                //从服务器获取最新的ProtoBundleInfos
                DownloadBytes(string.Format(@"{0}/{1}/{2}", PlatformDir, Version, UtilConstVal.ProtoBundleInfoRelativePath), out btsData);
                serverBundleInfos = ProtoBundleInfos.Parser.ParseFrom(btsData);
            }

            if (bundleInfos == null)
            {
                Debug.Log("Cannot load BundleInfos");
            }
            else
            {
                var infoList = bundleInfos.BundleInfos;
                Debug.Log("local");
                foreach (var item in infoList)
                {
                    mBundleInfoMap.Add(item.AssetPath, item);
                    //Debug.Log(item.Bundlename);
                }
                Debug.Log("server");
                infoList = serverBundleInfos.BundleInfos;
                foreach (var item in infoList)
                {
                    //Debug.Log(item.Bundlename);
                    mServerBundleInfoMap.Add(item.AssetPath, item);
                }
            }
        }
コード例 #2
0
    /// <summary>
    /// 创建AssetBundle索引文件,使用protobuf序列化
    /// </summary>
    public static void BuildBundleInfoProtoFile(string outputPath)
    {
        //TODO
        outputPath = outputPath + "/ProtoBundleInfos.dat";
        ProtoBundleInfos protoBundleInfos = new ProtoBundleInfos();

        foreach (var pair in bundleDataMap)
        {
            BundleDataInfo info = pair.Value;
            protoBundleInfos.BundleInfos.Add(new ProtoBundleInfo {
                BundlePath = info.bundlePath,
                AssetPath  = info.assetPath,
                Version    = version,
            });
        }
        //Create File
        using (var output = File.Create(outputPath))
        {
            protoBundleInfos.WriteTo(output);
        }
    }