Beispiel #1
0
 /// <summary>
 /// 添加元素
 /// </summary>
 public static void AddElement(string folderPath)
 {
     if (IsContainsElement(folderPath) == false)
     {
         AssetBundleCollectorSetting.Wrapper element = new AssetBundleCollectorSetting.Wrapper();
         element.FolderPath = folderPath;
         Setting.Elements.Add(element);
         SaveFile();
     }
 }
Beispiel #2
0
        /// <summary>
        /// 2. 创建Readme文件到输出目录
        /// </summary>
        private void CreateReadmeFile(string[] allAssetBundles)
        {
            // 删除旧文件
            string filePath = OutputPath + "/readme.txt";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            Log($"创建说明文件:{filePath}");

            StringBuilder content = new StringBuilder();

            AppendData(content, $"构建平台:{BuildTarget}");
            AppendData(content, $"构建版本:{BuildVersion}");
            AppendData(content, $"构建时间:{DateTime.Now}");

            AppendData(content, "");
            AppendData(content, $"--配置信息--");
            for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Elements.Count; i++)
            {
                AssetBundleCollectorSetting.Wrapper wrapper = AssetBundleCollectorSettingData.Setting.Elements[i];
                AppendData(content, $"FolderPath : {wrapper.FolderPath} || PackRule : {wrapper.PackRule} || LabelRule : {wrapper.LabelRule}");
            }

            AppendData(content, "");
            AppendData(content, $"--构建参数--");
            AppendData(content, $"CompressOption:{CompressOption}");
            AppendData(content, $"ForceRebuild:{IsForceRebuild}");
            AppendData(content, $"DisableWriteTypeTree:{IsDisableWriteTypeTree}");
            AppendData(content, $"IgnoreTypeTreeChanges:{IsIgnoreTypeTreeChanges}");

            AppendData(content, "");
            AppendData(content, $"--构建清单--");
            for (int i = 0; i < allAssetBundles.Length; i++)
            {
                AppendData(content, allAssetBundles[i]);
            }

            AppendData(content, "");
            AppendData(content, $"--更新清单--");
            PatchManifest patchFile = LoadPatchManifestFile();

            foreach (var pair in patchFile.Elements)
            {
                if (pair.Value.Version == BuildVersion)
                {
                    AppendData(content, pair.Key);
                }
            }

            // 创建新文件
            File.WriteAllText(filePath, content.ToString(), Encoding.UTF8);
        }
Beispiel #3
0
        /// <summary>
        /// 获取资源的打包标签
        /// </summary>
        public static string GetAssetBundleLabel(string assetPath)
        {
            // 注意:一个资源有可能被多个规则覆盖
            List <AssetBundleCollectorSetting.Wrapper> filterWrappers = new List <AssetBundleCollectorSetting.Wrapper>();

            for (int i = 0; i < Setting.Elements.Count; i++)
            {
                AssetBundleCollectorSetting.Wrapper wrapper = Setting.Elements[i];
                if (assetPath.StartsWith(wrapper.FolderPath))
                {
                    filterWrappers.Add(wrapper);
                }
            }

            // 我们使用路径最深层的规则
            AssetBundleCollectorSetting.Wrapper findWrapper = null;
            for (int i = 0; i < filterWrappers.Count; i++)
            {
                AssetBundleCollectorSetting.Wrapper wrapper = filterWrappers[i];
                if (findWrapper == null)
                {
                    findWrapper = wrapper;
                    continue;
                }
                if (wrapper.FolderPath.Length > findWrapper.FolderPath.Length)
                {
                    findWrapper = wrapper;
                }
            }

            // 如果没有找到命名规则,文件路径作为默认的标签名
            if (findWrapper == null)
            {
                return(assetPath.Remove(assetPath.LastIndexOf(".")));                // "Assets/Config/test.txt" --> "Assets/Config/test"
            }

            // 根据规则设置获取标签名称
            if (findWrapper.LabelRule == AssetBundleCollectorSetting.EBundleLabelRule.None)
            {
                // 注意:如果依赖资源来自于忽略文件夹,那么会触发这个异常
                throw new Exception($"CollectionSetting has depend asset in ignore folder : {findWrapper.FolderPath}");
            }
            else if (findWrapper.LabelRule == AssetBundleCollectorSetting.EBundleLabelRule.LabelByFilePath)
            {
                return(assetPath.Remove(assetPath.LastIndexOf(".")));                // "Assets/Config/test.txt" --> "Assets/Config/test"
            }
            else if (findWrapper.LabelRule == AssetBundleCollectorSetting.EBundleLabelRule.LabelByFolderPath)
            {
                return(Path.GetDirectoryName(assetPath));                // "Assets/Config/test.txt" --> "Assets/Config"
            }
            else
            {
                throw new NotImplementedException($"{findWrapper.LabelRule}");
            }
        }
Beispiel #4
0
 /// <summary>
 /// 是否忽略该资源
 /// </summary>
 public static bool IsIgnoreAsset(string assetPath)
 {
     for (int i = 0; i < Setting.Elements.Count; i++)
     {
         AssetBundleCollectorSetting.Wrapper wrapper = Setting.Elements[i];
         if (wrapper.PackRule == AssetBundleCollectorSetting.EFolderPackRule.Ignore)
         {
             if (assetPath.StartsWith(wrapper.FolderPath))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #5
0
        /// <summary>
        /// 获取所有的打包路径
        /// </summary>
        public static List <string> GetAllCollectPath()
        {
            List <string> result = new List <string>();

            for (int i = 0; i < Setting.Elements.Count; i++)
            {
                AssetBundleCollectorSetting.Wrapper wrapper = Setting.Elements[i];
                if (wrapper.PackRule == AssetBundleCollectorSetting.EFolderPackRule.Collect)
                {
                    result.Add(wrapper.FolderPath);
                }
            }

            return(result);
        }