2025-01-09 11:31:04 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
|
|
|
|
namespace YooAsset.Editor
|
|
|
|
|
{
|
|
|
|
|
public class BuildMapContext : IContextObject
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 资源包集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly Dictionary<string, BuildBundleInfo> _bundleInfoDic = new Dictionary<string, BuildBundleInfo>(10000);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 未被依赖的资源列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly List<ReportIndependAsset> IndependAssets = new List<ReportIndependAsset>(1000);
|
2025-02-28 16:11:01 +08:00
|
|
|
|
|
2025-01-09 11:31:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 参与构建的资源总数
|
|
|
|
|
/// 说明:包括主动收集的资源以及其依赖的所有资源
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int AssetFileCount;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 资源收集命令
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CollectCommand Command { set; get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 资源包信息列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Dictionary<string, BuildBundleInfo>.ValueCollection Collection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _bundleInfoDic.Values;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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))
|
|
|
|
|
{
|
|
|
|
|
bundleInfo.PackAsset(assetInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BuildBundleInfo newBundleInfo = new BuildBundleInfo(bundleName);
|
|
|
|
|
newBundleInfo.PackAsset(assetInfo);
|
|
|
|
|
_bundleInfoDic.Add(bundleName, newBundleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否包含资源包
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsContainsBundle(string bundleName)
|
|
|
|
|
{
|
|
|
|
|
return _bundleInfoDic.ContainsKey(bundleName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取资源包信息,如果没找到返回NULL
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BuildBundleInfo GetBundleInfo(string bundleName)
|
|
|
|
|
{
|
|
|
|
|
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo result))
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
throw new Exception($"Should never get here ! Not found bundle : {bundleName}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取构建管线里需要的数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
|
|
|
|
|
{
|
|
|
|
|
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(_bundleInfoDic.Count);
|
|
|
|
|
foreach (var bundleInfo in _bundleInfoDic.Values)
|
|
|
|
|
{
|
|
|
|
|
builds.Add(bundleInfo.CreatePipelineBuild());
|
|
|
|
|
}
|
|
|
|
|
return builds.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-02-28 16:11:01 +08:00
|
|
|
|
/// 创建空的资源包
|
2025-01-09 11:31:04 +08:00
|
|
|
|
/// </summary>
|
2025-02-28 16:11:01 +08:00
|
|
|
|
public void CreateEmptyBundleInfo(string bundleName)
|
2025-01-09 11:31:04 +08:00
|
|
|
|
{
|
2025-02-28 16:11:01 +08:00
|
|
|
|
if (IsContainsBundle(bundleName) == false)
|
2025-01-09 11:31:04 +08:00
|
|
|
|
{
|
2025-02-28 16:11:01 +08:00
|
|
|
|
var bundleInfo = new BuildBundleInfo(bundleName);
|
|
|
|
|
_bundleInfoDic.Add(bundleName, bundleInfo);
|
2025-01-09 11:31:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|