Exemplo n.º 1
0
        public static BundleLabelAndVariant GetBundleLabelAndVariant(string assetPath)
        {
            string label;

            // 获取收集器
            AssetBundleCollectorSetting.Collector findWrapper = null;
            for (int i = 0; i < Setting.Collectors.Count; i++)
            {
                AssetBundleCollectorSetting.Collector wrapper = Setting.Collectors[i];
                if (assetPath.StartsWith(wrapper.CollectDirectory))
                {
                    findWrapper = wrapper;
                    break;
                }
            }

            // 如果没有找到收集器
            if (findWrapper == null)
            {
                IBundleLabel defaultLabel = new LabelByFilePath();
                label = defaultLabel.GetAssetBundleLabel(assetPath);
            }
            else
            {
                // 根据规则设置获取标签名称
                IBundleLabel bundleLabel = GetCollectorInstance(findWrapper.LabelClassName);
                label = bundleLabel.GetAssetBundleLabel(assetPath);
            }

            // 注意:如果资源所在文件夹的名称包含后缀符号,则为变体资源
            string folderName = Path.GetDirectoryName(assetPath);             // "Assets/Texture.HD/background.jpg" --> "Assets/Texture.HD"

            if (Path.HasExtension(folderName))
            {
                string extension             = Path.GetExtension(folderName);
                BundleLabelAndVariant result = new BundleLabelAndVariant();
                result.BundleLabel   = EditorTools.GetRegularPath(label.Replace(extension, string.Empty));
                result.BundleVariant = extension.RemoveFirstChar();
                return(result);
            }
            else
            {
                BundleLabelAndVariant result = new BundleLabelAndVariant();
                result.BundleLabel   = EditorTools.GetRegularPath(label);
                result.BundleVariant = PatchDefine.AssetBundleDefaultVariant;
                return(result);
            }
        }
        /// <summary>
        /// 获取资源的打包标签
        /// </summary>
        public static string GetAssetBundleLabel(string assetpath)
        {
            // 注意:一个资源有可能被多个收集器覆盖
            List <Collector> filterWrappers = new List <Collector>();

            for (int i = 0; i < Setting.AssetBundleCollectors.Count; i++)
            {
                Collector wrapper = Setting.AssetBundleCollectors[i];
                if (assetpath.StartsWith(wrapper.CollectFolderPath))
                {
                    filterWrappers.Add(wrapper);
                }
            }

            // 我们使用路径最深层的收集器
            Collector findWrapper = null;

            for (int i = 0; i < filterWrappers.Count; i++)
            {
                Collector wrapper = filterWrappers[i];
                if (findWrapper == null)
                {
                    findWrapper = wrapper;
                    continue;
                }
                if (wrapper.CollectFolderPath.Length > findWrapper.CollectFolderPath.Length)
                {
                    findWrapper = wrapper;
                }
            }

            // 如果没有找到收集器
            if (findWrapper == null)
            {
                IAssetCollector defaultCollector = new LabelByFilePath();
                return(defaultCollector.GetAssetBundleLabel(assetpath));
            }

            // 根据规则设置获取标签名称
            IAssetCollector collector = GetCollectorInstance(findWrapper.GetCollectorClassName());

            return(collector.GetAssetBundleLabel(assetpath, findWrapper));
        }