Пример #1
0
        /// <summary>
        /// 通过资源获取打包选项
        /// </summary>
        /// <param name="assetUrl">资源路径</param>
        /// <returns>打包选项</returns>
        public BuildItem GetBuildItem(string assetUrl)
        {
            for (int i = 0; i < items.Count; ++i)
            {
                BuildItem item = items[i];
                //前面是否匹配
                if (assetUrl.StartsWith(item.assetPath, StringComparison.InvariantCulture))
                {
                    return(item);
                }
            }

            return(null);
        }
Пример #2
0
        public void AddSuffix(string suffix)
        {
            if (suffixList.Contains(suffix))
            {
                Debug.LogError("重复后缀");
                return;
            }

            for (int i = 0; i < items.Count; i++)
            {
                BuildItem item = items[i];
            }

            suffixList.Add(suffix);
            Save();
        }
Пример #3
0
        /// <summary>
        /// 通过资源获取打包选项
        /// </summary>
        /// <param name="assetUrl">资源路径</param>
        /// <returns>打包选项</returns>
        public BuildItem GetBuildItem(string assetUrl)
        {
            BuildItem item = null;

            for (int i = 0; i < items.Count; ++i)
            {
                BuildItem tempItem = items[i];
                //前面是否匹配
                if (assetUrl.StartsWith(tempItem.assetPath, StringComparison.InvariantCulture))
                {
                    //找到优先级最高的Rule,路径越长说明优先级越高
                    if (item == null || item.assetPath.Length < tempItem.assetPath.Length)
                    {
                        item = tempItem;
                    }
                }
            }

            return(item);
        }
Пример #4
0
        /// <summary>
        /// 获取所有在打包设置的文件列表
        /// </summary>
        /// <returns>文件列表</returns>
        public HashSet <string> Collect()
        {
            EditorUtility.DisplayProgressBar($"{nameof(Collect)}", "搜集打包设置资源", 0);

            HashSet <string> files = new HashSet <string>();

            for (int i = 0; i < items.Count; i++)
            {
                BuildItem     buildItem = items[i];
                List <string> tempFiles = Builder.GetFiles(buildItem.assetPath, null, buildItem.suffixes.ToArray());
                for (int ii = 0; ii < tempFiles.Count; ii++)
                {
                    files.Add(tempFiles[ii]);
                }

                EditorUtility.DisplayProgressBar($"{nameof(Collect)}", "搜集打包设置资源", (float)(i + 1) / items.Count);
            }

            EditorUtility.ClearProgressBar();

            return(files);
        }
Пример #5
0
        public void AddRule(BuildItem item)
        {
            if (string.IsNullOrEmpty(item.assetPath))
            {
                Debug.LogError("添加的规则路径不能为空!!");
                return;
            }

            if (!Directory.Exists(item.assetPath))
            {
                Debug.LogError($"不存在路径:{item.assetPath}!!");
                return;
            }

            if (GetBuildItem(item.assetPath) != null)
            {
                Debug.LogError($"该规则已经存在:{item.assetPath}!!");
                return;
            }

            items.Add(item);
            Save();
        }
Пример #6
0
        public void EndInit()
        {
            buildRoot = Path.GetFullPath(buildRoot).Replace("\\", "/");

            itemDic.Clear();

            for (int i = 0; i < items.Count; i++)
            {
                BuildItem buildItem = items[i];

                if (buildItem.bundleType == EBundleType.All || buildItem.bundleType == EBundleType.Directory)
                {
                    if (!Directory.Exists(buildItem.assetPath))
                    {
                        throw new Exception($"不存在资源路径:{buildItem.assetPath}");
                    }
                }

                //处理后缀
                string[] prefixes = buildItem.suffix.Split('|');
                for (int ii = 0; ii < prefixes.Length; ii++)
                {
                    string prefix = prefixes[ii].Trim();
                    if (!string.IsNullOrEmpty(prefix))
                    {
                        buildItem.suffixes.Add(prefix);
                    }
                }

                if (itemDic.ContainsKey(buildItem.assetPath))
                {
                    throw new Exception($"重复的资源路径:{buildItem.assetPath}");
                }
                itemDic.Add(buildItem.assetPath, buildItem);
            }
        }
Пример #7
0
        /// <summary>
        /// 获取所有在打包设置的文件列表
        /// </summary>
        /// <returns>文件列表</returns>
        public HashSet <string> Collect()
        {
            float min = Builder.collectRuleFileProgress.x;
            float max = Builder.collectRuleFileProgress.y;

            EditorUtility.DisplayProgressBar($"{nameof(Collect)}", "搜集打包规则资源", min);

            //处理每个规则忽略的目录,如路径A/B/C,需要忽略A/B
            for (int i = 0; i < items.Count; i++)
            {
                BuildItem buildItem_i = items[i];

                if (buildItem_i.resourceType != EResourceType.Direct)
                {
                    continue;
                }

                buildItem_i.ignorePaths.Clear();
                for (int j = 0; j < items.Count; j++)
                {
                    BuildItem buildItem_j = items[j];
                    if (i != j && buildItem_j.resourceType == EResourceType.Direct)
                    {
                        if (buildItem_j.assetPath.StartsWith(buildItem_i.assetPath, StringComparison.InvariantCulture))
                        {
                            buildItem_i.ignorePaths.Add(buildItem_j.assetPath);
                        }
                    }
                }
            }

            //存储被规则分析到的所有文件
            HashSet <string> files = new HashSet <string>();

            for (int i = 0; i < items.Count; i++)
            {
                BuildItem buildItem = items[i];

                EditorUtility.DisplayProgressBar($"{nameof(Collect)}", "搜集打包规则资源", min + (max - min) * ((float)i / (items.Count - 1)));

                if (buildItem.resourceType != EResourceType.Direct)
                {
                    continue;
                }

                List <string> tempFiles = Builder.GetFiles(buildItem.assetPath, null, buildItem.suffixes.ToArray());
                for (int j = 0; j < tempFiles.Count; j++)
                {
                    string file = tempFiles[j];

                    //过滤被忽略的
                    if (IsIgnore(buildItem.ignorePaths, file))
                    {
                        continue;
                    }

                    files.Add(file);
                }

                EditorUtility.DisplayProgressBar($"{nameof(Collect)}", "搜集打包设置资源", (float)(i + 1) / items.Count);
            }

            return(files);
        }