Files
YooAsset/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs

121 lines
2.6 KiB
C#
Raw Normal View History

2022-03-16 11:33:45 +08:00
using System;
using System.Linq;
2022-03-01 10:44:12 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
namespace YooAsset.Editor
{
public class BuildBundleInfo
{
/// <summary>
2022-04-02 15:12:08 +08:00
/// 资源包名称
2022-03-01 10:44:12 +08:00
/// </summary>
2022-03-17 15:27:49 +08:00
public string BundleName { private set; get; }
2022-03-01 10:44:12 +08:00
/// <summary>
2022-03-17 21:52:08 +08:00
/// 参与构建的资源列表
2022-04-02 15:12:08 +08:00
/// 注意:不包含零依赖资源
2022-03-01 10:44:12 +08:00
/// </summary>
2022-03-17 21:52:08 +08:00
public readonly List<BuildAssetInfo> BuildinAssets = new List<BuildAssetInfo>();
2022-03-01 10:44:12 +08:00
/// <summary>
/// 是否为原生文件
/// </summary>
public bool IsRawFile
{
get
{
2022-03-17 21:52:08 +08:00
foreach (var asset in BuildinAssets)
2022-03-01 10:44:12 +08:00
{
if (asset.IsRawAsset)
return true;
}
return false;
}
}
2022-08-03 20:47:43 +08:00
/// <summary>
/// 构建内容哈希值
/// </summary>
public string ContentHash { set; get; } = "00000000000000000000000000000000"; //32位
2022-03-01 10:44:12 +08:00
2022-03-16 17:35:21 +08:00
public BuildBundleInfo(string bundleName)
2022-03-01 10:44:12 +08:00
{
2022-03-16 17:35:21 +08:00
BundleName = bundleName;
2022-03-01 10:44:12 +08:00
}
/// <summary>
/// 添加一个打包资源
/// </summary>
public void PackAsset(BuildAssetInfo assetInfo)
{
if (IsContainsAsset(assetInfo.AssetPath))
throw new System.Exception($"Asset is existed : {assetInfo.AssetPath}");
2022-03-17 21:52:08 +08:00
BuildinAssets.Add(assetInfo);
2022-03-01 10:44:12 +08:00
}
/// <summary>
2022-04-02 15:12:08 +08:00
/// 是否包含指定资源
2022-03-01 10:44:12 +08:00
/// </summary>
2022-04-02 15:12:08 +08:00
public bool IsContainsAsset(string assetPath)
2022-03-01 10:44:12 +08:00
{
2022-04-02 15:12:08 +08:00
foreach (var assetInfo in BuildinAssets)
{
if (assetInfo.AssetPath == assetPath)
{
return true;
}
}
return false;
2022-03-01 10:44:12 +08:00
}
/// <summary>
/// 获取资源包的分类标签列表
2022-03-01 10:44:12 +08:00
/// </summary>
public string[] GetBundleTags()
2022-03-01 10:44:12 +08:00
{
2022-03-17 21:52:08 +08:00
List<string> result = new List<string>(BuildinAssets.Count);
foreach (var assetInfo in BuildinAssets)
2022-03-01 10:44:12 +08:00
{
foreach (var assetTag in assetInfo.BundleTags)
2022-03-01 10:44:12 +08:00
{
if (result.Contains(assetTag) == false)
result.Add(assetTag);
}
}
return result.ToArray();
}
/// <summary>
/// 获取构建的资源路径列表
/// </summary>
public string[] GetBuildinAssetPaths()
{
2022-03-17 21:52:08 +08:00
return BuildinAssets.Select(t => t.AssetPath).ToArray();
2022-03-01 10:44:12 +08:00
}
/// <summary>
2022-04-02 15:12:08 +08:00
/// 获取所有写入补丁清单的资源
2022-03-01 10:44:12 +08:00
/// </summary>
2022-04-02 15:12:08 +08:00
public BuildAssetInfo[] GetAllPatchAssetInfos()
2022-03-01 10:44:12 +08:00
{
return BuildinAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
2022-03-01 10:44:12 +08:00
}
/// <summary>
/// 创建AssetBundleBuild类
/// </summary>
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
{
// 注意我们不在支持AssetBundle的变种机制
AssetBundleBuild build = new AssetBundleBuild();
build.assetBundleName = BundleName;
build.assetBundleVariant = string.Empty;
build.assetNames = GetBuildinAssetPaths();
return build;
}
}
}