private static void CleanAllSonDir()
        {
            locAppId  = UnityEditorUtility.GetLocAppIdAtSelectDir();
            locU3DApp = ProjectInfoDati.GetActualInstance();
            if (string.IsNullOrEmpty(locAppId))
            {
                UnityEditorUtility.DisplayError("所选择的目录不是一个应用下的有效目录!");
                return;
            }
            var assetbundleEditor = AssetBundleEditorDati.GetActualInstance();

            if (assetbundleEditor == null)
            {
                UnityEditorUtility.DisplayError($"应用{locAppId}没有AssetBundle打包配置!");
                throw new Exception($"应用{locAppId}没有AssetBundle打包配置!");
            }
            foreach (var dir in AllSonDirs)
            {
                if (!dir.StartsWith(locU3DApp.ProjectAssetDatabaseDir))
                // dir.StartsWith(appHelper.StreamingAssetsDir))
                {
                    Debug.LogError($"目标目录不是一个有效的AssetBundle打包目录!");
                    continue;
                }
                assetbundleEditor.CleanBuildSettingAtDir(dir);
            }
            AssetBundleEditorDati.GetSingleDati().Save();
        }
예제 #2
0
        public static void SaveCurrentAppAssetBundleInfo()
        {
            if (string.IsNullOrEmpty(currentAssetBundleInfo.LocAppId))
            {
                UnityEditorUtility.DisplayError("应用Id不能为空!");
                throw new Exception("应用Id不能为空!");
            }

            var projectInfo = ProjectInfoDati.GetActualInstance();
            var localPath   = projectInfo.AssetBundleBuildDir
                              + $"{projectInfo.DevelopProjectName}_AssetToBundleMapInfo.bytes";
            var bytes = SerializeUtility.Serialize(currentAssetBundleInfo);

            IOUtility.WriteAllBytes(localPath, bytes);
            AssetDatabase.Refresh();
            Debug.Log($"应用{currentAssetBundleInfo.LocAppId}的AssetBundle数据已更新!");
        }
        /// <summary>
        /// 设置目标目录的打包类型
        /// </summary>
        /// <param name="buildType"></param>
        private static void SetTargetDirAtildType(AssetBundleBuildType buildType)
        {
            var projectInfo       = ProjectInfoDati.GetActualInstance();
            var assetbundleEditor = AssetBundleEditorDati.GetActualInstance();

            locAppId = projectInfo.DevelopProjectName;

            if (string.IsNullOrEmpty(locAppId))
            {
                UnityEditorUtility.DisplayError("未设置项目名称");
                return;
            }

            //appHelper = locU3DApp.Helper;

            if (assetbundleEditor == null)
            {
                Debug.LogError($"项目的 AssetBundleSetting 实例未创建 !");
                return;
            }

            var dirs = UnityEditorUtility.GetSelectDirs();

            foreach (var dir in dirs)
            {
                if (!dir.StartsWith(projectInfo.ProjectAssetDatabaseDir))
                {
                    Debug.LogError($"目标目录不是一个有效的AssetBundle打包目录!");
                    return;
                }
                assetbundleEditor.SetBuildAtTargetBuildType(dir, buildType);
                if (buildType == AssetBundleBuildType.BuildAtDirTree) // 清理所有子目录的打包配置
                {
                    var sonDirs = IOUtility.GetAllDir(dir, null, true, false);
                    foreach (var sonDir in sonDirs)
                    {
                        assetbundleEditor.CleanBuildSettingAtDir(sonDir);
                    }
                    Debug.Log($"目录{dir}已设置为目录树打包,其所有子目录的打包配置都已被清空!");
                }
            }
            AssetBundleEditorDati.GetSingleDati().Save();
        }
        private static void SetSonDirAtildType(AssetBundleBuildType buildType, List <string> dirs)
        {
            locAppId  = UnityEditorUtility.GetLocAppIdAtSelectDir();
            locU3DApp = ProjectInfoDati.GetActualInstance();
            if (string.IsNullOrEmpty(locAppId))
            {
                UnityEditorUtility.DisplayError("所选择的目录不是一个应用下的有效目录!");
                return;
            }

            foreach (var dir in dirs)
            {
                if (!dir.StartsWith(locU3DApp.ProjectAssetDatabaseDir))
                //&& dir.StartsWith(appHelper.StreamingAssetsDir))
                {
                    Debug.LogError($"目标目录不是一个有效的AssetBundle打包目录!");
                    continue;
                }

                var assetbundleEditor = AssetBundleEditorDati.GetActualInstance();
                if (assetbundleEditor == null)
                {
                    Debug.Log($"应用{locAppId}没有AssetBundle打包配置!");
                    return;
                }

                assetbundleEditor.SetBuildAtTargetBuildType(dir, buildType);
                if (buildType == AssetBundleBuildType.BuildAtDirTree) // 清理所有子目录的打包配置
                {
                    var sonDirs = IOUtility.GetAllDir(dir, null, true, false);
                    foreach (var sonDir in sonDirs)
                    {
                        assetbundleEditor.CleanBuildSettingAtDir(sonDir);
                    }
                    Debug.Log($"目录{dir}已设置为目录树打包,其所有子目录的打包配置都已被清空!");
                }
            }
            AssetBundleEditorDati.GetSingleDati().Save();
        }
        private static void CleanSelectDir()
        {
            var dirs      = UnityEditorUtility.GetSelectDirs();
            var targetApp = UnityEditorUtility.TryGetLocProjectInfoAtDir(dirs.First());

            if (targetApp == null)
            {
                UnityEditorUtility.DisplayError($"第一个目录必须是一个应用的允许打包目录!");
                return;
            }

            var assetbundleEditor = AssetBundleEditorDati.GetActualInstance();

            foreach (var dir in dirs)
            {
                //var dirSetting = appAssetBundleSetting.GetDirSetting(dir);
                //List<String> paths = null;
                //paths = dirSetting?.GetFullPathsAtDirTree();
                //assetbundleEditor.CleanBuildSettingAtDir(dir, paths);
            }
            AssetBundleEditorDati.GetSingleDati().Save();
        }
        private static void SetTargetDirsBundleIdAndSelectBuild(bool isBuild, bool isSaveSetting)
        {
            var selectDir = UnityEditorUtility.GetSelectDir();
            var targetApp = UnityEditorUtility.TryGetLocProjectInfoAtDir(selectDir);

            if (targetApp == null)
            {
                UnityEditorUtility.DisplayError("所选择的目录是一个无效目录,必须是一个应用允许打包的目录!");
                return;
            }

            var dirs = IOUtility.GetAllDir(selectDir);
            var appAssetBundleSetting = AssetBundleEditorDati.GetActualInstance();
            var dirSettings           = new List <AssetBundleBuildSetting>();

            foreach (var dir in dirs)
            {
                var setting = appAssetBundleSetting.GetSetting(dir);
                if (setting == null)
                {
                    continue;
                }

                dirSettings.Add(setting);
            }
            AssetBundleBuilder.currentAssetBundleInfo =
                AssetBundleBuilder.GetAppAssetBundleInfo(targetApp.DevelopProjectName);
            for (int i = 0; i < dirSettings.Count; i++)
            {
                EditorUtility.DisplayProgressBar("设置 AB 包名", $"正在设置 {dirSettings[i].Dir} 文件夹的 AB 包名", i * 1.0f / dirSettings.Count);
                AssetBundleBuilder.SetBundleIdAndSelectIsBuild(dirSettings[i],
                                                               isBuild, true, isSaveSetting);
            }
            EditorUtility.ClearProgressBar();
            AssetBundleBuilder.SaveCurrentAppAssetBundleInfo();

            AssetBundleEditorDati.GetSingleDati().Save();
        }
        private void AddNode()
        {
            if (BuildType != AssetBundleBuildType.BuildAtList)
            {
                UnityEditorUtility.DisplayError("当前目录的打包方式不是BuildAtList,请先修改打包方式!");
                return;
            }

            var fileIds = GetFileIds();

            foreach (var node in BundleNodes)
            {
                foreach (var file in node.FileIds)
                {
                    fileIds.Remove(file);
                }
            }

            AssetBundleBuildBaseNode newBaseNode = null;
            var dirId       = IOUtility.GetLastDir(Dir);
            var newBundleId = dirId + "_" + BundleNodes.Count;

            if (BundleNodes.Find(n => n.BundleId == newBundleId) != null)
            {
                UnityEditorUtility.DisplayError($"目标Bundle名已存在!");
                newBaseNode = new AssetBundleBuildBaseNode();
            }
            else
            {
                newBaseNode = new AssetBundleBuildBaseNode {
                    BundleId = newBundleId
                };
            }

            newBaseNode.AddFiles(fileIds);
            BundleNodes.Add(newBaseNode);
        }
예제 #8
0
        public static ProjectAssetsToBundleMapInfo GetAppAssetBundleInfo(string appId)
        {
            if (string.IsNullOrEmpty(appId))
            {
                UnityEditorUtility.DisplayError("应用Id不能为空!");
                throw new Exception("应用Id不能为空!");
            }

            var projectInfo = ProjectInfoDati.GetActualInstance();
            var localPath   = projectInfo.AssetBundleBuildDir
                              + $"{projectInfo.DevelopProjectName}_AssetToBundleMapInfo.bytes";

            if (File.Exists(localPath))
            {
                var bytes         = File.ReadAllBytes(localPath);
                var appBundleInfo = SerializeUtility.DeSerialize <ProjectAssetsToBundleMapInfo>(bytes);
                return(appBundleInfo);
            }

            var newBundleInfo = new ProjectAssetsToBundleMapInfo();

            newBundleInfo.LocAppId = appId;
            return(newBundleInfo);
        }