Ejemplo n.º 1
0
        static void BuildManifestInternel(DLCItem dlcItem)
        {
            var    builds       = AssetBundleBuildsCache = BuildBuildRules(dlcItem);
            string dlcName      = dlcItem.Name;
            string manifestPath = DLCAssetMgr.GetDLCManifestPath(dlcName);
            string dlcItemPath  = DLCAssetMgr.GetDLCItemPath(dlcName);

            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;
                tempData.BundleName = 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);
            }
            BaseFileUtils.SaveJson(manifestPath, dlcManifest, true);
            #endregion

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

            CLog.Debug("[BuildScript] BuildManifest with " + assets.Count + " assets and " + bundles.Count + " bundels.");
        }
Ejemplo n.º 2
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);
        }