예제 #1
0
        /// <summary>
        /// 获取资源的打包信息
        /// </summary>
        public static BundleLabelAndVariant GetBundleLabelAndVariant(string assetPath, System.Type assetType)
        {
            // 如果收集全路径着色器
            if (Setting.IsCollectAllShaders)
            {
                if (assetType == typeof(UnityEngine.Shader))
                {
                    return(new BundleLabelAndVariant(Setting.ShadersBundleName, PatchDefine.AssetBundleDefaultVariant));
                }
            }

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

            string bundleLabel;

            // 如果没有找到收集器
            if (findCollector == null)
            {
                IPackRule defaultInstance = new PackExplicit();
                bundleLabel = defaultInstance.GetAssetBundleLabel(assetPath);
            }
            else
            {
                // 根据规则设置获取标签名称
                IPackRule getInstance = GetPackRuleInstance(findCollector.PackRuleClassName);
                bundleLabel = getInstance.GetAssetBundleLabel(assetPath);
            }

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

            if (Path.HasExtension(assetDirectory))
            {
                string extension = Path.GetExtension(assetDirectory);
                bundleLabel = bundleLabel.Replace(extension, string.Empty);
                string bundleVariant = extension.RemoveFirstChar();
                return(new BundleLabelAndVariant(bundleLabel, bundleVariant));
            }
            else
            {
                return(new BundleLabelAndVariant(bundleLabel, PatchDefine.AssetBundleDefaultVariant));
            }
        }
        /// <summary>
        /// 获取资源的打包信息
        /// </summary>
        public static BundleLabelAndVariant GetBundleLabelAndVariant(string assetPath)
        {
            // 如果收集全路径着色器
            if (Setting.IsCollectAllShaders)
            {
                System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
                if (assetType == typeof(UnityEngine.Shader))
                {
                    return(new BundleLabelAndVariant(Setting.ShadersBundleName, PatchDefine.AssetBundleDefaultVariant));
                }
            }

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

            // 如果没有找到收集器
            string bundleLabel;

            if (findCollector == null)
            {
                IPackRule defaultInstance = new PackExplicit();
                bundleLabel = defaultInstance.GetAssetBundleLabel(assetPath);
            }
            else
            {
                // 根据规则设置获取标签名称
                IPackRule getInstance = GetPackRuleInstance(findCollector.PackRuleName);
                bundleLabel = getInstance.GetAssetBundleLabel(assetPath);
            }

            return(new BundleLabelAndVariant(bundleLabel, PatchDefine.AssetBundleDefaultVariant));
        }