Exemplo n.º 1
0
        static void CopyDLCToEXE(DLCItem item)
        {
            string sourcePath = Path.Combine(BaseConstMgr.Path_StreamingAssets, item.Name);
            string targetPath = Path.Combine(BuildConfig.DirPath, BuildConfig.FullName + "_Data/StreamingAssets", item.Name);

            BaseFileUtils.CopyDir(sourcePath, targetPath);
        }
Exemplo n.º 2
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.");
        }
Exemplo n.º 3
0
 private static void _BuildBundle(DLCItem dlcItem)
 {
     BaseFileUtils.EnsureDirectory(dlcItem.TargetPath);
     BuildManifest(dlcItem);
     BuildPipeline.BuildAssetBundles(dlcItem.TargetPath,
                                     AssetBundleBuildsCache.ToArray(),
                                     BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.ForceRebuildAssetBundle,
                                     EditorUserBuildSettings.activeBuildTarget);
     dlcItem.CopyAllFiles();
     AssetDatabase.Refresh();
 }
Exemplo n.º 4
0
 //拷贝非打包资源到指定目录
 public void CopyAllFiles()
 {
     for (int i = 0; i < AbsCopyDirectory.Count; ++i)
     {
         string absPath         = AbsCopyDirectory[i];
         string dir             = CopyDirectory[i];
         string finalTargetPath = Path.Combine(TargetPath, dir);
         BaseFileUtils.CopyDir(absPath, finalTargetPath, false, true);
     }
     //如果是默认DLC,拷贝指定的内部资源
     if (IsNative)
     {
         BaseFileUtils.CopyDir(BaseConstMgr.Path_InternalLanguage, Path.Combine(TargetPath, "Language"), false, false);
         BaseFileUtils.CopyDir(BaseConstMgr.Path_InternalLua, Path.Combine(TargetPath, "Lua"), false, false);
     }
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public string[] GetAllLuas()
        {
            List <string> fileList = new List <string>();

            //编辑器模式下获得内部Lua脚本,非编辑器模式下直接从StreamingAssets里面获取
            if (DLCConfig.IsEditorMode && IsNative)
            {
                var temp = BaseFileUtils.GetFiles(BaseConstMgr.Path_InternalLua, "*.txt", SearchOption.AllDirectories);
                if (temp != null)
                {
                    fileList.AddRange(temp);
                }
            }
            {
                var temp = BaseFileUtils.GetFiles(LuaPath, "*.txt", SearchOption.AllDirectories);
                if (temp != null)
                {
                    fileList.AddRange(temp);
                }
            }
            return(fileList.ToArray());
        }
Exemplo n.º 7
0
        /// <summary>
        /// 导出的初始化
        /// </summary>
        void Init()
        {
            //计算DLC的跟目录
            RootPath = DLCAssetMgr.GetDLCRootPath(Name);
            //计算出绝对路径(拷贝文件使用)
            AbsRootPath = Path.Combine(BaseConstMgr.Path_Project, RootPath.Replace("Assets/", ""));
            //计算出目标路径
            TargetPath = Path.Combine(BaseConstMgr.Path_StreamingAssets, Name);

            //计算语言包路径
            if (DLCConfig.IsEditorMode)
            {
                LanguagePath = Path.Combine(RootPath, BaseConstMgr.Dir_Language);
            }
            else
            {
                LanguagePath = Path.Combine(TargetPath, BaseConstMgr.Dir_Language);
            }
            //计算lua路径
            if (DLCConfig.IsEditorMode)
            {
                LuaPath = Path.Combine(RootPath, BaseConstMgr.Dir_Lua);
            }
            else
            {
                LuaPath = Path.Combine(TargetPath, BaseConstMgr.Dir_Lua);
            }

            #region func
            EnsureDirectories();
            GenerateCopyPath();
            GeneralPath();
            //确保DLC相关路径存在
            void EnsureDirectories()
            {
                if (DLCConfig.IsEditorMode)
                {
                    BaseFileUtils.EnsureDirectory(AbsRootPath);
                    foreach (var item in Data)
                    {
                        BaseFileUtils.EnsureDirectory(Path.Combine(AbsRootPath, item.SearchPath));
                    }
                    foreach (var item in CopyDirectory)
                    {
                        BaseFileUtils.EnsureDirectory(Path.Combine(AbsRootPath, item));
                    }
                }
            }

            //建立拷贝路径
            void GenerateCopyPath()
            {
                AbsCopyDirectory.Clear();
                if (CopyDirectory != null)
                {
                    for (int i = 0; i < CopyDirectory.Count; ++i)
                    {
                        AbsCopyDirectory.Add(Path.Combine(AbsRootPath, CopyDirectory[i]));
                    }
                }
            }

            //建立打包路径
            void GeneralPath()
            {
                foreach (var item in Data)
                {
                    var vals  = item.SearchPath.Replace('\\', '/');
                    var temps = vals.Split('/');
                    if (temps == null || temps.Length == 0)
                    {
                        CLog.Error("路径错误:{0}", item.SearchPath);
                    }
                    item.FinalDirectory = temps[temps.Length - 1];
                    if (item.FinalDirectory == null)
                    {
                        CLog.Error("错误");
                    }

                    string tempRootPath = RootPath;
                    if (!item.CustomRootPath.IsInvStr())
                    {
                        tempRootPath = item.CustomRootPath;
                    }
                    item.FullSearchPath = tempRootPath + "/" + item.SearchPath;
                }
            }

            #endregion
        }