mirror of https://github.com/tuyoogame/YooAsset
parent
eed3c9768b
commit
c4875d4f80
|
@ -7,8 +7,6 @@ namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class BuildAssetInfo
|
public class BuildAssetInfo
|
||||||
{
|
{
|
||||||
private string _mainBundleName;
|
|
||||||
private string _shareBundleName;
|
|
||||||
private bool _isAddAssetTags = false;
|
private bool _isAddAssetTags = false;
|
||||||
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
||||||
|
|
||||||
|
@ -17,6 +15,11 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ECollectorType CollectorType { private set; get; }
|
public ECollectorType CollectorType { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包完整名称
|
||||||
|
/// </summary>
|
||||||
|
public string BundleName { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 可寻址地址
|
/// 可寻址地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -54,10 +57,10 @@ namespace YooAsset.Editor
|
||||||
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
|
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
public BuildAssetInfo(ECollectorType collectorType, string mainBundleName, string address, string assetPath, bool isRawAsset)
|
public BuildAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, bool isRawAsset)
|
||||||
{
|
{
|
||||||
_mainBundleName = mainBundleName;
|
|
||||||
CollectorType = collectorType;
|
CollectorType = collectorType;
|
||||||
|
BundleName = bundleName;
|
||||||
Address = address;
|
Address = address;
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
IsRawAsset = isRawAsset;
|
IsRawAsset = isRawAsset;
|
||||||
|
@ -133,24 +136,12 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasBundleName()
|
public bool HasBundleName()
|
||||||
{
|
{
|
||||||
string bundleName = GetBundleName();
|
if (string.IsNullOrEmpty(BundleName))
|
||||||
if (string.IsNullOrEmpty(bundleName))
|
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取资源包名称
|
|
||||||
/// </summary>
|
|
||||||
public string GetBundleName()
|
|
||||||
{
|
|
||||||
if (CollectorType == ECollectorType.None)
|
|
||||||
return _shareBundleName;
|
|
||||||
else
|
|
||||||
return _mainBundleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加关联的资源包名称
|
/// 添加关联的资源包名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -164,53 +155,32 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 计算主资源或共享资源的完整包名
|
/// 计算共享资源包的完整包名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CalculateFullBundleName(bool uniqueBundleName, string packageName)
|
public void CalculateShareBundleName(bool uniqueBundleName, string packageName, string shadersBundleName)
|
||||||
{
|
|
||||||
if (CollectorType == ECollectorType.None)
|
|
||||||
{
|
{
|
||||||
|
if (CollectorType != ECollectorType.None)
|
||||||
|
return;
|
||||||
|
|
||||||
if (IsRawAsset)
|
if (IsRawAsset)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
if (IsShaderAsset)
|
if (IsShaderAsset)
|
||||||
{
|
{
|
||||||
_shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName(uniqueBundleName, packageName);
|
BundleName = shadersBundleName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_referenceBundleNames.Count > 1)
|
if (_referenceBundleNames.Count > 1)
|
||||||
{
|
{
|
||||||
IPackRule packRule = PackDirectory.StaticPackRule;
|
IPackRule packRule = PackDirectory.StaticPackRule;
|
||||||
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
|
PackRuleResult packRuleResult = packRule.GetPackRuleResult(new PackRuleData(AssetPath));
|
||||||
if (YooAssetSettingsData.Setting.RegularBundleName)
|
BundleName = packRuleResult.GetShareBundleName(packageName, uniqueBundleName);
|
||||||
bundleName = EditorTools.GetRegularPath(bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
|
||||||
else
|
|
||||||
bundleName = EditorTools.GetRegularPath(bundleName).ToLower();
|
|
||||||
|
|
||||||
if (uniqueBundleName)
|
|
||||||
_shareBundleName = $"{packageName.ToLower()}_share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
|
||||||
else
|
|
||||||
_shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IsRawAsset)
|
// 注意:被引用次数小于1的资源不需要设置资源包名称
|
||||||
{
|
BundleName = string.Empty;
|
||||||
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.RawBundleFileVariant}";
|
|
||||||
_mainBundleName = mainBundleName.ToLower();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
|
||||||
_mainBundleName = mainBundleName.ToLower(); ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uniqueBundleName)
|
|
||||||
{
|
|
||||||
_mainBundleName = $"{packageName.ToLower()}_{_mainBundleName}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,11 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool UniqueBundleName;
|
public bool UniqueBundleName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 着色器统一的全名称
|
||||||
|
/// </summary>
|
||||||
|
public string ShadersBundleName;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包列表
|
/// 资源包列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -35,7 +40,7 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void PackAsset(BuildAssetInfo assetInfo)
|
public void PackAsset(BuildAssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
string bundleName = assetInfo.GetBundleName();
|
string bundleName = assetInfo.BundleName;
|
||||||
if (string.IsNullOrEmpty(bundleName))
|
if (string.IsNullOrEmpty(bundleName))
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static BuildMapContext CreateBuildMap(EBuildMode buildMode, string packageName)
|
public static BuildMapContext CreateBuildMap(EBuildMode buildMode, string packageName)
|
||||||
{
|
{
|
||||||
BuildMapContext context = new BuildMapContext();
|
|
||||||
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000);
|
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000);
|
||||||
|
|
||||||
// 1. 检测配置合法性
|
// 1. 检测配置合法性
|
||||||
|
@ -22,7 +21,7 @@ namespace YooAsset.Editor
|
||||||
var buildResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
var buildResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
||||||
List<CollectAssetInfo> allCollectAssets = buildResult.CollectAssets;
|
List<CollectAssetInfo> allCollectAssets = buildResult.CollectAssets;
|
||||||
|
|
||||||
// 3. 剔除未被引用的依赖资源
|
// 3. 剔除未被引用的依赖项资源
|
||||||
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();
|
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();
|
||||||
foreach (var collectAssetInfo in allCollectAssets)
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
{
|
{
|
||||||
|
@ -42,7 +41,8 @@ namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
|
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
|
||||||
{
|
{
|
||||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName,
|
var buildAssetInfo = new BuildAssetInfo(
|
||||||
|
collectAssetInfo.CollectorType, collectAssetInfo.BundleName,
|
||||||
collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
|
collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
|
||||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
||||||
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||||
|
@ -54,32 +54,28 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 录入相关依赖的资源
|
// 5. 录入所有收集资源的依赖资源
|
||||||
foreach (var collectAssetInfo in allCollectAssets)
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
{
|
{
|
||||||
|
string collectAssetBundleName = collectAssetInfo.BundleName;
|
||||||
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
||||||
{
|
{
|
||||||
if (buildAssetDic.ContainsKey(dependAssetPath))
|
if (buildAssetDic.ContainsKey(dependAssetPath))
|
||||||
{
|
{
|
||||||
buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags);
|
buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags);
|
||||||
buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName);
|
buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetBundleName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
||||||
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||||
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
|
buildAssetInfo.AddReferenceBundleName(collectAssetBundleName);
|
||||||
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. 记录关键信息
|
// 6. 填充所有收集资源的依赖列表
|
||||||
context.AssetFileCount = buildAssetDic.Count;
|
|
||||||
context.EnableAddressable = buildResult.EnableAddressable;
|
|
||||||
context.UniqueBundleName = buildResult.UniqueBundleName;
|
|
||||||
|
|
||||||
// 7. 填充主动收集资源的依赖列表
|
|
||||||
foreach (var collectAssetInfo in allCollectAssets)
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
{
|
{
|
||||||
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
|
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
|
||||||
|
@ -93,10 +89,18 @@ namespace YooAsset.Editor
|
||||||
buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
|
buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. 计算完整的资源包名
|
// 7. 记录关键信息
|
||||||
|
BuildMapContext context = new BuildMapContext();
|
||||||
|
context.AssetFileCount = buildAssetDic.Count;
|
||||||
|
context.EnableAddressable = buildResult.Command.EnableAddressable;
|
||||||
|
context.UniqueBundleName = buildResult.Command.UniqueBundleName;
|
||||||
|
context.ShadersBundleName = buildResult.ShadersBundleName;
|
||||||
|
|
||||||
|
// 8. 计算共享的资源包名
|
||||||
|
var command = buildResult.Command;
|
||||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
||||||
{
|
{
|
||||||
pair.Value.CalculateFullBundleName(buildResult.UniqueBundleName, buildResult.PackageName);
|
pair.Value.CalculateShareBundleName(command.UniqueBundleName, command.PackageName, buildResult.ShadersBundleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. 移除不参与构建的资源
|
// 9. 移除不参与构建的资源
|
||||||
|
|
|
@ -33,8 +33,7 @@ namespace YooAsset.Editor
|
||||||
// 开始构建
|
// 开始构建
|
||||||
IBundleBuildResults buildResults;
|
IBundleBuildResults buildResults;
|
||||||
var buildParameters = buildParametersContext.GetSBPBuildParameters();
|
var buildParameters = buildParametersContext.GetSBPBuildParameters();
|
||||||
var shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(buildMapContext.UniqueBundleName, buildParametersContext.Parameters.PackageName);
|
var taskList = SBPBuildTasks.Create(buildMapContext.ShadersBundleName);
|
||||||
var taskList = SBPBuildTasks.Create(shadersBunldeName);
|
|
||||||
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
|
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
|
||||||
if (exitCode < 0)
|
if (exitCode < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,13 +42,12 @@ namespace YooAsset.Editor
|
||||||
patchManifest.AssetList = GetAllPatchAsset(context, patchManifest);
|
patchManifest.AssetList = GetAllPatchAsset(context, patchManifest);
|
||||||
|
|
||||||
// 更新Unity内置资源包的引用关系
|
// 更新Unity内置资源包的引用关系
|
||||||
string shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(buildMapContext.UniqueBundleName, buildParameters.PackageName);
|
|
||||||
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
{
|
{
|
||||||
if (buildParameters.BuildMode == EBuildMode.IncrementalBuild)
|
if (buildParameters.BuildMode == EBuildMode.IncrementalBuild)
|
||||||
{
|
{
|
||||||
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||||
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results, shadersBunldeName);
|
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results, buildMapContext.ShadersBundleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +97,6 @@ namespace YooAsset.Editor
|
||||||
private List<PatchBundle> GetAllPatchBundle(BuildContext context)
|
private List<PatchBundle> GetAllPatchBundle(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
|
||||||
|
|
||||||
List<PatchBundle> result = new List<PatchBundle>(1000);
|
List<PatchBundle> result = new List<PatchBundle>(1000);
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
|
@ -129,7 +127,7 @@ namespace YooAsset.Editor
|
||||||
patchAsset.Address = string.Empty;
|
patchAsset.Address = string.Empty;
|
||||||
patchAsset.AssetPath = assetInfo.AssetPath;
|
patchAsset.AssetPath = assetInfo.AssetPath;
|
||||||
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||||
patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest);
|
patchAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, patchManifest);
|
||||||
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
|
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
|
||||||
result.Add(patchAsset);
|
result.Add(patchAsset);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +141,7 @@ namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
if (dependAssetInfo.HasBundleName())
|
if (dependAssetInfo.HasBundleName())
|
||||||
{
|
{
|
||||||
int bundleID = GetAssetBundleID(dependAssetInfo.GetBundleName(), patchManifest);
|
int bundleID = GetAssetBundleID(dependAssetInfo.BundleName, patchManifest);
|
||||||
if (mainBundleID != bundleID)
|
if (mainBundleID != bundleID)
|
||||||
{
|
{
|
||||||
if (result.Contains(bundleID) == false)
|
if (result.Contains(bundleID) == false)
|
||||||
|
|
|
@ -48,7 +48,8 @@ namespace YooAsset.Editor
|
||||||
// 4.更新补丁包输出的文件路径
|
// 4.更新补丁包输出的文件路径
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
{
|
{
|
||||||
string patchFileName = PatchManifestTools.CreateBundleFileName(outputNameStyle, bundleInfo.BundleName, bundleInfo.PatchInfo.PatchFileHash, bundleInfo.IsRawFile);
|
string patchFileExtension = PatchManifestTools.GetRemoteBundleFileExtension(bundleInfo.BundleName);
|
||||||
|
string patchFileName = PatchManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleInfo.BundleName, patchFileExtension, bundleInfo.PatchInfo.PatchFileHash);
|
||||||
bundleInfo.PatchInfo.PatchOutputFilePath = $"{packageOutputDirectory}/{patchFileName}";
|
bundleInfo.PatchInfo.PatchOutputFilePath = $"{packageOutputDirectory}/{patchFileName}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,11 +142,14 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
||||||
bool isRawAsset = PackRuleName == nameof(PackRawFile);
|
|
||||||
|
// 检测是否为原生资源打包规则
|
||||||
|
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||||
|
bool isRawFilePackRule = packRuleInstance.IsRawFilePackRule();
|
||||||
|
|
||||||
// 检测原生资源包的收集器类型
|
// 检测原生资源包的收集器类型
|
||||||
if (isRawAsset && CollectorType != ECollectorType.MainAssetCollector)
|
if (isRawFilePackRule && CollectorType != ECollectorType.MainAssetCollector)
|
||||||
throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}");
|
throw new Exception($"The raw file pack rule must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(CollectPath))
|
if (string.IsNullOrEmpty(CollectPath))
|
||||||
throw new Exception($"The collect path is null or empty in group : {group.GroupName}");
|
throw new Exception($"The collect path is null or empty in group : {group.GroupName}");
|
||||||
|
@ -158,11 +161,11 @@ namespace YooAsset.Editor
|
||||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||||
foreach (string assetPath in findAssets)
|
foreach (string assetPath in findAssets)
|
||||||
{
|
{
|
||||||
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(assetPath))
|
||||||
{
|
{
|
||||||
if (result.ContainsKey(assetPath) == false)
|
if (result.ContainsKey(assetPath) == false)
|
||||||
{
|
{
|
||||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawAsset);
|
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawFilePackRule);
|
||||||
result.Add(assetPath, collectAssetInfo);
|
result.Add(assetPath, collectAssetInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -175,9 +178,9 @@ namespace YooAsset.Editor
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string assetPath = CollectPath;
|
string assetPath = CollectPath;
|
||||||
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(assetPath))
|
||||||
{
|
{
|
||||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawAsset);
|
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawFilePackRule);
|
||||||
result.Add(assetPath, collectAssetInfo);
|
result.Add(assetPath, collectAssetInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -207,22 +210,22 @@ namespace YooAsset.Editor
|
||||||
return result.Values.ToList();
|
return result.Values.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath, bool isRawFilePackRule)
|
||||||
{
|
{
|
||||||
string address = GetAddress(group, assetPath);
|
string address = GetAddress(group, assetPath);
|
||||||
string bundleName = GetBundleName(group, assetPath);
|
string bundleName = GetBundleName(command, group, assetPath);
|
||||||
List<string> assetTags = GetAssetTags(group);
|
List<string> assetTags = GetAssetTags(group);
|
||||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
|
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, isRawFilePackRule, assetTags);
|
||||||
|
|
||||||
// 注意:模拟构建模式下不需要收集依赖资源
|
// 注意:模拟构建模式下不需要收集依赖资源
|
||||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||||
collectAssetInfo.DependAssets = new List<string>();
|
collectAssetInfo.DependAssets = new List<string>();
|
||||||
else
|
else
|
||||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
collectAssetInfo.DependAssets = GetAllDependencies(assetPath, isRawFilePackRule);
|
||||||
|
|
||||||
return collectAssetInfo;
|
return collectAssetInfo;
|
||||||
}
|
}
|
||||||
private bool IsValidateAsset(string assetPath)
|
private bool IsValidateAsset(string assetPath, bool isRawFilePackRule)
|
||||||
{
|
{
|
||||||
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
||||||
{
|
{
|
||||||
|
@ -239,10 +242,31 @@ namespace YooAsset.Editor
|
||||||
if (type == typeof(LightingDataAsset))
|
if (type == typeof(LightingDataAsset))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// 检测原生文件是否合规
|
||||||
|
if (isRawFilePackRule)
|
||||||
|
{
|
||||||
|
string extension = StringUtility.RemoveFirstChar(System.IO.Path.GetExtension(assetPath));
|
||||||
|
if (extension == EAssetFileExtension.unity.ToString() || extension == EAssetFileExtension.prefab.ToString() ||
|
||||||
|
extension == EAssetFileExtension.mat.ToString() || extension == EAssetFileExtension.controller.ToString() ||
|
||||||
|
extension == EAssetFileExtension.fbx.ToString() || extension == EAssetFileExtension.anim.ToString() ||
|
||||||
|
extension == EAssetFileExtension.shader.ToString())
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogWarning($"Raw file pack rule can not support file estension : {extension}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:原生文件只支持无依赖关系的资源
|
||||||
|
string[] depends = AssetDatabase.GetDependencies(assetPath, true);
|
||||||
|
if (depends.Length != 1)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogWarning($"Raw file pack rule can not support estension : {extension}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// 忽略Unity无法识别的无效文件
|
// 忽略Unity无法识别的无效文件
|
||||||
// 注意:只对非原生文件收集器处理
|
// 注意:只对非原生文件收集器处理
|
||||||
if(PackRuleName != nameof(PackRawFile))
|
|
||||||
{
|
|
||||||
if (type == typeof(UnityEditor.DefaultAsset))
|
if (type == typeof(UnityEditor.DefaultAsset))
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
|
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
|
||||||
|
@ -258,7 +282,7 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
private bool IsIgnoreFile(string fileExtension)
|
private bool IsIgnoreFile(string fileExtension)
|
||||||
{
|
{
|
||||||
foreach (var extension in YooAssetSettings.IgnoreFileExtensions)
|
foreach (var extension in DefaultFilterRule.IgnoreFileExtensions)
|
||||||
{
|
{
|
||||||
if (extension == fileExtension)
|
if (extension == fileExtension)
|
||||||
return true;
|
return true;
|
||||||
|
@ -284,19 +308,22 @@ namespace YooAsset.Editor
|
||||||
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName));
|
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName));
|
||||||
return adressValue;
|
return adressValue;
|
||||||
}
|
}
|
||||||
private string GetBundleName(AssetBundleCollectorGroup group, string assetPath)
|
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||||
{
|
{
|
||||||
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||||
return EditorTools.GetRegularPath(YooAssetSettings.UnityShadersBundleName).ToLower();
|
{
|
||||||
|
// 获取着色器打包规则结果
|
||||||
// 根据规则设置获取资源包名称
|
PackRuleResult packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
return packRuleResult.GetMainBundleName(command.PackageName, command.UniqueBundleName);
|
||||||
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName));
|
}
|
||||||
if(YooAssetSettingsData.Setting.RegularBundleName)
|
|
||||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
|
||||||
else
|
else
|
||||||
return EditorTools.GetRegularPath(bundleName).ToLower();
|
{
|
||||||
|
// 获取其它资源打包规则结果
|
||||||
|
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||||
|
PackRuleResult packRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetPath, CollectPath, group.GroupName));
|
||||||
|
return packRuleResult.GetMainBundleName(command.PackageName, command.UniqueBundleName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||||
{
|
{
|
||||||
|
@ -305,13 +332,13 @@ namespace YooAsset.Editor
|
||||||
tags.AddRange(temper);
|
tags.AddRange(temper);
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
private List<string> GetAllDependencies(string mainAssetPath)
|
private List<string> GetAllDependencies(string mainAssetPath, bool isRawFilePackRule)
|
||||||
{
|
{
|
||||||
List<string> result = new List<string>();
|
List<string> result = new List<string>();
|
||||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||||
foreach (string assetPath in depends)
|
foreach (string assetPath in depends)
|
||||||
{
|
{
|
||||||
if (IsValidateAsset(assetPath))
|
if (IsValidateAsset(assetPath, isRawFilePackRule))
|
||||||
{
|
{
|
||||||
// 注意:排除主资源对象
|
// 注意:排除主资源对象
|
||||||
if (assetPath != mainAssetPath)
|
if (assetPath != mainAssetPath)
|
||||||
|
|
|
@ -100,8 +100,8 @@ namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
if (package.PackageName == packageName)
|
if (package.PackageName == packageName)
|
||||||
{
|
{
|
||||||
CollectCommand command = new CollectCommand(buildMode, EnableAddressable);
|
CollectCommand command = new CollectCommand(buildMode, package.PackageName, EnableAddressable, UniqueBundleName);
|
||||||
CollectResult collectResult = new CollectResult(package.PackageName, EnableAddressable, UniqueBundleName);
|
CollectResult collectResult = new CollectResult(command);
|
||||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||||
return collectResult;
|
return collectResult;
|
||||||
}
|
}
|
||||||
|
@ -118,8 +118,8 @@ namespace YooAsset.Editor
|
||||||
List<CollectResult> collectResultList = new List<CollectResult>(1000);
|
List<CollectResult> collectResultList = new List<CollectResult>(1000);
|
||||||
foreach (var package in Packages)
|
foreach (var package in Packages)
|
||||||
{
|
{
|
||||||
CollectCommand command = new CollectCommand(buildMode, EnableAddressable);
|
CollectCommand command = new CollectCommand(buildMode, package.PackageName, EnableAddressable, UniqueBundleName);
|
||||||
CollectResult collectResult = new CollectResult(package.PackageName, EnableAddressable, UniqueBundleName);
|
CollectResult collectResult = new CollectResult(command);
|
||||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||||
collectResultList.Add(collectResult);
|
collectResultList.Add(collectResult);
|
||||||
}
|
}
|
||||||
|
|
|
@ -776,7 +776,7 @@ namespace YooAsset.Editor
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CollectCommand command = new CollectCommand(EBuildMode.DryRunBuild, _enableAddressableToogle.value);
|
CollectCommand command = new CollectCommand(EBuildMode.DryRunBuild, _packageNameTxt.value, _enableAddressableToogle.value, _uniqueBundleNameToogle.value);
|
||||||
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
|
|
|
@ -25,30 +25,30 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AssetPath { private set; get; }
|
public string AssetPath { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源分类标签
|
|
||||||
/// </summary>
|
|
||||||
public List<string> AssetTags { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否为原生资源
|
/// 是否为原生资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsRawAsset { private set; get; }
|
public bool IsRawAsset { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源分类标签
|
||||||
|
/// </summary>
|
||||||
|
public List<string> AssetTags { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖的资源列表
|
/// 依赖的资源列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> DependAssets = new List<string>();
|
public List<string> DependAssets = new List<string>();
|
||||||
|
|
||||||
|
|
||||||
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, List<string> assetTags, bool isRawAsset)
|
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, bool isRawAsset, List<string> assetTags)
|
||||||
{
|
{
|
||||||
CollectorType = collectorType;
|
CollectorType = collectorType;
|
||||||
BundleName = bundleName;
|
BundleName = bundleName;
|
||||||
Address = address;
|
Address = address;
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
AssetTags = assetTags;
|
|
||||||
IsRawAsset = isRawAsset;
|
IsRawAsset = isRawAsset;
|
||||||
|
AssetTags = assetTags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,15 +8,27 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EBuildMode BuildMode { private set; get; }
|
public EBuildMode BuildMode { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 包裹名称
|
||||||
|
/// </summary>
|
||||||
|
public string PackageName { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用可寻址资源定位
|
/// 是否启用可寻址资源定位
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnableAddressable { private set; get; }
|
public bool EnableAddressable { private set; get; }
|
||||||
|
|
||||||
public CollectCommand(EBuildMode buildMode, bool enableAddressable)
|
/// <summary>
|
||||||
|
/// 资源包名唯一化
|
||||||
|
/// </summary>
|
||||||
|
public bool UniqueBundleName { private set; get; }
|
||||||
|
|
||||||
|
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool uniqueBundleName)
|
||||||
{
|
{
|
||||||
BuildMode = buildMode;
|
BuildMode = buildMode;
|
||||||
|
PackageName = packageName;
|
||||||
EnableAddressable = enableAddressable;
|
EnableAddressable = enableAddressable;
|
||||||
|
UniqueBundleName = uniqueBundleName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,19 +6,14 @@ namespace YooAsset.Editor
|
||||||
public class CollectResult
|
public class CollectResult
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 包裹名称
|
/// 收集命令
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageName { private set; get; }
|
public CollectCommand Command { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用可寻址资源定位
|
/// 着色器统一全名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnableAddressable { private set; get; }
|
public string ShadersBundleName { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源包名唯一化
|
|
||||||
/// </summary>
|
|
||||||
public bool UniqueBundleName { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 收集的资源信息列表
|
/// 收集的资源信息列表
|
||||||
|
@ -26,11 +21,13 @@ namespace YooAsset.Editor
|
||||||
public List<CollectAssetInfo> CollectAssets { private set; get; }
|
public List<CollectAssetInfo> CollectAssets { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
public CollectResult(string packageName, bool enableAddressable, bool uniqueBundleName)
|
public CollectResult(CollectCommand command)
|
||||||
{
|
{
|
||||||
PackageName = packageName;
|
Command = command;
|
||||||
EnableAddressable = enableAddressable;
|
|
||||||
UniqueBundleName = uniqueBundleName;
|
// 着色器统一全名称
|
||||||
|
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||||
|
ShadersBundleName = packRuleResult.GetMainBundleName(command.PackageName, command.UniqueBundleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
|
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
|
||||||
|
|
|
@ -4,6 +4,14 @@ using System.IO;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
|
public class DefaultFilterRule
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 忽略的文件类型
|
||||||
|
/// </summary>
|
||||||
|
public static readonly string[] IgnoreFileExtensions = { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
|
||||||
|
}
|
||||||
|
|
||||||
[DisplayName("收集所有资源")]
|
[DisplayName("收集所有资源")]
|
||||||
public class CollectAll : IFilterRule
|
public class CollectAll : IFilterRule
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,31 @@ using UnityEditor;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
|
public class DefaultPackRule
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// AssetBundle文件的后缀名
|
||||||
|
/// </summary>
|
||||||
|
public const string AssetBundleFileExtension = "bundle";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 原生文件的后缀名
|
||||||
|
/// </summary>
|
||||||
|
public const string RawFileExtension = "rawfile";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unity着色器资源包名称
|
||||||
|
/// </summary>
|
||||||
|
public const string ShadersBundleName = "unityshaders";
|
||||||
|
|
||||||
|
|
||||||
|
public static PackRuleResult CreateShadersPackRuleResult()
|
||||||
|
{
|
||||||
|
PackRuleResult result = new PackRuleResult(ShadersBundleName, AssetBundleFileExtension);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以文件路径作为资源包名
|
/// 以文件路径作为资源包名
|
||||||
/// 注意:每个文件独自打资源包
|
/// 注意:每个文件独自打资源包
|
||||||
|
@ -13,9 +38,16 @@ namespace YooAsset.Editor
|
||||||
[DisplayName("以文件路径作为资源包名")]
|
[DisplayName("以文件路径作为资源包名")]
|
||||||
public class PackSeparately : IPackRule
|
public class PackSeparately : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||||
{
|
{
|
||||||
return StringUtility.RemoveExtension(data.AssetPath);
|
string bundleName = StringUtility.RemoveExtension(data.AssetPath);
|
||||||
|
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPackRule.IsRawFilePackRule()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +62,16 @@ namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public static PackDirectory StaticPackRule = new PackDirectory();
|
public static PackDirectory StaticPackRule = new PackDirectory();
|
||||||
|
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||||
{
|
{
|
||||||
return Path.GetDirectoryName(data.AssetPath);
|
string bundleName = Path.GetDirectoryName(data.AssetPath);
|
||||||
|
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPackRule.IsRawFilePackRule()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +85,7 @@ namespace YooAsset.Editor
|
||||||
[DisplayName("以收集器路径下顶级文件夹为资源包名")]
|
[DisplayName("以收集器路径下顶级文件夹为资源包名")]
|
||||||
public class PackTopDirectory : IPackRule
|
public class PackTopDirectory : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||||
{
|
{
|
||||||
string assetPath = data.AssetPath.Replace(data.CollectPath, string.Empty);
|
string assetPath = data.AssetPath.Replace(data.CollectPath, string.Empty);
|
||||||
assetPath = assetPath.TrimStart('/');
|
assetPath = assetPath.TrimStart('/');
|
||||||
|
@ -56,13 +95,19 @@ namespace YooAsset.Editor
|
||||||
if (Path.HasExtension(splits[0]))
|
if (Path.HasExtension(splits[0]))
|
||||||
throw new Exception($"Not found root directory : {assetPath}");
|
throw new Exception($"Not found root directory : {assetPath}");
|
||||||
string bundleName = $"{data.CollectPath}/{splits[0]}";
|
string bundleName = $"{data.CollectPath}/{splits[0]}";
|
||||||
return bundleName;
|
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception($"Not found root directory : {assetPath}");
|
throw new Exception($"Not found root directory : {assetPath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IPackRule.IsRawFilePackRule()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -72,17 +117,26 @@ namespace YooAsset.Editor
|
||||||
[DisplayName("以收集器路径作为资源包名")]
|
[DisplayName("以收集器路径作为资源包名")]
|
||||||
public class PackCollector : IPackRule
|
public class PackCollector : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||||
{
|
{
|
||||||
|
string bundleName;
|
||||||
string collectPath = data.CollectPath;
|
string collectPath = data.CollectPath;
|
||||||
if (AssetDatabase.IsValidFolder(collectPath))
|
if (AssetDatabase.IsValidFolder(collectPath))
|
||||||
{
|
{
|
||||||
return collectPath;
|
bundleName = collectPath;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return StringUtility.RemoveExtension(collectPath);
|
bundleName = StringUtility.RemoveExtension(collectPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPackRule.IsRawFilePackRule()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +147,16 @@ namespace YooAsset.Editor
|
||||||
[DisplayName("以分组名称作为资源包名")]
|
[DisplayName("以分组名称作为资源包名")]
|
||||||
public class PackGroup : IPackRule
|
public class PackGroup : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||||
{
|
{
|
||||||
return data.GroupName;
|
string bundleName = data.GroupName;
|
||||||
|
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPackRule.IsRawFilePackRule()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,23 +167,16 @@ namespace YooAsset.Editor
|
||||||
[DisplayName("打包原生文件")]
|
[DisplayName("打包原生文件")]
|
||||||
public class PackRawFile : IPackRule
|
public class PackRawFile : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||||
{
|
{
|
||||||
string extension = StringUtility.RemoveFirstChar(Path.GetExtension(data.AssetPath));
|
string bundleName = data.AssetPath;
|
||||||
if (extension == EAssetFileExtension.unity.ToString() || extension == EAssetFileExtension.prefab.ToString() ||
|
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.RawFileExtension);
|
||||||
extension == EAssetFileExtension.mat.ToString() || extension == EAssetFileExtension.controller.ToString() ||
|
return result;
|
||||||
extension == EAssetFileExtension.fbx.ToString() || extension == EAssetFileExtension.anim.ToString() ||
|
|
||||||
extension == EAssetFileExtension.shader.ToString())
|
|
||||||
{
|
|
||||||
throw new Exception($"{nameof(PackRawFile)} is not support file estension : {extension}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:原生文件只支持无依赖关系的资源
|
bool IPackRule.IsRawFilePackRule()
|
||||||
string[] depends = AssetDatabase.GetDependencies(data.AssetPath, true);
|
{
|
||||||
if (depends.Length != 1)
|
return true;
|
||||||
throw new Exception($"{nameof(PackRawFile)} is not support estension : {extension}");
|
|
||||||
|
|
||||||
return data.AssetPath;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +186,14 @@ namespace YooAsset.Editor
|
||||||
[DisplayName("打包着色器变种集合")]
|
[DisplayName("打包着色器变种集合")]
|
||||||
public class PackShaderVariants : IPackRule
|
public class PackShaderVariants : IPackRule
|
||||||
{
|
{
|
||||||
public string GetBundleName(PackRuleData data)
|
public PackRuleResult GetPackRuleResult(PackRuleData data)
|
||||||
{
|
{
|
||||||
return YooAssetSettings.UnityShadersBundleName;
|
return DefaultPackRule.CreateShadersPackRuleResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPackRule.IsRawFilePackRule()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,14 +21,59 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct PackRuleResult
|
||||||
|
{
|
||||||
|
private readonly string _bundleName;
|
||||||
|
private readonly string _bundleExtension;
|
||||||
|
|
||||||
|
public PackRuleResult(string bundleName, string bundleExtension)
|
||||||
|
{
|
||||||
|
_bundleName = bundleName;
|
||||||
|
_bundleExtension = bundleExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取主资源包全名称
|
||||||
|
/// </summary>
|
||||||
|
public string GetMainBundleName(string packageName, bool uniqueBundleName)
|
||||||
|
{
|
||||||
|
string fullName;
|
||||||
|
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
||||||
|
if (uniqueBundleName)
|
||||||
|
fullName = $"{packageName}_{bundleName}.{_bundleExtension}";
|
||||||
|
else
|
||||||
|
fullName = $"{bundleName}.{_bundleExtension}";
|
||||||
|
return fullName.ToLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取共享资源包全名称
|
||||||
|
/// </summary>
|
||||||
|
public string GetShareBundleName(string packageName, bool uniqueBundleName)
|
||||||
|
{
|
||||||
|
string fullName;
|
||||||
|
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
||||||
|
if (uniqueBundleName)
|
||||||
|
fullName = $"{packageName}_share_{bundleName}.{_bundleExtension}";
|
||||||
|
else
|
||||||
|
fullName = $"share_{bundleName}.{_bundleExtension}";
|
||||||
|
return fullName.ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源打包规则接口
|
/// 资源打包规则接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPackRule
|
public interface IPackRule
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源打包所属的资源包名称
|
/// 获取打包规则结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string GetBundleName(PackRuleData data);
|
PackRuleResult GetPackRuleResult(PackRuleData data);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为原生文件打包规则
|
||||||
|
/// </summary>
|
||||||
|
bool IsRawFilePackRule();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue