示例#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.");
        }
示例#2
0
        public DLCManifest GetManifestFile()
        {
            DLCManifest reader = null;

            if (DLCConfig.Ins.IsEditorOrConfigMode)
            {
                reader = FileUtil.LoadJson <DLCManifest>(GetManifest());
            }
            else
            {
                var asset = DLCManager.LoadRawAsset <TextAsset>(Const.BN_Config, "DLCManifest", this);
                if (asset != null)
                {
                    reader = JsonUtility.FromJson <DLCManifest>(asset.text);
                }
            }
            return(reader);
        }
示例#3
0
        /// <summary>
        /// 加载Manifest
        /// </summary>
        /// <param name="reader"></param>
        private static void LoadDLCManifest(DLCManifest reader)
        {
            if (reader == null)
            {
                CLog.Error("错误:reader 为 null");
                return;
            }


            foreach (var item in reader.Data)
            {
                string bundle = item.BundleName;
                allBundles.Add(bundle);
                if (!bmap.ContainsKey(bundle))
                {
                    bmap.Add(bundle, new List <int>());
                }

                foreach (var assetPathData in item.AssetFullPaths)
                {
                    //完整路径
                    string fullpath = assetPathData.FullPath;
                    //添加完整路径到资源表
                    allAssets.Add(fullpath);
                    //计算资源路径Index
                    int assetPathIndex = allAssets.Count - 1;
                    //计算资源bunleIndex
                    int bundleNameIndex = allBundles.Count - 1;
                    //添加完整资源路径的Index到映射表中
                    bmap[bundle].Add(assetPathIndex);
                    //添加完整的Bundle名称的Index到映射表中
                    amap[fullpath] = bundleNameIndex;

                    //如果资源有自己的Bundle设定,则添加到映射表中
                    if (!assetPathData.SourceBundleName.IsInvStr())
                    {
                        string bampKey = assetPathData.SourceBundleName + assetPathData.FileName;
                        bamap[bampKey] = new Tuple <int, string>(assetPathIndex, item.DLCName);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// 加载DLC
        /// </summary>
        /// <param name="config"></param>
        public static bool LoadDLC(string name)
        {
            //屏蔽NoBundle下得目录
            if (name == BaseConstMgr.Dir_NoBundles)
            {
                return(false);
            }
            if (DLCItems.ContainsKey(name))
            {
                CLog.Error("重复加载!!!!");
                return(false);
            }
            //DLC名称
            string dlcName = name;
            //AB清单
            AssetBundleManifest abManifest = null;
            //加载dlc item
            DLCItem dlcItem = BaseFileUtils.LoadJson <DLCItem>(GetDLCItemPath(dlcName));
            //加载自定义Manifest
            DLCManifest dlcManifest = BaseFileUtils.LoadJson <DLCManifest>(GetDLCManifestPath(dlcName));

            //bundle模式
            if (!DLCConfig.Ins.IsEditorMode)
            {
                //加载Unity Assetbundle Manifest
                Bundle tempBundle = LoadBundle(dlcName, dlcName, false);
                abManifest = tempBundle.LoadAsset <AssetBundleManifest>(BaseConstMgr.STR_ABManifest);
                //如果是Native DLC 直接加载共享Shader和Shared包
                if (dlcItem.IsNative)
                {
                    LoadBundle(BaseConstMgr.BN_Shared, dlcName);
                    LoadBundle(BaseConstMgr.BN_Shader, dlcName);
                }
            }
            DLCItems.Add(dlcItem.Name, dlcItem);
            dlcItem.Load(abManifest);
            LoadDLCManifest(dlcManifest);
            return(true);
        }
示例#5
0
        /// <summary>
        /// 加载DLC
        /// </summary>
        /// <param name="config"></param>
        public static bool LoadDLC(DLCItemConfig config)
        {
            if (LoadedDLCItems.ContainsKey(config.Name))
            {
                CLog.Error("重复加载!!!!");
                return(false);
            }

            //DLC名称
            string dlcName = config.Name;
            //AB清单
            AssetBundleManifest abManifest = LoadAssetBundleManifest(dlcName);
            //if (!DLCConfig.Ins.IsEditorMode)
            //{
            //加载Shared包
            //if(DLCConfig.IsInitLoadSharedBundle)
            //    LoadAllSharedBundle(dlcName);
            //}
            DLCItem item = new DLCItem(config, abManifest);

            //加载自定义Manifest
            LoadManifest(item);
            LoadedDLCItems.Add(dlcName, item);
            CLog.Info("[DLC] Load dlc:{0} succeed", dlcName);
            return(true);

            void LoadManifest(DLCItem dlc)
            {
                DLCManifest reader = dlc.GetManifestFile();

                if (reader == null)
                {
                    CLog.Error("错误:reader 为 null");
                    return;
                }


                foreach (var bundleDataItem in reader.Data)
                {
                    string bundle = bundleDataItem.BundleName;
                    allBundles.Add(bundle);
                    if (!bmap.ContainsKey(bundle))
                    {
                        bmap.Add(bundle, new List <int>());
                    }
                    if (bundleDataItem.IsShared)
                    {
                        if (!allSharedBundles.ContainsKey(dlc.Name))
                        {
                            allSharedBundles.Add(dlc.Name, new List <string>());
                        }
                        allSharedBundles[dlc.Name].Add(bundle);
                    }

                    foreach (var assetPathData in bundleDataItem.AssetFullPaths)
                    {
                        //完整路径
                        string fullpath = assetPathData.FullPath;
                        //添加完整路径到资源表
                        allAssets.Add(fullpath);
                        //计算资源路径Index
                        int assetPathIndex = allAssets.Count - 1;
                        //计算资源bunleIndex
                        int bundleNameIndex = allBundles.Count - 1;
                        //添加完整资源路径的Index到映射表中
                        bmap[bundle].Add(assetPathIndex);
                        //添加完整的Bundle名称的Index到映射表中
                        amap[fullpath] = bundleNameIndex;
                        //如果资源有自己的Bundle设定,则添加到映射表中
                        if (!assetPathData.SourceBundleName.IsInv())
                        {
                            string bampKey = assetPathData.SourceBundleName + assetPathData.FileName;
                            bamap[bampKey] = new Tuple <int, string>(assetPathIndex, bundleDataItem.DLCName);
                            allBundlesAssetsMap.Add(bampKey);
                        }
                    }
                }
            }
        }
示例#6
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);
        }