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

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

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

        StringBuilder content = new StringBuilder();

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

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

        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, $"--更新清单--");
        PatchFile patchFile = LoadPatchFile();

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

        // 创建新文件
        File.WriteAllText(filePath, content.ToString(), Encoding.UTF8);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 获取所有的打包路径
    /// </summary>
    public static List <string> GetAllCollectPath()
    {
        List <string> result = new List <string>();

        for (int i = 0; i < Setting.Elements.Count; i++)
        {
            BuildSetting.Wrapper wrapper = Setting.Elements[i];
            if (wrapper.PackRule == BuildSetting.EFolderPackRule.Collect)
            {
                result.Add(wrapper.FolderPath);
            }
        }
        return(result);
    }
Exemplo n.º 4
0
 /// <summary>
 /// 是否忽略该资源
 /// </summary>
 public static bool IsIgnoreAsset(string assetPath)
 {
     for (int i = 0; i < Setting.Elements.Count; i++)
     {
         BuildSetting.Wrapper wrapper = Setting.Elements[i];
         if (wrapper.PackRule == BuildSetting.EFolderPackRule.Ignore)
         {
             if (assetPath.StartsWith(wrapper.FolderPath))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 5
0
    /// <summary>
    /// 获取资源的打包标签名称
    /// </summary>
    public static string GetAssetTagName(string assetPath)
    {
        for (int i = 0; i < Setting.Elements.Count; i++)
        {
            BuildSetting.Wrapper wrapper = Setting.Elements[i];
            if (assetPath.StartsWith(wrapper.FolderPath))
            {
                if (wrapper.NameRule == BuildSetting.EBundleNameRule.None)
                {
                    // 注意:如果依赖资源来自于忽略文件夹,那么会触发这个异常
                    throw new Exception($"BuildSetting has depend asset in ignore folder : {wrapper.FolderPath}");
                }
                else if (wrapper.NameRule == BuildSetting.EBundleNameRule.TagByFileName)
                {
                    return(Path.GetFileNameWithoutExtension(assetPath));
                }
                else if (wrapper.NameRule == BuildSetting.EBundleNameRule.TagByFilePath)
                {
                    return(assetPath.Remove(assetPath.LastIndexOf(".")));
                }
                else if (wrapper.NameRule == BuildSetting.EBundleNameRule.TagByFolderName)
                {
                    string temp = Path.GetDirectoryName(assetPath);
                    return(Path.GetFileName(temp));
                }
                else if (wrapper.NameRule == BuildSetting.EBundleNameRule.TagByFolderPath)
                {
                    return(Path.GetDirectoryName(assetPath));
                }
                else
                {
                    throw new NotImplementedException($"{wrapper.NameRule}");
                }
            }
        }

        // 如果没有找到命名规则
        return(assetPath.Remove(assetPath.LastIndexOf(".")));
    }
Exemplo n.º 6
0
    /// <summary>
    /// 获取资源的打包标签名称
    /// </summary>
    public static string GetAssetTagName(string assetPath)
    {
        // 注意:一个资源有可能被多个规则覆盖
        List <BuildSetting.Wrapper> filterWrappers = new List <BuildSetting.Wrapper>();

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

        // 我们使用路径最深层的规则
        BuildSetting.Wrapper findWrapper = null;
        for (int i = 0; i < filterWrappers.Count; i++)
        {
            BuildSetting.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(".")));
        }

        // 根据规则设置获取标签名称
        if (findWrapper.NameRule == BuildSetting.EBundleNameRule.None)
        {
            // 注意:如果依赖资源来自于忽略文件夹,那么会触发这个异常
            throw new Exception($"BuildSetting has depend asset in ignore folder : {findWrapper.FolderPath}");
        }
        else if (findWrapper.NameRule == BuildSetting.EBundleNameRule.TagByFileName)
        {
            return(Path.GetFileNameWithoutExtension(assetPath));
        }
        else if (findWrapper.NameRule == BuildSetting.EBundleNameRule.TagByFilePath)
        {
            return(assetPath.Remove(assetPath.LastIndexOf(".")));
        }
        else if (findWrapper.NameRule == BuildSetting.EBundleNameRule.TagByFolderName)
        {
            string temp = Path.GetDirectoryName(assetPath);
            return(Path.GetFileName(temp));
        }
        else if (findWrapper.NameRule == BuildSetting.EBundleNameRule.TagByFolderPath)
        {
            return(Path.GetDirectoryName(assetPath));
        }
        else
        {
            throw new NotImplementedException($"{findWrapper.NameRule}");
        }
    }