Пример #1
0
 public static void BuildDLCConfig(DLCItem dlc)
 {
     //清除缓存
     PackedAssets_Internal.Clear();
     PackedAssets_Native.Clear();
     PackedAssets_DLC.Clear();
     Builds.Clear();
     Rules.Clear();
     AllDependencies.Clear();
     AllAssets.Clear();
     AllBundles.Clear();
     AllSharedBundles.Clear();
     Consts.Clear();
     //永远提前打包Internal
     if (!dlc.IsInternal)
     {
         BuildDLCConfigInternal(Internal);
     }
     //如果不是NativeDLC则先BuildNativeDLC,防止资源被其他DLC重复打包
     if (!dlc.IsInternal && !dlc.IsNative)
     {
         BuildDLCConfigInternal(Native);
     }
     BuildDLCConfigInternal(dlc);
 }
Пример #2
0
        /// <summary>
        /// 活的构建的数据
        /// </summary>
        /// <param name="manifestPath"></param>
        /// <returns></returns>
        private static List <AssetBundleBuild> GenerateAssetBundleBuildData(DLCItem dlc)
        {
            if (dlc.IsInternal)
            {
                PackedAssets_Internal.Clear();
            }
            else if (dlc.IsNative)
            {
                PackedAssets_Native.Clear();
            }
            PackedAssets_DLC.Clear();
            Builds.Clear();
            Rules.Clear();
            AllDependencies.Clear();
            AllAssets.Clear();
            AllBundles.Clear();
            AllSharedBundles.Clear();

            //建立其他文件
            List <BuildRuleConfig> tempBuildDatas = dlc.BuildRuleData;

            if (tempBuildDatas == null && tempBuildDatas.Count == 0)
            {
                CLog.Error("没有配置相关的AssetBundle信息");
                return(null);
            }

            foreach (var item in tempBuildDatas)
            {
                BuildRule buildRule = null;
                if (item.BuildRuleType == BuildRuleType.Directroy)
                {
                    buildRule = new BuildAssetsWithDirectroy(dlc, item);
                }
                else if (item.BuildRuleType == BuildRuleType.FullPath)
                {
                    buildRule = new BuildAssetsWithPath(dlc, item);
                }
                else if (item.BuildRuleType == BuildRuleType.File)
                {
                    buildRule = new BuildAssetsWithFile(dlc, item);
                }
                Rules.Add(buildRule);
            }

            //搜集依赖的资源
            foreach (var item in Rules)
            {
                CollectDependencies(item.Config.FullSearchPath);
            }
            //打包共享的资源
            BuildSharedAssets(dlc);

            foreach (var item in Rules)
            {
                item.Build();
            }
            EditorUtility.ClearProgressBar();
            return(Builds);
        }
Пример #3
0
 private static void AddToAllBundles(Tuple <string, string> bundleName, bool isShared = false)
 {
     if (!AllBundles.ContainsKey(bundleName.Item1))
     {
         AllBundles.Add(bundleName.Item1, bundleName.Item2);
     }
     if (isShared)
     {
         if (!AllSharedBundles.Contains(bundleName.Item1))
         {
             AllSharedBundles.Add(bundleName.Item1);
         }
     }
 }
Пример #4
0
        static void BuildDLCConfigInternal(DLCItem dlcItem)
        {
            var    builds       = AssetBundleBuildsCache = GenerateAssetBundleBuildData(dlcItem);
            string constPath    = dlcItem.GetConst();
            string manifestPath = dlcItem.GetManifest();
            string dlcItemPath  = dlcItem.GetConfig();

            List <string> bundles = new List <string>();
            List <string> assets  = new List <string>();

            if (builds.Count > 0)
            {
                foreach (var item in builds)
                {
                    bundles.Add(item.assetBundleName);
                    foreach (var assetPath in item.assetNames)
                    {
                        assets.Add(assetPath + ":" + (bundles.Count - 1));
                    }
                }
            }

            #region 创建Manifest文件
            if (File.Exists(manifestPath))
            {
                File.Delete(manifestPath);
            }
            DLCManifest dlcManifest = new DLCManifest();
            foreach (var item in builds)
            {
                BundleData tempData = new BundleData();
                tempData.DLCName = dlcItem.Name;
                if (AllBundles.ContainsKey(item.assetBundleName))
                {
                    tempData.BundleName = item.assetBundleName;
                    if (AllSharedBundles.Contains(item.assetBundleName))
                    {
                        tempData.IsShared = true;
                    }
                }
                else
                {
                    CLog.Error("没有包含:" + item.assetBundleName);
                }
                foreach (var asset in item.assetNames)
                {
                    AssetPathData pathData = new AssetPathData();
                    pathData.FullPath = asset;
                    pathData.FileName = Path.GetFileNameWithoutExtension(asset);
                    if (AllAssets.ContainsKey(asset))
                    {
                        pathData.SourceBundleName = AllAssets[asset];
                    }
                    tempData.AssetFullPaths.Add(pathData);
                }
                dlcManifest.Data.Add(tempData);
            }
            FileUtil.SaveJson(manifestPath, dlcManifest, true);
            #endregion

            #region dlcitem
            if (File.Exists(dlcItemPath))
            {
                File.Delete(dlcItemPath);
            }
            FileUtil.SaveJson(dlcItemPath, dlcItem.Config, true);
            #endregion

            #region const
            if (File.Exists(constPath))
            {
                File.Delete(constPath);
            }
            var cultureInfo = new System.Globalization.CultureInfo("en-us");
            var w           = new CodegenTextWriter(constPath, System.Text.Encoding.UTF8);
            w.WithCurlyBraces("namespace CYM", () =>
            {
                w.WithCurlyBraces("public partial class Const", () =>
                {
                    foreach (var bundleData in dlcManifest.Data)
                    {
                        string newBundleName = "";
                        foreach (var pathData in bundleData.AssetFullPaths)
                        {
                            if (pathData.SourceBundleName.IsInv())
                            {
                                continue;
                            }
                            //跳过指定的Bundle资源
                            if (pathData.SourceBundleName == Const.BN_System ||
                                pathData.SourceBundleName == Const.BN_Shared)
                            {
                                continue;
                            }
                            //获得相应的Bundle名称
                            if (pathData.SourceBundleName.StartsWith(Const.BN_Scene))
                            {
                                newBundleName = Const.BN_Scene;
                            }
                            else
                            {
                                newBundleName = pathData.SourceBundleName;
                            }
                            //保证变量名称有效
                            var fileName = pathData.FileName.Replace(".", "_").Replace("(", "_").Replace(")", "").Trim();
                            //加上前缀
                            fileName = newBundleName.ToUpper() + "_" + fileName;
                            //忽略不需要的Const
                            if (DLCConfig.IsInIgnoreConst(fileName))
                            {
                                continue;
                            }
                            if (Consts.Contains(fileName))
                            {
                                continue;
                            }
                            Consts.Add(fileName);
                            w.WriteLine($"public const string {fileName} = \"{pathData.FileName}\";");
                        }
                    }
                });
            });
            w.Flush();
            w.Dispose();
            #endregion

            CLog.Info("[Builder][{0}] BuildManifest with " + assets.Count + " assets and " + bundles.Count + " bundels.", dlcItem.Name);
        }