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

113 lines
2.7 KiB
C#
Raw Normal View History

2022-04-02 15:12:08 +08:00
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
namespace YooAsset.Editor
{
public class BuildMapContext : IContextObject
{
private readonly Dictionary<string, BuildBundleInfo> _bundleInfoDic = new Dictionary<string, BuildBundleInfo>(10000);
2022-04-02 15:12:08 +08:00
/// <summary>
/// 参与构建的资源总数
/// 说明:包括主动收集的资源以及其依赖的所有资源
/// </summary>
public int AssetFileCount;
2022-10-19 15:54:59 +08:00
/// <summary>
/// 是否启用可寻址资源定位
/// </summary>
public bool EnableAddressable;
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName;
/// <summary>
/// 着色器统一的全名称
/// </summary>
public string ShadersBundleName;
2022-04-02 15:12:08 +08:00
/// <summary>
2023-03-09 15:16:02 +08:00
/// 资源包信息列表
2022-04-02 15:12:08 +08:00
/// </summary>
2023-03-09 15:16:02 +08:00
public Dictionary<string, BuildBundleInfo>.ValueCollection Collection
{
get
{
return _bundleInfoDic.Values;
}
}
2022-04-02 15:12:08 +08:00
/// <summary>
/// 添加一个打包资源
/// </summary>
public void PackAsset(BuildAssetInfo assetInfo)
{
string bundleName = assetInfo.BundleName;
if (string.IsNullOrEmpty(bundleName))
throw new Exception("Should never get here !");
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo bundleInfo))
2022-04-02 15:12:08 +08:00
{
bundleInfo.PackAsset(assetInfo);
}
else
{
BuildBundleInfo newBundleInfo = new BuildBundleInfo(bundleName);
2022-04-02 15:12:08 +08:00
newBundleInfo.PackAsset(assetInfo);
_bundleInfoDic.Add(bundleName, newBundleInfo);
2022-04-02 15:12:08 +08:00
}
}
/// <summary>
/// 是否包含资源包
/// </summary>
public bool IsContainsBundle(string bundleName)
{
return _bundleInfoDic.ContainsKey(bundleName);
2022-04-02 15:12:08 +08:00
}
/// <summary>
/// 获取资源包信息如果没找到返回NULL
/// </summary>
public BuildBundleInfo GetBundleInfo(string bundleName)
2022-04-02 15:12:08 +08:00
{
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo result))
2022-04-02 15:12:08 +08:00
{
return result;
2022-04-02 15:12:08 +08:00
}
throw new Exception($"Not found bundle : {bundleName}");
2022-04-02 15:12:08 +08:00
}
2023-03-09 10:29:14 +08:00
2023-03-09 15:16:02 +08:00
/// <summary>
/// 获取构建管线里需要的数据
/// </summary>
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
{
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(_bundleInfoDic.Count);
foreach (var bundleInfo in _bundleInfoDic.Values)
{
if (bundleInfo.IsRawFile == false)
builds.Add(bundleInfo.CreatePipelineBuild());
}
return builds.ToArray();
}
2023-03-09 10:29:14 +08:00
/// <summary>
/// 创建着色器信息类
/// </summary>
public void CreateShadersBundleInfo(string shadersBundleName)
{
if (IsContainsBundle(shadersBundleName) == false)
{
var shaderBundleInfo = new BuildBundleInfo(shadersBundleName);
_bundleInfoDic.Add(shadersBundleName, shaderBundleInfo);
}
}
2022-04-02 15:12:08 +08:00
}
}