mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
TEngine全面更新,升级YooAsset2.1.1、UniTask、UIWindow、I2Localization
TEngine全面更新,升级YooAsset2.1.1、UniTask、UIWindow、I2Localization
This commit is contained in:
@@ -6,352 +6,316 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class AssetBundleCollector
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集路径
|
||||
/// 注意:支持文件夹或单个资源文件
|
||||
/// </summary>
|
||||
public string CollectPath = string.Empty;
|
||||
[Serializable]
|
||||
public class AssetBundleCollector
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集路径
|
||||
/// 注意:支持文件夹或单个资源文件
|
||||
/// </summary>
|
||||
public string CollectPath = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 收集器的GUID
|
||||
/// </summary>
|
||||
public string CollectorGUID = string.Empty;
|
||||
/// <summary>
|
||||
/// 收集器的GUID
|
||||
/// </summary>
|
||||
public string CollectorGUID = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 收集器类型
|
||||
/// </summary>
|
||||
public ECollectorType CollectorType = ECollectorType.MainAssetCollector;
|
||||
/// <summary>
|
||||
/// 收集器类型
|
||||
/// </summary>
|
||||
public ECollectorType CollectorType = ECollectorType.MainAssetCollector;
|
||||
|
||||
/// <summary>
|
||||
/// 寻址规则类名
|
||||
/// </summary>
|
||||
public string AddressRuleName = nameof(AddressByFileName);
|
||||
/// <summary>
|
||||
/// 寻址规则类名
|
||||
/// </summary>
|
||||
public string AddressRuleName = nameof(AddressByFileName);
|
||||
|
||||
/// <summary>
|
||||
/// 打包规则类名
|
||||
/// </summary>
|
||||
public string PackRuleName = nameof(PackDirectory);
|
||||
/// <summary>
|
||||
/// 打包规则类名
|
||||
/// </summary>
|
||||
public string PackRuleName = nameof(PackDirectory);
|
||||
|
||||
/// <summary>
|
||||
/// 过滤规则类名
|
||||
/// </summary>
|
||||
public string FilterRuleName = nameof(CollectAll);
|
||||
/// <summary>
|
||||
/// 过滤规则类名
|
||||
/// </summary>
|
||||
public string FilterRuleName = nameof(CollectAll);
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
/// </summary>
|
||||
public string AssetTags = string.Empty;
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
/// </summary>
|
||||
public string AssetTags = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 用户自定义数据
|
||||
/// </summary>
|
||||
public string UserData = string.Empty;
|
||||
/// <summary>
|
||||
/// 用户自定义数据
|
||||
/// </summary>
|
||||
public string UserData = string.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 收集器是否有效
|
||||
/// </summary>
|
||||
public bool IsValid()
|
||||
{
|
||||
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
|
||||
return false;
|
||||
/// <summary>
|
||||
/// 收集器是否有效
|
||||
/// </summary>
|
||||
public bool IsValid()
|
||||
{
|
||||
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
|
||||
return false;
|
||||
|
||||
if (CollectorType == ECollectorType.None)
|
||||
return false;
|
||||
if (CollectorType == ECollectorType.None)
|
||||
return false;
|
||||
|
||||
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||
return false;
|
||||
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||
return false;
|
||||
|
||||
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
|
||||
return false;
|
||||
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
|
||||
return false;
|
||||
|
||||
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
|
||||
return false;
|
||||
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测配置错误
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
string assetGUID = AssetDatabase.AssetPathToGUID(CollectPath);
|
||||
if (string.IsNullOrEmpty(assetGUID))
|
||||
throw new Exception($"Invalid collect path : {CollectPath}");
|
||||
/// <summary>
|
||||
/// 检测配置错误
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
string assetGUID = AssetDatabase.AssetPathToGUID(CollectPath);
|
||||
if (string.IsNullOrEmpty(assetGUID))
|
||||
throw new Exception($"Invalid collect path : {CollectPath}");
|
||||
|
||||
if (CollectorType == ECollectorType.None)
|
||||
throw new Exception($"{nameof(ECollectorType)}.{ECollectorType.None} is invalid in collector : {CollectPath}");
|
||||
if (CollectorType == ECollectorType.None)
|
||||
throw new Exception($"{nameof(ECollectorType)}.{ECollectorType.None} is invalid in collector : {CollectPath}");
|
||||
|
||||
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName} in collector : {CollectPath}");
|
||||
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName} in collector : {CollectPath}");
|
||||
|
||||
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName} in collector : {CollectPath}");
|
||||
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName} in collector : {CollectPath}");
|
||||
|
||||
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}");
|
||||
}
|
||||
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修复配置错误
|
||||
/// </summary>
|
||||
public bool FixConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
/// <summary>
|
||||
/// 修复配置错误
|
||||
/// </summary>
|
||||
public bool FixConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
|
||||
if (string.IsNullOrEmpty(CollectorGUID) == false)
|
||||
{
|
||||
string convertAssetPath = AssetDatabase.GUIDToAssetPath(CollectorGUID);
|
||||
if (string.IsNullOrEmpty(convertAssetPath))
|
||||
{
|
||||
Debug.LogWarning($"Collector GUID {CollectorGUID} is invalid and has been auto removed !");
|
||||
CollectorGUID = string.Empty;
|
||||
isFixed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CollectPath != convertAssetPath)
|
||||
{
|
||||
CollectPath = convertAssetPath;
|
||||
isFixed = true;
|
||||
Debug.LogWarning($"Fix collect path : {CollectPath} -> {convertAssetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(CollectorGUID) == false)
|
||||
{
|
||||
string convertAssetPath = AssetDatabase.GUIDToAssetPath(CollectorGUID);
|
||||
if (string.IsNullOrEmpty(convertAssetPath))
|
||||
{
|
||||
Debug.LogWarning($"Collector GUID {CollectorGUID} is invalid and has been auto removed !");
|
||||
CollectorGUID = string.Empty;
|
||||
isFixed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CollectPath != convertAssetPath)
|
||||
{
|
||||
CollectPath = convertAssetPath;
|
||||
isFixed = true;
|
||||
Debug.LogWarning($"Fix collect path : {CollectPath} -> {convertAssetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
string convertGUID = AssetDatabase.AssetPathToGUID(CollectPath);
|
||||
if(string.IsNullOrEmpty(convertGUID) == false)
|
||||
{
|
||||
CollectorGUID = convertGUID;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
string convertGUID = AssetDatabase.AssetPathToGUID(CollectPath);
|
||||
if(string.IsNullOrEmpty(convertGUID) == false)
|
||||
{
|
||||
CollectorGUID = convertGUID;
|
||||
}
|
||||
*/
|
||||
|
||||
return isFixed;
|
||||
}
|
||||
return isFixed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group)
|
||||
{
|
||||
// 注意:模拟构建模式下只收集主资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group)
|
||||
{
|
||||
// 注意:模拟构建模式下只收集主资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
||||
|
||||
// 检测是否为原生资源打包规则
|
||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||
bool isRawFilePackRule = packRuleInstance.IsRawFilePackRule();
|
||||
// 收集打包资源路径
|
||||
List<string> findAssets =new List<string>();
|
||||
if (AssetDatabase.IsValidFolder(CollectPath))
|
||||
{
|
||||
string collectDirectory = CollectPath;
|
||||
string[] findResult = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
findAssets.AddRange(findResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
string assetPath = CollectPath;
|
||||
findAssets.Add(assetPath);
|
||||
}
|
||||
|
||||
// 检测原生资源包的收集器类型
|
||||
if (isRawFilePackRule && CollectorType != ECollectorType.MainAssetCollector)
|
||||
throw new Exception($"The raw file pack rule must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}");
|
||||
// 收集打包资源信息
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
var assetInfo = new AssetInfo(assetPath);
|
||||
if (IsValidateAsset(command, assetInfo) && IsCollectAsset(group, assetInfo))
|
||||
{
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetInfo);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(CollectPath))
|
||||
throw new Exception($"The collect path is null or empty in group : {group.GroupName}");
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
// 收集打包资源
|
||||
if (AssetDatabase.IsValidFolder(CollectPath))
|
||||
{
|
||||
string collectDirectory = CollectPath;
|
||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(group, assetPath))
|
||||
{
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawFilePackRule);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string assetPath = CollectPath;
|
||||
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(group, assetPath))
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawFilePackRule);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The collecting single asset file is invalid : {assetPath} in collector : {CollectPath}");
|
||||
}
|
||||
}
|
||||
if (address.StartsWith("Assets/") || address.StartsWith("assets/"))
|
||||
throw new Exception($"The address can not set asset path in collector : {CollectPath} \nAssetPath: {assetPath}");
|
||||
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} in collector : {CollectPath} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (address.StartsWith("Assets/") || address.StartsWith("assets/"))
|
||||
throw new Exception($"The address can not set asset path in collector : {CollectPath} \nAssetPath: {assetPath}");
|
||||
// 返回列表
|
||||
return result.Values.ToList();
|
||||
}
|
||||
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} in collector : {CollectPath} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 返回列表
|
||||
return result.Values.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建资源收集类
|
||||
/// </summary>
|
||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
string address = GetAddress(command, group, assetInfo);
|
||||
string bundleName = GetBundleName(command, group, assetInfo);
|
||||
List<string> assetTags = GetAssetTags(group);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetInfo, assetTags);
|
||||
|
||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath, bool isRawFilePackRule)
|
||||
{
|
||||
string address = GetAddress(command, group, assetPath);
|
||||
string bundleName = GetBundleName(command, group, assetPath);
|
||||
List<string> assetTags = GetAssetTags(group);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, isRawFilePackRule, assetTags);
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
collectAssetInfo.DependAssets = new List<AssetInfo>();
|
||||
else
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(command, assetInfo.AssetPath);
|
||||
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
collectAssetInfo.DependAssets = new List<string>();
|
||||
else
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
||||
return collectAssetInfo;
|
||||
}
|
||||
|
||||
return collectAssetInfo;
|
||||
}
|
||||
private bool IsValidateAsset(string assetPath, bool isRawFilePackRule)
|
||||
{
|
||||
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Invalid asset path : {assetPath}");
|
||||
return false;
|
||||
}
|
||||
private bool IsValidateAsset(CollectCommand command, AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 忽略文件夹
|
||||
if (AssetDatabase.IsValidFolder(assetPath))
|
||||
return false;
|
||||
// 忽略文件夹
|
||||
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
|
||||
return false;
|
||||
|
||||
// 忽略编辑器下的类型资源
|
||||
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(LightingDataAsset))
|
||||
return false;
|
||||
// 忽略编辑器下的类型资源
|
||||
if (assetInfo.AssetType == typeof(LightingDataAsset))
|
||||
return false;
|
||||
|
||||
// 检测原生文件是否合规
|
||||
if (isRawFilePackRule)
|
||||
{
|
||||
string extension = EditorTools.RemoveFirstChar(System.IO.Path.GetExtension(assetPath));
|
||||
if (extension == EAssetFileExtension.unity.ToString() || extension == EAssetFileExtension.prefab.ToString() ||
|
||||
extension == EAssetFileExtension.fbx.ToString() || extension == EAssetFileExtension.mat.ToString() ||
|
||||
extension == EAssetFileExtension.controller.ToString() || extension == EAssetFileExtension.anim.ToString() ||
|
||||
extension == EAssetFileExtension.ttf.ToString() || extension == EAssetFileExtension.shader.ToString())
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Raw file pack rule can not support file estension : {extension}");
|
||||
return false;
|
||||
}
|
||||
// 忽略Unity引擎无法识别的文件
|
||||
if (command.IgnoreDefaultType)
|
||||
{
|
||||
if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
|
||||
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无法识别的无效文件
|
||||
// 注意:只对非原生文件收集器处理
|
||||
if (assetType == typeof(UnityEditor.DefaultAsset))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (DefaultFilterRule.IsIgnoreFile(assetInfo.FileExtension))
|
||||
return false;
|
||||
|
||||
string fileExtension = System.IO.Path.GetExtension(assetPath);
|
||||
if (DefaultFilterRule.IsIgnoreFile(fileExtension))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
// 根据规则设置过滤资源文件
|
||||
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
|
||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
}
|
||||
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
if (command.EnableAddressable == false)
|
||||
return string.Empty;
|
||||
|
||||
return true;
|
||||
}
|
||||
private bool IsCollectAsset(AssetBundleCollectorGroup group, string assetPath)
|
||||
{
|
||||
// 根据规则设置过滤资源文件
|
||||
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
|
||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
}
|
||||
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
{
|
||||
if (command.EnableAddressable == false)
|
||||
return string.Empty;
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
return string.Empty;
|
||||
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
return string.Empty;
|
||||
IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
|
||||
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
return adressValue;
|
||||
}
|
||||
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
if (command.AutoCollectShaders)
|
||||
{
|
||||
if (assetInfo.IsShaderAsset())
|
||||
{
|
||||
// 获取着色器打包规则结果
|
||||
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
return shaderPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
|
||||
}
|
||||
}
|
||||
|
||||
IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
|
||||
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
return adressValue;
|
||||
}
|
||||
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
{
|
||||
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
{
|
||||
// 获取着色器打包规则结果
|
||||
PackRuleResult packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
return packRuleResult.GetMainBundleName(command.PackageName, command.UniqueBundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 获取其它资源打包规则结果
|
||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||
PackRuleResult packRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
return packRuleResult.GetMainBundleName(command.PackageName, command.UniqueBundleName);
|
||||
}
|
||||
}
|
||||
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||
{
|
||||
List<string> tags = EditorTools.StringToStringList(group.AssetTags, ';');
|
||||
List<string> temper = EditorTools.StringToStringList(AssetTags, ';');
|
||||
tags.AddRange(temper);
|
||||
return tags;
|
||||
}
|
||||
private List<string> GetAllDependencies(string mainAssetPath)
|
||||
{
|
||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
foreach (string assetPath in depends)
|
||||
{
|
||||
// 注意:排除主资源对象
|
||||
if (assetPath == mainAssetPath)
|
||||
continue;
|
||||
// 获取其它资源打包规则结果
|
||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||
PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
return defaultPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
|
||||
}
|
||||
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||
{
|
||||
List<string> tags = EditorTools.StringToStringList(group.AssetTags, ';');
|
||||
List<string> temper = EditorTools.StringToStringList(AssetTags, ';');
|
||||
tags.AddRange(temper);
|
||||
return tags;
|
||||
}
|
||||
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
{
|
||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||
List<AssetInfo> result = new List<AssetInfo>(depends.Length);
|
||||
foreach (string assetPath in depends)
|
||||
{
|
||||
// 注意:排除主资源对象
|
||||
if (assetPath == mainAssetPath)
|
||||
continue;
|
||||
|
||||
if (IsValidateAsset(assetPath, false))
|
||||
{
|
||||
result.Add(assetPath);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
AssetInfo assetInfo = new AssetInfo(assetPath);
|
||||
if (IsValidateAsset(command, assetInfo))
|
||||
result.Add(assetInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,381 +8,257 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleCollectorConfig
|
||||
{
|
||||
public const string ConfigVersion = "2.4";
|
||||
public class AssetBundleCollectorConfig
|
||||
{
|
||||
public const string ConfigVersion = "v2.0.0";
|
||||
|
||||
public const string XmlVersion = "Version";
|
||||
public const string XmlCommon = "Common";
|
||||
public const string XmlEnableAddressable = "AutoAddressable";
|
||||
public const string XmlLocationToLower = "LocationToLower";
|
||||
public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
|
||||
public const string XmlUniqueBundleName = "UniqueBundleName";
|
||||
public const string XmlShowPackageView = "ShowPackageView";
|
||||
public const string XmlShowEditorAlias = "ShowEditorAlias";
|
||||
public const string XmlVersion = "Version";
|
||||
public const string XmlCommon = "Common";
|
||||
|
||||
public const string XmlPackage = "Package";
|
||||
public const string XmlPackageName = "PackageName";
|
||||
public const string XmlPackageDesc = "PackageDesc";
|
||||
public const string XmlShowPackageView = "ShowPackageView";
|
||||
public const string XmlShowEditorAlias = "ShowEditorAlias";
|
||||
public const string XmlUniqueBundleName = "UniqueBundleName";
|
||||
|
||||
public const string XmlGroup = "Group";
|
||||
public const string XmlGroupActiveRule = "GroupActiveRule";
|
||||
public const string XmlGroupName = "GroupName";
|
||||
public const string XmlGroupDesc = "GroupDesc";
|
||||
public const string XmlPackage = "Package";
|
||||
public const string XmlPackageName = "PackageName";
|
||||
public const string XmlPackageDesc = "PackageDesc";
|
||||
public const string XmlEnableAddressable = "AutoAddressable";
|
||||
public const string XmlLocationToLower = "LocationToLower";
|
||||
public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
|
||||
public const string XmlIgnoreDefaultType = "IgnoreDefaultType";
|
||||
|
||||
public const string XmlCollector = "Collector";
|
||||
public const string XmlCollectPath = "CollectPath";
|
||||
public const string XmlCollectorGUID = "CollectGUID";
|
||||
public const string XmlCollectorType = "CollectType";
|
||||
public const string XmlAddressRule = "AddressRule";
|
||||
public const string XmlPackRule = "PackRule";
|
||||
public const string XmlFilterRule = "FilterRule";
|
||||
public const string XmlUserData = "UserData";
|
||||
public const string XmlAssetTags = "AssetTags";
|
||||
public const string XmlGroup = "Group";
|
||||
public const string XmlGroupActiveRule = "GroupActiveRule";
|
||||
public const string XmlGroupName = "GroupName";
|
||||
public const string XmlGroupDesc = "GroupDesc";
|
||||
|
||||
/// <summary>
|
||||
/// 导入XML配置表
|
||||
/// </summary>
|
||||
public static void ImportXmlConfig(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
throw new FileNotFoundException(filePath);
|
||||
public const string XmlCollector = "Collector";
|
||||
public const string XmlCollectPath = "CollectPath";
|
||||
public const string XmlCollectorGUID = "CollectGUID";
|
||||
public const string XmlCollectorType = "CollectType";
|
||||
public const string XmlAddressRule = "AddressRule";
|
||||
public const string XmlPackRule = "PackRule";
|
||||
public const string XmlFilterRule = "FilterRule";
|
||||
public const string XmlUserData = "UserData";
|
||||
public const string XmlAssetTags = "AssetTags";
|
||||
|
||||
if (Path.GetExtension(filePath) != ".xml")
|
||||
throw new Exception($"Only support xml : {filePath}");
|
||||
/// <summary>
|
||||
/// 导入XML配置表
|
||||
/// </summary>
|
||||
public static void ImportXmlConfig(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
throw new FileNotFoundException(filePath);
|
||||
|
||||
// 加载配置文件
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.Load(filePath);
|
||||
XmlElement root = xmlDoc.DocumentElement;
|
||||
if (Path.GetExtension(filePath) != ".xml")
|
||||
throw new Exception($"Only support xml : {filePath}");
|
||||
|
||||
// 读取配置版本
|
||||
string configVersion = root.GetAttribute(XmlVersion);
|
||||
if (configVersion != ConfigVersion)
|
||||
{
|
||||
if (UpdateXmlConfig(xmlDoc) == false)
|
||||
throw new Exception($"The config version update failed : {configVersion} -> {ConfigVersion}");
|
||||
else
|
||||
Debug.Log($"The config version update succeed : {configVersion} -> {ConfigVersion}");
|
||||
}
|
||||
// 加载配置文件
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.Load(filePath);
|
||||
XmlElement root = xmlDoc.DocumentElement;
|
||||
|
||||
// 读取公共配置
|
||||
bool enableAddressable = false;
|
||||
bool locationToLower = false;
|
||||
bool includeAssetGUID = false;
|
||||
bool uniqueBundleName = false;
|
||||
bool showPackageView = false;
|
||||
bool showEditorAlias = false;
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlEnableAddressable))
|
||||
enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
||||
if (commonElement.HasAttribute(XmlLocationToLower))
|
||||
locationToLower = commonElement.GetAttribute(XmlLocationToLower) == "True" ? true : false;
|
||||
if (commonElement.HasAttribute(XmlIncludeAssetGUID))
|
||||
includeAssetGUID = commonElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false;
|
||||
if (commonElement.HasAttribute(XmlUniqueBundleName))
|
||||
uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false;
|
||||
if (commonElement.HasAttribute(XmlShowPackageView))
|
||||
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
|
||||
if (commonElement.HasAttribute(XmlShowEditorAlias))
|
||||
showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false;
|
||||
}
|
||||
// 读取配置版本
|
||||
string configVersion = root.GetAttribute(XmlVersion);
|
||||
if (configVersion != ConfigVersion)
|
||||
{
|
||||
if (UpdateXmlConfig(xmlDoc) == false)
|
||||
throw new Exception($"The config version update failed : {configVersion} -> {ConfigVersion}");
|
||||
else
|
||||
Debug.Log($"The config version update succeed : {configVersion} -> {ConfigVersion}");
|
||||
}
|
||||
|
||||
// 读取包裹配置
|
||||
List<AssetBundleCollectorPackage> packages = new List<AssetBundleCollectorPackage>();
|
||||
var packageNodeList = root.GetElementsByTagName(XmlPackage);
|
||||
foreach (var packageNode in packageNodeList)
|
||||
{
|
||||
XmlElement packageElement = packageNode as XmlElement;
|
||||
if (packageElement.HasAttribute(XmlPackageName) == false)
|
||||
throw new Exception($"Not found attribute {XmlPackageName} in {XmlPackage}");
|
||||
if (packageElement.HasAttribute(XmlPackageDesc) == false)
|
||||
throw new Exception($"Not found attribute {XmlPackageDesc} in {XmlPackage}");
|
||||
// 读取公共配置
|
||||
bool uniqueBundleName = false;
|
||||
bool showPackageView = false;
|
||||
bool showEditorAlias = false;
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlShowPackageView))
|
||||
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
|
||||
if (commonElement.HasAttribute(XmlShowEditorAlias))
|
||||
showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false;
|
||||
if (commonElement.HasAttribute(XmlUniqueBundleName))
|
||||
uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false;
|
||||
}
|
||||
|
||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
||||
package.PackageName = packageElement.GetAttribute(XmlPackageName);
|
||||
package.PackageDesc = packageElement.GetAttribute(XmlPackageDesc);
|
||||
packages.Add(package);
|
||||
// 读取包裹配置
|
||||
List<AssetBundleCollectorPackage> packages = new List<AssetBundleCollectorPackage>();
|
||||
var packageNodeList = root.GetElementsByTagName(XmlPackage);
|
||||
foreach (var packageNode in packageNodeList)
|
||||
{
|
||||
XmlElement packageElement = packageNode as XmlElement;
|
||||
if (packageElement.HasAttribute(XmlPackageName) == false)
|
||||
throw new Exception($"Not found attribute {XmlPackageName} in {XmlPackage}");
|
||||
if (packageElement.HasAttribute(XmlPackageDesc) == false)
|
||||
throw new Exception($"Not found attribute {XmlPackageDesc} in {XmlPackage}");
|
||||
|
||||
// 读取分组配置
|
||||
var groupNodeList = packageElement.GetElementsByTagName(XmlGroup);
|
||||
foreach (var groupNode in groupNodeList)
|
||||
{
|
||||
XmlElement groupElement = groupNode as XmlElement;
|
||||
if (groupElement.HasAttribute(XmlGroupActiveRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlGroupActiveRule} in {XmlGroup}");
|
||||
if (groupElement.HasAttribute(XmlGroupName) == false)
|
||||
throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
|
||||
if (groupElement.HasAttribute(XmlGroupDesc) == false)
|
||||
throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
|
||||
if (groupElement.HasAttribute(XmlAssetTags) == false)
|
||||
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
|
||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
||||
package.PackageName = packageElement.GetAttribute(XmlPackageName);
|
||||
package.PackageDesc = packageElement.GetAttribute(XmlPackageDesc);
|
||||
package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
||||
package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false;
|
||||
package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false;
|
||||
package.IgnoreDefaultType = packageElement.GetAttribute(XmlIgnoreDefaultType) == "True" ? true : false;
|
||||
packages.Add(package);
|
||||
|
||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||
group.ActiveRuleName = groupElement.GetAttribute(XmlGroupActiveRule);
|
||||
group.GroupName = groupElement.GetAttribute(XmlGroupName);
|
||||
group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
|
||||
group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
|
||||
package.Groups.Add(group);
|
||||
// 读取分组配置
|
||||
var groupNodeList = packageElement.GetElementsByTagName(XmlGroup);
|
||||
foreach (var groupNode in groupNodeList)
|
||||
{
|
||||
XmlElement groupElement = groupNode as XmlElement;
|
||||
if (groupElement.HasAttribute(XmlGroupActiveRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlGroupActiveRule} in {XmlGroup}");
|
||||
if (groupElement.HasAttribute(XmlGroupName) == false)
|
||||
throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
|
||||
if (groupElement.HasAttribute(XmlGroupDesc) == false)
|
||||
throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
|
||||
if (groupElement.HasAttribute(XmlAssetTags) == false)
|
||||
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
|
||||
|
||||
// 读取收集器配置
|
||||
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
|
||||
foreach (var collectorNode in collectorNodeList)
|
||||
{
|
||||
XmlElement collectorElement = collectorNode as XmlElement;
|
||||
if (collectorElement.HasAttribute(XmlCollectPath) == false)
|
||||
throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlCollectorGUID) == false)
|
||||
throw new Exception($"Not found attribute {XmlCollectorGUID} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlCollectorType) == false)
|
||||
throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlAddressRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlPackRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlFilterRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlUserData) == false)
|
||||
throw new Exception($"Not found attribute {XmlUserData} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlAssetTags) == false)
|
||||
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
|
||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||
group.ActiveRuleName = groupElement.GetAttribute(XmlGroupActiveRule);
|
||||
group.GroupName = groupElement.GetAttribute(XmlGroupName);
|
||||
group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
|
||||
group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
|
||||
package.Groups.Add(group);
|
||||
|
||||
AssetBundleCollector collector = new AssetBundleCollector();
|
||||
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
|
||||
collector.CollectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
|
||||
collector.CollectorType = EditorTools.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
|
||||
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
|
||||
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
|
||||
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
|
||||
collector.UserData = collectorElement.GetAttribute(XmlUserData);
|
||||
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags);
|
||||
group.Collectors.Add(collector);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 读取收集器配置
|
||||
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
|
||||
foreach (var collectorNode in collectorNodeList)
|
||||
{
|
||||
XmlElement collectorElement = collectorNode as XmlElement;
|
||||
if (collectorElement.HasAttribute(XmlCollectPath) == false)
|
||||
throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlCollectorGUID) == false)
|
||||
throw new Exception($"Not found attribute {XmlCollectorGUID} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlCollectorType) == false)
|
||||
throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlAddressRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlPackRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlFilterRule) == false)
|
||||
throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlUserData) == false)
|
||||
throw new Exception($"Not found attribute {XmlUserData} in {XmlCollector}");
|
||||
if (collectorElement.HasAttribute(XmlAssetTags) == false)
|
||||
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
|
||||
|
||||
// 检测配置错误
|
||||
foreach (var package in packages)
|
||||
{
|
||||
package.CheckConfigError();
|
||||
}
|
||||
AssetBundleCollector collector = new AssetBundleCollector();
|
||||
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
|
||||
collector.CollectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
|
||||
collector.CollectorType = EditorTools.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
|
||||
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
|
||||
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
|
||||
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
|
||||
collector.UserData = collectorElement.GetAttribute(XmlUserData);
|
||||
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags);
|
||||
group.Collectors.Add(collector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存配置数据
|
||||
AssetBundleCollectorSettingData.ClearAll();
|
||||
AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
|
||||
AssetBundleCollectorSettingData.Setting.LocationToLower = locationToLower;
|
||||
AssetBundleCollectorSettingData.Setting.IncludeAssetGUID = includeAssetGUID;
|
||||
AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName;
|
||||
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
|
||||
AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias;
|
||||
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
|
||||
AssetBundleCollectorSettingData.SaveFile();
|
||||
Debug.Log($"导入配置完毕!");
|
||||
}
|
||||
// 检测配置错误
|
||||
foreach (var package in packages)
|
||||
{
|
||||
package.CheckConfigError();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出XML配置表
|
||||
/// </summary>
|
||||
public static void ExportXmlConfig(string savePath)
|
||||
{
|
||||
if (File.Exists(savePath))
|
||||
File.Delete(savePath);
|
||||
// 保存配置数据
|
||||
AssetBundleCollectorSettingData.ClearAll();
|
||||
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
|
||||
AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias;
|
||||
AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName;
|
||||
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
|
||||
AssetBundleCollectorSettingData.SaveFile();
|
||||
Debug.Log($"Asset bundle collector config import complete!");
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
sb.AppendLine("<root>");
|
||||
sb.AppendLine("</root>");
|
||||
/// <summary>
|
||||
/// 导出XML配置表
|
||||
/// </summary>
|
||||
public static void ExportXmlConfig(string savePath)
|
||||
{
|
||||
if (File.Exists(savePath))
|
||||
File.Delete(savePath);
|
||||
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(sb.ToString());
|
||||
XmlElement root = xmlDoc.DocumentElement;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
sb.AppendLine("<root>");
|
||||
sb.AppendLine("</root>");
|
||||
|
||||
// 设置配置版本
|
||||
root.SetAttribute(XmlVersion, ConfigVersion);
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(sb.ToString());
|
||||
XmlElement root = xmlDoc.DocumentElement;
|
||||
|
||||
// 设置公共配置
|
||||
var commonElement = xmlDoc.CreateElement(XmlCommon);
|
||||
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
|
||||
commonElement.SetAttribute(XmlLocationToLower, AssetBundleCollectorSettingData.Setting.LocationToLower.ToString());
|
||||
commonElement.SetAttribute(XmlIncludeAssetGUID, AssetBundleCollectorSettingData.Setting.IncludeAssetGUID.ToString());
|
||||
commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString());
|
||||
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
|
||||
commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString());
|
||||
root.AppendChild(commonElement);
|
||||
// 设置配置版本
|
||||
root.SetAttribute(XmlVersion, ConfigVersion);
|
||||
|
||||
// 设置Package配置
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
var packageElement = xmlDoc.CreateElement(XmlPackage);
|
||||
packageElement.SetAttribute(XmlPackageName, package.PackageName);
|
||||
packageElement.SetAttribute(XmlPackageDesc, package.PackageDesc);
|
||||
root.AppendChild(packageElement);
|
||||
// 设置公共配置
|
||||
var commonElement = xmlDoc.CreateElement(XmlCommon);
|
||||
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
|
||||
commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString());
|
||||
commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString());
|
||||
root.AppendChild(commonElement);
|
||||
|
||||
// 设置分组配置
|
||||
foreach (var group in package.Groups)
|
||||
{
|
||||
var groupElement = xmlDoc.CreateElement(XmlGroup);
|
||||
groupElement.SetAttribute(XmlGroupActiveRule, group.ActiveRuleName);
|
||||
groupElement.SetAttribute(XmlGroupName, group.GroupName);
|
||||
groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
|
||||
groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
|
||||
packageElement.AppendChild(groupElement);
|
||||
// 设置Package配置
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
var packageElement = xmlDoc.CreateElement(XmlPackage);
|
||||
packageElement.SetAttribute(XmlPackageName, package.PackageName);
|
||||
packageElement.SetAttribute(XmlPackageDesc, package.PackageDesc);
|
||||
packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString());
|
||||
packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString());
|
||||
packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString());
|
||||
packageElement.SetAttribute(XmlIgnoreDefaultType, package.IgnoreDefaultType.ToString());
|
||||
root.AppendChild(packageElement);
|
||||
|
||||
// 设置收集器配置
|
||||
foreach (var collector in group.Collectors)
|
||||
{
|
||||
var collectorElement = xmlDoc.CreateElement(XmlCollector);
|
||||
collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath);
|
||||
collectorElement.SetAttribute(XmlCollectorGUID, collector.CollectorGUID);
|
||||
collectorElement.SetAttribute(XmlCollectorType, collector.CollectorType.ToString());
|
||||
collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName);
|
||||
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
|
||||
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
|
||||
collectorElement.SetAttribute(XmlUserData, collector.UserData);
|
||||
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
|
||||
groupElement.AppendChild(collectorElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 设置分组配置
|
||||
foreach (var group in package.Groups)
|
||||
{
|
||||
var groupElement = xmlDoc.CreateElement(XmlGroup);
|
||||
groupElement.SetAttribute(XmlGroupActiveRule, group.ActiveRuleName);
|
||||
groupElement.SetAttribute(XmlGroupName, group.GroupName);
|
||||
groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
|
||||
groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
|
||||
packageElement.AppendChild(groupElement);
|
||||
|
||||
// 生成配置文件
|
||||
xmlDoc.Save(savePath);
|
||||
Debug.Log($"导出配置完毕!");
|
||||
}
|
||||
// 设置收集器配置
|
||||
foreach (var collector in group.Collectors)
|
||||
{
|
||||
var collectorElement = xmlDoc.CreateElement(XmlCollector);
|
||||
collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath);
|
||||
collectorElement.SetAttribute(XmlCollectorGUID, collector.CollectorGUID);
|
||||
collectorElement.SetAttribute(XmlCollectorType, collector.CollectorType.ToString());
|
||||
collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName);
|
||||
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
|
||||
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
|
||||
collectorElement.SetAttribute(XmlUserData, collector.UserData);
|
||||
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
|
||||
groupElement.AppendChild(collectorElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 升级XML配置表
|
||||
/// </summary>
|
||||
private static bool UpdateXmlConfig(XmlDocument xmlDoc)
|
||||
{
|
||||
XmlElement root = xmlDoc.DocumentElement;
|
||||
string configVersion = root.GetAttribute(XmlVersion);
|
||||
if (configVersion == ConfigVersion)
|
||||
return true;
|
||||
// 生成配置文件
|
||||
xmlDoc.Save(savePath);
|
||||
Debug.Log($"Asset bundle collector config export complete!");
|
||||
}
|
||||
|
||||
// 1.0 -> 2.0
|
||||
if (configVersion == "1.0")
|
||||
{
|
||||
// 添加公共元素属性
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlShowPackageView) == false)
|
||||
commonElement.SetAttribute(XmlShowPackageView, "False");
|
||||
}
|
||||
/// <summary>
|
||||
/// 升级XML配置表
|
||||
/// </summary>
|
||||
private static bool UpdateXmlConfig(XmlDocument xmlDoc)
|
||||
{
|
||||
XmlElement root = xmlDoc.DocumentElement;
|
||||
string configVersion = root.GetAttribute(XmlVersion);
|
||||
if (configVersion == ConfigVersion)
|
||||
return true;
|
||||
|
||||
// 添加包裹元素
|
||||
var packageElement = xmlDoc.CreateElement(XmlPackage);
|
||||
packageElement.SetAttribute(XmlPackageName, "DefaultPackage");
|
||||
packageElement.SetAttribute(XmlPackageDesc, string.Empty);
|
||||
root.AppendChild(packageElement);
|
||||
|
||||
// 获取所有分组元素
|
||||
var groupNodeList = root.GetElementsByTagName(XmlGroup);
|
||||
List<XmlElement> temper = new List<XmlElement>(groupNodeList.Count);
|
||||
foreach (var groupNode in groupNodeList)
|
||||
{
|
||||
XmlElement groupElement = groupNode as XmlElement;
|
||||
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
|
||||
foreach (var collectorNode in collectorNodeList)
|
||||
{
|
||||
XmlElement collectorElement = collectorNode as XmlElement;
|
||||
if (collectorElement.HasAttribute(XmlCollectorGUID) == false)
|
||||
collectorElement.SetAttribute(XmlCollectorGUID, string.Empty);
|
||||
}
|
||||
temper.Add(groupElement);
|
||||
}
|
||||
|
||||
// 将分组元素转移至包裹元素下
|
||||
foreach (var groupElement in temper)
|
||||
{
|
||||
root.RemoveChild(groupElement);
|
||||
packageElement.AppendChild(groupElement);
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.0");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
// 2.0 -> 2.1
|
||||
if (configVersion == "2.0")
|
||||
{
|
||||
// 添加公共元素属性
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlUniqueBundleName) == false)
|
||||
commonElement.SetAttribute(XmlUniqueBundleName, "False");
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.1");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
// 2.1 -> 2.2
|
||||
if (configVersion == "2.1")
|
||||
{
|
||||
// 添加公共元素属性
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlShowEditorAlias) == false)
|
||||
commonElement.SetAttribute(XmlShowEditorAlias, "False");
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.2");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
// 2.2 -> 2.3
|
||||
if (configVersion == "2.2")
|
||||
{
|
||||
// 获取所有分组元素
|
||||
var groupNodeList = root.GetElementsByTagName(XmlGroup);
|
||||
foreach (var groupNode in groupNodeList)
|
||||
{
|
||||
XmlElement groupElement = groupNode as XmlElement;
|
||||
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
|
||||
foreach (var collectorNode in collectorNodeList)
|
||||
{
|
||||
XmlElement collectorElement = collectorNode as XmlElement;
|
||||
if (collectorElement.HasAttribute(XmlUserData) == false)
|
||||
collectorElement.SetAttribute(XmlUserData, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.3");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
// 2.3 -> 2.4
|
||||
if (configVersion == "2.3")
|
||||
{
|
||||
// 获取所有分组元素
|
||||
var groupNodeList = root.GetElementsByTagName(XmlGroup);
|
||||
foreach (var groupNode in groupNodeList)
|
||||
{
|
||||
XmlElement groupElement = groupNode as XmlElement;
|
||||
if (groupElement.HasAttribute(XmlGroupActiveRule) == false)
|
||||
groupElement.SetAttribute(XmlGroupActiveRule, $"{nameof(EnableGroup)}");
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.4");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,118 +7,120 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class AssetBundleCollectorGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// 分组名称
|
||||
/// </summary>
|
||||
public string GroupName = string.Empty;
|
||||
[Serializable]
|
||||
public class AssetBundleCollectorGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// 分组名称
|
||||
/// </summary>
|
||||
public string GroupName = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 分组描述
|
||||
/// </summary>
|
||||
public string GroupDesc = string.Empty;
|
||||
/// <summary>
|
||||
/// 分组描述
|
||||
/// </summary>
|
||||
public string GroupDesc = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
/// </summary>
|
||||
public string AssetTags = string.Empty;
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
/// </summary>
|
||||
public string AssetTags = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 分组激活规则
|
||||
/// </summary>
|
||||
public string ActiveRuleName = nameof(EnableGroup);
|
||||
/// <summary>
|
||||
/// 分组激活规则
|
||||
/// </summary>
|
||||
public string ActiveRuleName = nameof(EnableGroup);
|
||||
|
||||
/// <summary>
|
||||
/// 分组的收集器列表
|
||||
/// </summary>
|
||||
public List<AssetBundleCollector> Collectors = new List<AssetBundleCollector>();
|
||||
/// <summary>
|
||||
/// 分组的收集器列表
|
||||
/// </summary>
|
||||
public List<AssetBundleCollector> Collectors = new List<AssetBundleCollector>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检测配置错误
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
|
||||
|
||||
// 当分组不是激活状态时,直接不进行检测
|
||||
if (ActiveRuleName == nameof(DisableGroup)) return;
|
||||
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 检测配置错误
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
|
||||
|
||||
/// <summary>
|
||||
/// 修复配置错误
|
||||
/// </summary>
|
||||
public bool FixConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
if (collector.FixConfigError())
|
||||
{
|
||||
isFixed = true;
|
||||
}
|
||||
}
|
||||
return isFixed;
|
||||
}
|
||||
// 检测分组是否激活
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||
if (activeRule.IsActiveGroup() == false)
|
||||
return;
|
||||
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
}
|
||||
}
|
||||
|
||||
// 检测分组是否激活
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||
if (activeRule.IsActiveGroup() == false)
|
||||
{
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 修复配置错误
|
||||
/// </summary>
|
||||
public bool FixConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
if (collector.FixConfigError())
|
||||
{
|
||||
isFixed = true;
|
||||
}
|
||||
}
|
||||
return isFixed;
|
||||
}
|
||||
|
||||
// 收集打包资源
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
var temper = collector.GetAllCollectAssets(command, this);
|
||||
foreach (var assetInfo in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
result.Add(assetInfo.AssetPath, assetInfo);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
// 检测分组是否激活
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||
if (activeRule.IsActiveGroup() == false)
|
||||
{
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} in group : {GroupName} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 收集打包资源
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
var temper = collector.GetAllCollectAssets(command, this);
|
||||
foreach (var collectAsset in temper)
|
||||
{
|
||||
if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
|
||||
result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath} in group : {GroupName}");
|
||||
}
|
||||
}
|
||||
|
||||
// 返回列表
|
||||
return result.Values.ToList();
|
||||
}
|
||||
}
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectAssetPair in result)
|
||||
{
|
||||
if (collectAssetPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectAssetPair.Value.Address;
|
||||
string assetPath = collectAssetPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} in group : {GroupName} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 返回列表
|
||||
return result.Values.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,123 +7,148 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class AssetBundleCollectorPackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName = string.Empty;
|
||||
[Serializable]
|
||||
public class AssetBundleCollectorPackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹描述
|
||||
/// </summary>
|
||||
public string PackageDesc = string.Empty;
|
||||
/// <summary>
|
||||
/// 包裹描述
|
||||
/// </summary>
|
||||
public string PackageDesc = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 分组列表
|
||||
/// </summary>
|
||||
public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址大小写不敏感
|
||||
/// </summary>
|
||||
public bool LocationToLower = false;
|
||||
|
||||
/// <summary>
|
||||
/// 包含资源GUID数据
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID = false;
|
||||
|
||||
/// <summary>
|
||||
/// 忽略Unity引擎无法识别的文件
|
||||
/// </summary>
|
||||
public bool IgnoreDefaultType = true;
|
||||
|
||||
/// <summary>
|
||||
/// 自动收集所有着色器(所有着色器存储在一个资源包内)
|
||||
/// </summary>
|
||||
public bool AutoCollectShaders = true;
|
||||
|
||||
/// <summary>
|
||||
/// 分组列表
|
||||
/// </summary>
|
||||
public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检测配置错误
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
group.CheckConfigError();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 检测配置错误
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
group.CheckConfigError();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修复配置错误
|
||||
/// </summary>
|
||||
public bool FixConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
if (group.FixConfigError())
|
||||
{
|
||||
isFixed = true;
|
||||
}
|
||||
}
|
||||
return isFixed;
|
||||
}
|
||||
/// <summary>
|
||||
/// 修复配置错误
|
||||
/// </summary>
|
||||
public bool FixConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
if (group.FixConfigError())
|
||||
{
|
||||
isFixed = true;
|
||||
}
|
||||
}
|
||||
return isFixed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
|
||||
// 收集打包资源
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
var temper = group.GetAllCollectAssets(command);
|
||||
foreach (var assetInfo in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
result.Add(assetInfo.AssetPath, assetInfo);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
|
||||
}
|
||||
}
|
||||
// 收集打包资源
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
var temper = group.GetAllCollectAssets(command);
|
||||
foreach (var collectAsset in temper)
|
||||
{
|
||||
if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
|
||||
result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 返回列表
|
||||
return result.Values.ToList();
|
||||
}
|
||||
// 返回列表
|
||||
return result.Values.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的资源标签
|
||||
/// </summary>
|
||||
public List<string> GetAllTags()
|
||||
{
|
||||
HashSet<string> result = new HashSet<string>();
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
List<string> groupTags = EditorTools.StringToStringList(group.AssetTags, ';');
|
||||
foreach (var tag in groupTags)
|
||||
{
|
||||
if (result.Contains(tag) == false)
|
||||
result.Add(tag);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有的资源标签
|
||||
/// </summary>
|
||||
public List<string> GetAllTags()
|
||||
{
|
||||
HashSet<string> result = new HashSet<string>();
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
List<string> groupTags = EditorTools.StringToStringList(group.AssetTags, ';');
|
||||
foreach (var tag in groupTags)
|
||||
{
|
||||
if (result.Contains(tag) == false)
|
||||
result.Add(tag);
|
||||
}
|
||||
|
||||
foreach (var collector in group.Collectors)
|
||||
{
|
||||
List<string> collectorTags = EditorTools.StringToStringList(collector.AssetTags, ';');
|
||||
foreach (var tag in collectorTags)
|
||||
{
|
||||
if (result.Contains(tag) == false)
|
||||
result.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.ToList();
|
||||
}
|
||||
}
|
||||
foreach (var collector in group.Collectors)
|
||||
{
|
||||
List<string> collectorTags = EditorTools.StringToStringList(collector.AssetTags, ';');
|
||||
foreach (var tag in collectorTags)
|
||||
{
|
||||
if (result.Contains(tag) == false)
|
||||
result.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,132 +6,125 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")]
|
||||
public class AssetBundleCollectorSetting : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示包裹列表视图
|
||||
/// </summary>
|
||||
public bool ShowPackageView = false;
|
||||
[CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")]
|
||||
public class AssetBundleCollectorSetting : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示包裹列表视图
|
||||
/// </summary>
|
||||
public bool ShowPackageView = false;
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable = false;
|
||||
/// <summary>
|
||||
/// 是否显示编辑器别名
|
||||
/// </summary>
|
||||
public bool ShowEditorAlias = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址大小写不敏感
|
||||
/// </summary>
|
||||
public bool LocationToLower = false;
|
||||
|
||||
/// <summary>
|
||||
/// 包含资源GUID数据
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示编辑器别名
|
||||
/// </summary>
|
||||
public bool ShowEditorAlias = false;
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 包裹列表
|
||||
/// </summary>
|
||||
public List<AssetBundleCollectorPackage> Packages = new List<AssetBundleCollectorPackage>();
|
||||
/// <summary>
|
||||
/// 包裹列表
|
||||
/// </summary>
|
||||
public List<AssetBundleCollectorPackage> Packages = new List<AssetBundleCollectorPackage>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有数据
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
ShowPackageView = false;
|
||||
EnableAddressable = false;
|
||||
LocationToLower = false;
|
||||
IncludeAssetGUID = false;
|
||||
UniqueBundleName = false;
|
||||
ShowEditorAlias = false;
|
||||
Packages.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
/// 清空所有数据
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
ShowPackageView = false;
|
||||
UniqueBundleName = false;
|
||||
ShowEditorAlias = false;
|
||||
Packages.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测包裹配置错误
|
||||
/// </summary>
|
||||
public void CheckPackageConfigError(string packageName)
|
||||
{
|
||||
var package = GetPackage(packageName);
|
||||
package.CheckConfigError();
|
||||
}
|
||||
/// <summary>
|
||||
/// 检测包裹配置错误
|
||||
/// </summary>
|
||||
public void CheckPackageConfigError(string packageName)
|
||||
{
|
||||
var package = GetPackage(packageName);
|
||||
package.CheckConfigError();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测所有配置错误
|
||||
/// </summary>
|
||||
public void CheckAllPackageConfigError()
|
||||
{
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
package.CheckConfigError();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 检测所有配置错误
|
||||
/// </summary>
|
||||
public void CheckAllPackageConfigError()
|
||||
{
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
package.CheckConfigError();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修复所有配置错误
|
||||
/// </summary>
|
||||
public bool FixAllPackageConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
if (package.FixConfigError())
|
||||
{
|
||||
isFixed = true;
|
||||
}
|
||||
}
|
||||
return isFixed;
|
||||
}
|
||||
/// <summary>
|
||||
/// 修复所有配置错误
|
||||
/// </summary>
|
||||
public bool FixAllPackageConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
if (package.FixConfigError())
|
||||
{
|
||||
isFixed = true;
|
||||
}
|
||||
}
|
||||
return isFixed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的资源标签
|
||||
/// </summary>
|
||||
public List<string> GetPackageAllTags(string packageName)
|
||||
{
|
||||
var package = GetPackage(packageName);
|
||||
return package.GetAllTags();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有的资源标签
|
||||
/// </summary>
|
||||
public List<string> GetPackageAllTags(string packageName)
|
||||
{
|
||||
var package = GetPackage(packageName);
|
||||
return package.GetAllTags();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹收集的资源文件
|
||||
/// </summary>
|
||||
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
throw new Exception("Build package name is null or empty !");
|
||||
/// <summary>
|
||||
/// 获取包裹收集的资源文件
|
||||
/// </summary>
|
||||
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
throw new Exception("Build package name is null or empty !");
|
||||
|
||||
var package = GetPackage(packageName);
|
||||
CollectCommand command = new CollectCommand(buildMode, packageName,
|
||||
EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
|
||||
CollectResult collectResult = new CollectResult(command);
|
||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||
return collectResult;
|
||||
}
|
||||
// 检测配置合法性
|
||||
var package = GetPackage(packageName);
|
||||
package.CheckConfigError();
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹类
|
||||
/// </summary>
|
||||
public AssetBundleCollectorPackage GetPackage(string packageName)
|
||||
{
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
if (package.PackageName == packageName)
|
||||
return package;
|
||||
}
|
||||
throw new Exception($"Not found package : {packageName}");
|
||||
}
|
||||
}
|
||||
// 创建资源收集命令
|
||||
CollectCommand command = new CollectCommand(buildMode, packageName,
|
||||
package.EnableAddressable,
|
||||
package.LocationToLower,
|
||||
package.IncludeAssetGUID,
|
||||
package.IgnoreDefaultType,
|
||||
package.AutoCollectShaders,
|
||||
UniqueBundleName);
|
||||
|
||||
// 获取收集的资源集合
|
||||
CollectResult collectResult = new CollectResult(command);
|
||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||
return collectResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹类
|
||||
/// </summary>
|
||||
public AssetBundleCollectorPackage GetPackage(string packageName)
|
||||
{
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
if (package.PackageName == packageName)
|
||||
return package;
|
||||
}
|
||||
throw new Exception($"Not found package : {packageName}");
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,440 +7,424 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleCollectorSettingData
|
||||
{
|
||||
private static readonly Dictionary<string, System.Type> _cacheActiveRuleTypes = new Dictionary<string, Type>();
|
||||
private static readonly Dictionary<string, IActiveRule> _cacheActiveRuleInstance = new Dictionary<string, IActiveRule>();
|
||||
public class AssetBundleCollectorSettingData
|
||||
{
|
||||
private static readonly Dictionary<string, System.Type> _cacheActiveRuleTypes = new Dictionary<string, Type>();
|
||||
private static readonly Dictionary<string, IActiveRule> _cacheActiveRuleInstance = new Dictionary<string, IActiveRule>();
|
||||
|
||||
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
|
||||
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
|
||||
|
||||
private static readonly Dictionary<string, System.Type> _cachePackRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IPackRule> _cachePackRuleInstance = new Dictionary<string, IPackRule>();
|
||||
private static readonly Dictionary<string, System.Type> _cachePackRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IPackRule> _cachePackRuleInstance = new Dictionary<string, IPackRule>();
|
||||
|
||||
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
|
||||
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
|
||||
|
||||
/// <summary>
|
||||
/// 配置数据是否被修改
|
||||
/// </summary>
|
||||
public static bool IsDirty { private set; get; } = false;
|
||||
/// <summary>
|
||||
/// 配置数据是否被修改
|
||||
/// </summary>
|
||||
public static bool IsDirty { private set; get; } = false;
|
||||
|
||||
|
||||
static AssetBundleCollectorSettingData()
|
||||
{
|
||||
// IPackRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cachePackRuleTypes.Clear();
|
||||
_cachePackRuleInstance.Clear();
|
||||
static AssetBundleCollectorSettingData()
|
||||
{
|
||||
// IPackRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cachePackRuleTypes.Clear();
|
||||
_cachePackRuleInstance.Clear();
|
||||
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(PackSeparately),
|
||||
typeof(PackDirectory),
|
||||
typeof(PackTopDirectory),
|
||||
typeof(PackCollector),
|
||||
typeof(PackGroup),
|
||||
typeof(PackRawFile),
|
||||
typeof(PackShaderVariants)
|
||||
};
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(PackSeparately),
|
||||
typeof(PackDirectory),
|
||||
typeof(PackTopDirectory),
|
||||
typeof(PackCollector),
|
||||
typeof(PackGroup),
|
||||
typeof(PackRawFile),
|
||||
typeof(PackShaderVariants)
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cachePackRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cachePackRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cachePackRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cachePackRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
|
||||
// IFilterRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheFilterRuleTypes.Clear();
|
||||
_cacheFilterRuleInstance.Clear();
|
||||
// IFilterRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheFilterRuleTypes.Clear();
|
||||
_cacheFilterRuleInstance.Clear();
|
||||
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(CollectAll),
|
||||
typeof(CollectScene),
|
||||
typeof(CollectPrefab),
|
||||
typeof(CollectSprite)
|
||||
};
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(CollectAll),
|
||||
typeof(CollectScene),
|
||||
typeof(CollectPrefab),
|
||||
typeof(CollectSprite)
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheFilterRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheFilterRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheFilterRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheFilterRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
|
||||
// IAddressRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheAddressRuleTypes.Clear();
|
||||
_cacheAddressRuleInstance.Clear();
|
||||
// IAddressRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheAddressRuleTypes.Clear();
|
||||
_cacheAddressRuleInstance.Clear();
|
||||
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(AddressByFileName),
|
||||
typeof(AddressByFilePath),
|
||||
typeof(AddressByFolderAndFileName),
|
||||
typeof(AddressByGroupAndFileName),
|
||||
typeof(AddressDisable)
|
||||
};
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(AddressByFileName),
|
||||
typeof(AddressByFolderAndFileName),
|
||||
typeof(AddressByGroupAndFileName),
|
||||
typeof(AddressDisable)
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheAddressRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheAddressRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheAddressRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheAddressRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
|
||||
// IActiveRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheActiveRuleTypes.Clear();
|
||||
_cacheActiveRuleInstance.Clear();
|
||||
// IActiveRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheActiveRuleTypes.Clear();
|
||||
_cacheActiveRuleInstance.Clear();
|
||||
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(EnableGroup),
|
||||
typeof(DisableGroup),
|
||||
};
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(EnableGroup),
|
||||
typeof(DisableGroup),
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheActiveRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheActiveRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AssetBundleCollectorSetting _setting = null;
|
||||
public static AssetBundleCollectorSetting Setting
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_setting == null)
|
||||
_setting = SettingLoader.LoadSettingData<AssetBundleCollectorSetting>();
|
||||
return _setting;
|
||||
}
|
||||
}
|
||||
private static AssetBundleCollectorSetting _setting = null;
|
||||
public static AssetBundleCollectorSetting Setting
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_setting == null)
|
||||
_setting = SettingLoader.LoadSettingData<AssetBundleCollectorSetting>();
|
||||
return _setting;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 存储配置文件
|
||||
/// </summary>
|
||||
public static void SaveFile()
|
||||
{
|
||||
if (Setting != null)
|
||||
{
|
||||
IsDirty = false;
|
||||
EditorUtility.SetDirty(Setting);
|
||||
AssetDatabase.SaveAssets();
|
||||
Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 存储配置文件
|
||||
/// </summary>
|
||||
public static void SaveFile()
|
||||
{
|
||||
if (Setting != null)
|
||||
{
|
||||
IsDirty = false;
|
||||
EditorUtility.SetDirty(Setting);
|
||||
AssetDatabase.SaveAssets();
|
||||
Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修复配置文件
|
||||
/// </summary>
|
||||
public static void FixFile()
|
||||
{
|
||||
bool isFixed = Setting.FixAllPackageConfigError();
|
||||
if (isFixed)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 修复配置文件
|
||||
/// </summary>
|
||||
public static void FixFile()
|
||||
{
|
||||
bool isFixed = Setting.FixAllPackageConfigError();
|
||||
if (isFixed)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有数据
|
||||
/// </summary>
|
||||
public static void ClearAll()
|
||||
{
|
||||
Setting.ClearAll();
|
||||
SaveFile();
|
||||
}
|
||||
/// <summary>
|
||||
/// 清空所有数据
|
||||
/// </summary>
|
||||
public static void ClearAll()
|
||||
{
|
||||
Setting.ClearAll();
|
||||
SaveFile();
|
||||
}
|
||||
|
||||
public static List<RuleDisplayName> GetActiveRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheActiveRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetAddressRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheAddressRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetPackRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cachePackRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetFilterRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheFilterRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
private static string GetRuleDisplayName(string name, Type type)
|
||||
{
|
||||
var attribute = DisplayNameAttributeHelper.GetAttribute<DisplayNameAttribute>(type);
|
||||
if (attribute != null && string.IsNullOrEmpty(attribute.DisplayName) == false)
|
||||
return attribute.DisplayName;
|
||||
else
|
||||
return name;
|
||||
}
|
||||
public static List<RuleDisplayName> GetActiveRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheActiveRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetAddressRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheAddressRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetPackRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cachePackRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetFilterRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheFilterRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
private static string GetRuleDisplayName(string name, Type type)
|
||||
{
|
||||
var attribute = DisplayNameAttributeHelper.GetAttribute<DisplayNameAttribute>(type);
|
||||
if (attribute != null && string.IsNullOrEmpty(attribute.DisplayName) == false)
|
||||
return attribute.DisplayName;
|
||||
else
|
||||
return name;
|
||||
}
|
||||
|
||||
public static bool HasActiveRuleName(string ruleName)
|
||||
{
|
||||
return _cacheActiveRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasAddressRuleName(string ruleName)
|
||||
{
|
||||
return _cacheAddressRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasPackRuleName(string ruleName)
|
||||
{
|
||||
return _cachePackRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasFilterRuleName(string ruleName)
|
||||
{
|
||||
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasActiveRuleName(string ruleName)
|
||||
{
|
||||
return _cacheActiveRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasAddressRuleName(string ruleName)
|
||||
{
|
||||
return _cacheAddressRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasPackRuleName(string ruleName)
|
||||
{
|
||||
return _cachePackRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasFilterRuleName(string ruleName)
|
||||
{
|
||||
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
||||
return instance;
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
||||
return instance;
|
||||
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IActiveRule)Activator.CreateInstance(type);
|
||||
_cacheActiveRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IActiveRule)}类型无效:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IAddressRule GetAddressRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
|
||||
return instance;
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IActiveRule)Activator.CreateInstance(type);
|
||||
_cacheActiveRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IActiveRule)} is invalid:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IAddressRule GetAddressRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
|
||||
return instance;
|
||||
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheAddressRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IAddressRule)Activator.CreateInstance(type);
|
||||
_cacheAddressRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IAddressRule)}类型无效:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IPackRule GetPackRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance))
|
||||
return instance;
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheAddressRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IAddressRule)Activator.CreateInstance(type);
|
||||
_cacheAddressRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IAddressRule)} is invalid:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IPackRule GetPackRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance))
|
||||
return instance;
|
||||
|
||||
// 如果不存在创建类的实例
|
||||
if (_cachePackRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IPackRule)Activator.CreateInstance(type);
|
||||
_cachePackRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IPackRule)}类型无效:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IFilterRule GetFilterRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheFilterRuleInstance.TryGetValue(ruleName, out IFilterRule instance))
|
||||
return instance;
|
||||
// 如果不存在创建类的实例
|
||||
if (_cachePackRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IPackRule)Activator.CreateInstance(type);
|
||||
_cachePackRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IPackRule)} is invalid:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IFilterRule GetFilterRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheFilterRuleInstance.TryGetValue(ruleName, out IFilterRule instance))
|
||||
return instance;
|
||||
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheFilterRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IFilterRule)Activator.CreateInstance(type);
|
||||
_cacheFilterRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IFilterRule)}类型无效:{ruleName}");
|
||||
}
|
||||
}
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheFilterRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IFilterRule)Activator.CreateInstance(type);
|
||||
_cacheFilterRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IFilterRule)} is invalid:{ruleName}");
|
||||
}
|
||||
}
|
||||
|
||||
// 公共参数编辑相关
|
||||
public static void ModifyPackageView(bool showPackageView)
|
||||
{
|
||||
Setting.ShowPackageView = showPackageView;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyAddressable(bool enableAddressable)
|
||||
{
|
||||
Setting.EnableAddressable = enableAddressable;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyLocationToLower(bool locationToLower)
|
||||
{
|
||||
Setting.LocationToLower = locationToLower;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyIncludeAssetGUID(bool includeAssetGUID)
|
||||
{
|
||||
Setting.IncludeAssetGUID = includeAssetGUID;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyUniqueBundleName(bool uniqueBundleName)
|
||||
{
|
||||
Setting.UniqueBundleName = uniqueBundleName;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyShowEditorAlias(bool showAlias)
|
||||
{
|
||||
Setting.ShowEditorAlias = showAlias;
|
||||
IsDirty = true;
|
||||
}
|
||||
// 公共参数编辑相关
|
||||
public static void ModifyShowPackageView(bool showPackageView)
|
||||
{
|
||||
Setting.ShowPackageView = showPackageView;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyShowEditorAlias(bool showAlias)
|
||||
{
|
||||
Setting.ShowEditorAlias = showAlias;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyUniqueBundleName(bool uniqueBundleName)
|
||||
{
|
||||
Setting.UniqueBundleName = uniqueBundleName;
|
||||
IsDirty = true;
|
||||
}
|
||||
|
||||
// 资源包裹编辑相关
|
||||
public static AssetBundleCollectorPackage CreatePackage(string packageName)
|
||||
{
|
||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
||||
package.PackageName = packageName;
|
||||
Setting.Packages.Add(package);
|
||||
IsDirty = true;
|
||||
return package;
|
||||
}
|
||||
public static void RemovePackage(AssetBundleCollectorPackage package)
|
||||
{
|
||||
if (Setting.Packages.Remove(package))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed remove package : {package.PackageName}");
|
||||
}
|
||||
}
|
||||
public static void ModifyPackage(AssetBundleCollectorPackage package)
|
||||
{
|
||||
if (package != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
// 资源包裹编辑相关
|
||||
public static AssetBundleCollectorPackage CreatePackage(string packageName)
|
||||
{
|
||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
||||
package.PackageName = packageName;
|
||||
Setting.Packages.Add(package);
|
||||
IsDirty = true;
|
||||
return package;
|
||||
}
|
||||
public static void RemovePackage(AssetBundleCollectorPackage package)
|
||||
{
|
||||
if (Setting.Packages.Remove(package))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed remove package : {package.PackageName}");
|
||||
}
|
||||
}
|
||||
public static void ModifyPackage(AssetBundleCollectorPackage package)
|
||||
{
|
||||
if (package != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 资源分组编辑相关
|
||||
public static AssetBundleCollectorGroup CreateGroup(AssetBundleCollectorPackage package, string groupName)
|
||||
{
|
||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||
group.GroupName = groupName;
|
||||
package.Groups.Add(group);
|
||||
IsDirty = true;
|
||||
return group;
|
||||
}
|
||||
public static void RemoveGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
|
||||
{
|
||||
if (package.Groups.Remove(group))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed remove group : {group.GroupName}");
|
||||
}
|
||||
}
|
||||
public static void ModifyGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
|
||||
{
|
||||
if (package != null && group != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
// 资源分组编辑相关
|
||||
public static AssetBundleCollectorGroup CreateGroup(AssetBundleCollectorPackage package, string groupName)
|
||||
{
|
||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||
group.GroupName = groupName;
|
||||
package.Groups.Add(group);
|
||||
IsDirty = true;
|
||||
return group;
|
||||
}
|
||||
public static void RemoveGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
|
||||
{
|
||||
if (package.Groups.Remove(group))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed remove group : {group.GroupName}");
|
||||
}
|
||||
}
|
||||
public static void ModifyGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
|
||||
{
|
||||
if (package != null && group != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 资源收集器编辑相关
|
||||
public static void CreateCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
group.Collectors.Add(collector);
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
if (group.Collectors.Remove(collector))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
|
||||
}
|
||||
}
|
||||
public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
if (group != null && collector != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
// 资源收集器编辑相关
|
||||
public static void CreateCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
group.Collectors.Add(collector);
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
if (group.Collectors.Remove(collector))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
|
||||
}
|
||||
}
|
||||
public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
if (group != null && collector != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的资源标签
|
||||
/// </summary>
|
||||
public static string GetPackageAllTags(string packageName)
|
||||
{
|
||||
var allTags = Setting.GetPackageAllTags(packageName);
|
||||
return string.Join(";", allTags);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有的资源标签
|
||||
/// </summary>
|
||||
public static string GetPackageAllTags(string packageName)
|
||||
{
|
||||
var allTags = Setting.GetPackageAllTags(packageName);
|
||||
return string.Join(";", allTags);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,22 +1,29 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
|
||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="修复" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="Export" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="Import" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="Fix" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
</uie:Toolbar>
|
||||
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); flex-direction: column; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
<ui:VisualElement name="HelpBoxContainer" style="flex-grow: 1;" />
|
||||
<ui:Button text="Settings" display-tooltip-when-elided="true" name="SettingsButton" />
|
||||
<ui:VisualElement name="PublicContainer1" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
|
||||
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Show Editor Alias" name="ShowEditorAlias" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Unique Bundle Name" name="UniqueBundleName" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:VisualElement name="GlobalSettingsContainer">
|
||||
<ui:Button text="Global Settings" name="GlobalSettingsButton" />
|
||||
<ui:VisualElement name="PublicContainer1">
|
||||
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Show Rule Alias" name="ShowRuleAlias" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Unique Bundle Name" name="UniqueBundleName" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="PublicContainer2" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
|
||||
<ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:VisualElement name="PackageSettingsContainer">
|
||||
<ui:Button text="Package Settings" display-tooltip-when-elided="true" name="PackageSettingsButton" />
|
||||
<ui:VisualElement name="PublicContainer2">
|
||||
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Ignore Default Type" name="IgnoreDefaultType" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShaders" value="true" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
|
||||
@@ -43,7 +50,7 @@
|
||||
<ui:VisualElement name="ActiveRuleContainer" style="height: 20px;" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
|
||||
<ui:TextField picking-mode="Ignore" label="Asset Tags" name="GroupTags" />
|
||||
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
|
||||
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
|
||||
</ui:VisualElement>
|
||||
|
@@ -3,52 +3,46 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class CollectAssetInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集器类型
|
||||
/// </summary>
|
||||
public ECollectorType CollectorType { private set; get; }
|
||||
public class CollectAssetInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集器类型
|
||||
/// </summary>
|
||||
public ECollectorType CollectorType { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public string BundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 可寻址地址
|
||||
/// </summary>
|
||||
public string Address { private set; get; }
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public string BundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
/// <summary>
|
||||
/// 可寻址地址
|
||||
/// </summary>
|
||||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原生资源
|
||||
/// </summary>
|
||||
public bool IsRawAsset { private set; get; }
|
||||
/// <summary>
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public AssetInfo AssetInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
/// </summary>
|
||||
public List<string> AssetTags { private set; get; }
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
/// </summary>
|
||||
public List<string> AssetTags { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的资源列表
|
||||
/// </summary>
|
||||
public List<string> DependAssets = new List<string>();
|
||||
/// <summary>
|
||||
/// 依赖的资源列表
|
||||
/// </summary>
|
||||
public List<AssetInfo> DependAssets = new List<AssetInfo>();
|
||||
|
||||
|
||||
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, bool isRawAsset, List<string> assetTags)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
BundleName = bundleName;
|
||||
Address = address;
|
||||
AssetPath = assetPath;
|
||||
IsRawAsset = isRawAsset;
|
||||
AssetTags = assetTags;
|
||||
}
|
||||
}
|
||||
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, AssetInfo assetInfo, List<string> assetTags)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
BundleName = bundleName;
|
||||
Address = address;
|
||||
AssetInfo = assetInfo;
|
||||
AssetTags = assetTags;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,56 +1,68 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class CollectCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode { private set; get; }
|
||||
public class CollectCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable { private set; get; }
|
||||
/// <summary>
|
||||
/// 忽略Unity引擎无法识别的文件
|
||||
/// </summary>
|
||||
public bool IgnoreDefaultType { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址大小写不敏感
|
||||
/// </summary>
|
||||
public bool LocationToLower { private set; get; }
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 包含资源GUID数据
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID { private set; get; }
|
||||
/// <summary>
|
||||
/// 资源定位地址大小写不敏感
|
||||
/// </summary>
|
||||
public bool LocationToLower { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName { private set; get; }
|
||||
/// <summary>
|
||||
/// 包含资源GUID数据
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 着色器统一全名称
|
||||
/// </summary>
|
||||
public string ShadersBundleName { private set; get; }
|
||||
/// <summary>
|
||||
/// 自动收集所有着色器
|
||||
/// </summary>
|
||||
public bool AutoCollectShaders { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 着色器统一全名称
|
||||
/// </summary>
|
||||
public string ShadersBundleName { private set; get; }
|
||||
|
||||
|
||||
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool locationToLower, bool includeAssetGUID, bool uniqueBundleName)
|
||||
{
|
||||
BuildMode = buildMode;
|
||||
PackageName = packageName;
|
||||
EnableAddressable = enableAddressable;
|
||||
LocationToLower = locationToLower;
|
||||
IncludeAssetGUID = includeAssetGUID;
|
||||
UniqueBundleName = uniqueBundleName;
|
||||
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool locationToLower, bool includeAssetGUID, bool ignoreDefaultType, bool autoCollectShaders, bool uniqueBundleName)
|
||||
{
|
||||
BuildMode = buildMode;
|
||||
PackageName = packageName;
|
||||
EnableAddressable = enableAddressable;
|
||||
LocationToLower = locationToLower;
|
||||
IncludeAssetGUID = includeAssetGUID;
|
||||
IgnoreDefaultType = ignoreDefaultType;
|
||||
AutoCollectShaders = autoCollectShaders;
|
||||
UniqueBundleName = uniqueBundleName;
|
||||
|
||||
// 着色器统一全名称
|
||||
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
ShadersBundleName = packRuleResult.GetMainBundleName(packageName, uniqueBundleName);
|
||||
}
|
||||
}
|
||||
// 着色器统一全名称
|
||||
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
ShadersBundleName = packRuleResult.GetBundleName(packageName, uniqueBundleName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,25 +3,25 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class CollectResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集命令
|
||||
/// </summary>
|
||||
public CollectCommand Command { private set; get; }
|
||||
public class CollectResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集命令
|
||||
/// </summary>
|
||||
public CollectCommand Command { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 收集的资源信息列表
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> CollectAssets { private set; get; }
|
||||
/// <summary>
|
||||
/// 收集的资源信息列表
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> CollectAssets { private set; get; }
|
||||
|
||||
public CollectResult(CollectCommand command)
|
||||
{
|
||||
Command = command;
|
||||
}
|
||||
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
|
||||
{
|
||||
CollectAssets = collectAssets;
|
||||
}
|
||||
}
|
||||
public CollectResult(CollectCommand command)
|
||||
{
|
||||
Command = command;
|
||||
}
|
||||
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
|
||||
{
|
||||
CollectAssets = collectAssets;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,14 +1,14 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源分组激活规则接口
|
||||
/// </summary>
|
||||
public interface IActiveRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否激活分组
|
||||
/// </summary>
|
||||
bool IsActiveGroup();
|
||||
}
|
||||
/// <summary>
|
||||
/// 资源分组激活规则接口
|
||||
/// </summary>
|
||||
public interface IActiveRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否激活分组
|
||||
/// </summary>
|
||||
bool IsActiveGroup();
|
||||
}
|
||||
}
|
@@ -1,27 +1,27 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public struct AddressRuleData
|
||||
{
|
||||
public string AssetPath;
|
||||
public string CollectPath;
|
||||
public string GroupName;
|
||||
public string UserData;
|
||||
public struct AddressRuleData
|
||||
{
|
||||
public string AssetPath;
|
||||
public string CollectPath;
|
||||
public string GroupName;
|
||||
public string UserData;
|
||||
|
||||
public AddressRuleData(string assetPath, string collectPath, string groupName, string userData)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
CollectPath = collectPath;
|
||||
GroupName = groupName;
|
||||
UserData = userData;
|
||||
}
|
||||
}
|
||||
public AddressRuleData(string assetPath, string collectPath, string groupName, string userData)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
CollectPath = collectPath;
|
||||
GroupName = groupName;
|
||||
UserData = userData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 寻址规则接口
|
||||
/// </summary>
|
||||
public interface IAddressRule
|
||||
{
|
||||
string GetAssetAddress(AddressRuleData data);
|
||||
}
|
||||
/// <summary>
|
||||
/// 寻址规则接口
|
||||
/// </summary>
|
||||
public interface IAddressRule
|
||||
{
|
||||
string GetAssetAddress(AddressRuleData data);
|
||||
}
|
||||
}
|
@@ -1,31 +1,31 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public struct FilterRuleData
|
||||
{
|
||||
public string AssetPath;
|
||||
public string CollectPath;
|
||||
public string GroupName;
|
||||
public string UserData;
|
||||
|
||||
public FilterRuleData(string assetPath, string collectPath, string groupName, string userData)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
CollectPath = collectPath;
|
||||
GroupName = groupName;
|
||||
UserData = userData;
|
||||
}
|
||||
}
|
||||
public struct FilterRuleData
|
||||
{
|
||||
public string AssetPath;
|
||||
public string CollectPath;
|
||||
public string GroupName;
|
||||
public string UserData;
|
||||
|
||||
/// <summary>
|
||||
/// 资源过滤规则接口
|
||||
/// </summary>
|
||||
public interface IFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否为收集资源
|
||||
/// </summary>
|
||||
/// <returns>如果收集该资源返回TRUE</returns>
|
||||
bool IsCollectAsset(FilterRuleData data);
|
||||
}
|
||||
public FilterRuleData(string assetPath, string collectPath, string groupName, string userData)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
CollectPath = collectPath;
|
||||
GroupName = groupName;
|
||||
UserData = userData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源过滤规则接口
|
||||
/// </summary>
|
||||
public interface IFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否为收集资源
|
||||
/// </summary>
|
||||
/// <returns>如果收集该资源返回TRUE</returns>
|
||||
bool IsCollectAsset(FilterRuleData data);
|
||||
}
|
||||
}
|
@@ -1,79 +1,78 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public struct PackRuleData
|
||||
{
|
||||
public string AssetPath;
|
||||
public string CollectPath;
|
||||
public string GroupName;
|
||||
public string UserData;
|
||||
public struct PackRuleData
|
||||
{
|
||||
public string AssetPath;
|
||||
public string CollectPath;
|
||||
public string GroupName;
|
||||
public string UserData;
|
||||
|
||||
public PackRuleData(string assetPath, string collectPath, string groupName, string userData)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
CollectPath = collectPath;
|
||||
GroupName = groupName;
|
||||
UserData = userData;
|
||||
}
|
||||
}
|
||||
public PackRuleData(string assetPath, string collectPath, string groupName, string userData)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
CollectPath = collectPath;
|
||||
GroupName = groupName;
|
||||
UserData = userData;
|
||||
}
|
||||
}
|
||||
|
||||
public struct PackRuleResult
|
||||
{
|
||||
private readonly string _bundleName;
|
||||
private readonly string _bundleExtension;
|
||||
public struct PackRuleResult
|
||||
{
|
||||
private readonly string _bundleName;
|
||||
private readonly string _bundleExtension;
|
||||
|
||||
public PackRuleResult(string bundleName, string bundleExtension)
|
||||
{
|
||||
_bundleName = bundleName;
|
||||
_bundleExtension = 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 bool IsValid()
|
||||
{
|
||||
return string.IsNullOrEmpty(_bundleName) == false && string.IsNullOrEmpty(_bundleExtension) == false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取共享资源包全名称
|
||||
/// </summary>
|
||||
public string GetShareBundleName(string packageName, bool uniqueBundleName)
|
||||
{
|
||||
// 注意:冗余的共享资源包名返回空
|
||||
if (string.IsNullOrEmpty(_bundleName) && string.IsNullOrEmpty(_bundleExtension))
|
||||
return string.Empty;
|
||||
/// <summary>
|
||||
/// 获取资源包全名称
|
||||
/// </summary>
|
||||
public string GetBundleName(string packageName, bool uniqueBundleName)
|
||||
{
|
||||
string fullName;
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').Replace(" ", "_").ToLower();
|
||||
if (uniqueBundleName)
|
||||
fullName = $"{packageName}_{bundleName}.{_bundleExtension}";
|
||||
else
|
||||
fullName = $"{bundleName}.{_bundleExtension}";
|
||||
return fullName.ToLower();
|
||||
}
|
||||
|
||||
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>
|
||||
public string GetShareBundleName(string packageName, bool uniqueBundleName)
|
||||
{
|
||||
string fullName;
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').Replace(" ", "_").ToLower();
|
||||
if (uniqueBundleName)
|
||||
fullName = $"{packageName}_share_{bundleName}.{_bundleExtension}";
|
||||
else
|
||||
fullName = $"share_{bundleName}.{_bundleExtension}";
|
||||
return fullName.ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源打包规则接口
|
||||
/// </summary>
|
||||
public interface IPackRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取打包规则结果
|
||||
/// </summary>
|
||||
PackRuleResult GetPackRuleResult(PackRuleData data);
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原生文件打包规则
|
||||
/// </summary>
|
||||
bool IsRawFilePackRule();
|
||||
}
|
||||
/// <summary>
|
||||
/// 资源打包规则接口
|
||||
/// </summary>
|
||||
public interface IPackRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取打包规则结果
|
||||
/// </summary>
|
||||
PackRuleResult GetPackRuleResult(PackRuleData data);
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 共享资源的打包规则
|
||||
/// </summary>
|
||||
public interface ISharedPackRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取打包规则结果
|
||||
/// </summary>
|
||||
PackRuleResult GetPackRuleResult(string assetPath);
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ed930b0cc1db1742b0a131ca476bd82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,21 +1,21 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[DisplayName("启用分组")]
|
||||
public class EnableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
[DisplayName("启用分组")]
|
||||
public class EnableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("禁用分组")]
|
||||
public class DisableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
[DisplayName("禁用分组")]
|
||||
public class DisableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,51 +2,42 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[DisplayName("定位地址: 禁用")]
|
||||
public class AddressDisable : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
[DisplayName("定位地址: 禁用")]
|
||||
public class AddressDisable : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("定位地址: 文件名")]
|
||||
public class AddressByFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
}
|
||||
}
|
||||
[DisplayName("定位地址: 文件名")]
|
||||
public class AddressByFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("定位地址: 文件路径")]
|
||||
public class AddressByFilePath : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
throw new System.Exception("可寻址模式下已经默认支持通过资源路径加载!");
|
||||
}
|
||||
}
|
||||
[DisplayName("定位地址: 分组名_文件名")]
|
||||
public class AddressByGroupAndFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
return $"{data.GroupName}_{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("定位地址: 分组名_文件名")]
|
||||
public class AddressByGroupAndFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
return $"{data.GroupName}_{fileName}";
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("定位地址: 文件夹名_文件名")]
|
||||
public class AddressByFolderAndFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
FileInfo fileInfo = new FileInfo(data.AssetPath);
|
||||
return $"{fileInfo.Directory.Name}_{fileName}";
|
||||
}
|
||||
}
|
||||
[DisplayName("定位地址: 文件夹名_文件名")]
|
||||
public class AddressByFolderAndFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
FileInfo fileInfo = new FileInfo(data.AssetPath);
|
||||
return $"{fileInfo.Directory.Name}_{fileName}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,76 +6,76 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class DefaultFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 忽略的文件类型
|
||||
/// </summary>
|
||||
private readonly static HashSet<string> _ignoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
|
||||
public class DefaultFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 忽略的文件类型
|
||||
/// </summary>
|
||||
private readonly static HashSet<string> _ignoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
|
||||
|
||||
/// <summary>
|
||||
/// 查询是否为忽略文件
|
||||
/// </summary>
|
||||
public static bool IsIgnoreFile(string fileExtension)
|
||||
{
|
||||
return _ignoreFileExtensions.Contains(fileExtension);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询是否为忽略文件
|
||||
/// </summary>
|
||||
public static bool IsIgnoreFile(string fileExtension)
|
||||
{
|
||||
return _ignoreFileExtensions.Contains(fileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集所有资源")]
|
||||
public class CollectAll : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
[DisplayName("收集所有资源")]
|
||||
public class CollectAll : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集场景")]
|
||||
public class CollectScene : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
}
|
||||
}
|
||||
[DisplayName("收集场景")]
|
||||
public class CollectScene : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集预制体")]
|
||||
public class CollectPrefab : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".prefab";
|
||||
}
|
||||
}
|
||||
[DisplayName("收集预制体")]
|
||||
public class CollectPrefab : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".prefab";
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集精灵类型的纹理")]
|
||||
public class CollectSprite : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
||||
if (mainAssetType == typeof(Texture2D))
|
||||
{
|
||||
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
|
||||
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
[DisplayName("收集精灵类型的纹理")]
|
||||
public class CollectSprite : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
||||
if (mainAssetType == typeof(Texture2D))
|
||||
{
|
||||
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
|
||||
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集着色器变种集合")]
|
||||
public class CollectShaderVariants : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".shadervariants";
|
||||
}
|
||||
}
|
||||
[DisplayName("收集着色器变种集合")]
|
||||
public class CollectShaderVariants : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".shadervariants";
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,193 +4,158 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class DefaultPackRule
|
||||
{
|
||||
/// <summary>
|
||||
/// AssetBundle文件的后缀名
|
||||
/// </summary>
|
||||
public const string AssetBundleFileExtension = "bundle";
|
||||
public class DefaultPackRule
|
||||
{
|
||||
/// <summary>
|
||||
/// AssetBundle文件的后缀名
|
||||
/// </summary>
|
||||
public const string AssetBundleFileExtension = "bundle";
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的后缀名
|
||||
/// </summary>
|
||||
public const string RawFileExtension = "rawfile";
|
||||
/// <summary>
|
||||
/// 原生文件的后缀名
|
||||
/// </summary>
|
||||
public const string RawFileExtension = "rawfile";
|
||||
|
||||
/// <summary>
|
||||
/// Unity着色器资源包名称
|
||||
/// </summary>
|
||||
public const string ShadersBundleName = "unityshaders";
|
||||
/// <summary>
|
||||
/// Unity着色器资源包名称
|
||||
/// </summary>
|
||||
public const string ShadersBundleName = "unityshaders";
|
||||
|
||||
|
||||
public static PackRuleResult CreateShadersPackRuleResult()
|
||||
{
|
||||
PackRuleResult result = new PackRuleResult(ShadersBundleName, AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public static PackRuleResult CreateShadersPackRuleResult()
|
||||
{
|
||||
PackRuleResult result = new PackRuleResult(ShadersBundleName, AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以文件路径作为资源包名
|
||||
/// 注意:每个文件独自打资源包
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 文件路径")]
|
||||
public class PackSeparately : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = PathUtility.RemoveExtension(data.AssetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 以文件路径作为资源包名
|
||||
/// 注意:每个文件独自打资源包
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 文件路径")]
|
||||
public class PackSeparately : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = PathUtility.RemoveExtension(data.AssetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 以父类文件夹路径作为资源包名
|
||||
/// 注意:文件夹下所有文件打进一个资源包
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 父类文件夹路径")]
|
||||
public class PackDirectory : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = Path.GetDirectoryName(data.AssetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以父类文件夹路径作为资源包名
|
||||
/// 注意:文件夹下所有文件打进一个资源包
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 父类文件夹路径")]
|
||||
public class PackDirectory : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = Path.GetDirectoryName(data.AssetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 以收集器路径下顶级文件夹为资源包名
|
||||
/// 注意:文件夹下所有文件打进一个资源包
|
||||
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 收集器下顶级文件夹路径")]
|
||||
public class PackTopDirectory : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string assetPath = data.AssetPath.Replace(data.CollectPath, string.Empty);
|
||||
assetPath = assetPath.TrimStart('/');
|
||||
string[] splits = assetPath.Split('/');
|
||||
if (splits.Length > 0)
|
||||
{
|
||||
if (Path.HasExtension(splits[0]))
|
||||
throw new Exception($"Not found root directory : {assetPath}");
|
||||
string bundleName = $"{data.CollectPath}/{splits[0]}";
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Not found root directory : {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 以收集器路径作为资源包名
|
||||
/// 注意:收集的所有文件打进一个资源包
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 收集器路径")]
|
||||
public class PackCollector : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName;
|
||||
string collectPath = data.CollectPath;
|
||||
if (AssetDatabase.IsValidFolder(collectPath))
|
||||
{
|
||||
bundleName = collectPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
bundleName = PathUtility.RemoveExtension(collectPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以收集器路径下顶级文件夹为资源包名
|
||||
/// 注意:文件夹下所有文件打进一个资源包
|
||||
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 收集器下顶级文件夹路径")]
|
||||
public class PackTopDirectory : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string assetPath = data.AssetPath.Replace(data.CollectPath, string.Empty);
|
||||
assetPath = assetPath.TrimStart('/');
|
||||
string[] splits = assetPath.Split('/');
|
||||
if (splits.Length > 0)
|
||||
{
|
||||
if (Path.HasExtension(splits[0]))
|
||||
throw new Exception($"Not found root directory : {assetPath}");
|
||||
string bundleName = $"{data.CollectPath}/{splits[0]}";
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Not found root directory : {assetPath}");
|
||||
}
|
||||
}
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 以分组名称作为资源包名
|
||||
/// 注意:收集的所有文件打进一个资源包
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 分组名称")]
|
||||
public class PackGroup : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = data.GroupName;
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以收集器路径作为资源包名
|
||||
/// 注意:收集的所有文件打进一个资源包
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 收集器路径")]
|
||||
public class PackCollector : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName;
|
||||
string collectPath = data.CollectPath;
|
||||
if (AssetDatabase.IsValidFolder(collectPath))
|
||||
{
|
||||
bundleName = collectPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
bundleName = PathUtility.RemoveExtension(collectPath);
|
||||
}
|
||||
/// <summary>
|
||||
/// 打包原生文件
|
||||
/// </summary>
|
||||
[DisplayName("打包原生文件")]
|
||||
public class PackRawFile : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = data.AssetPath;
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.RawFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以分组名称作为资源包名
|
||||
/// 注意:收集的所有文件打进一个资源包
|
||||
/// </summary>
|
||||
[DisplayName("资源包名: 分组名称")]
|
||||
public class PackGroup : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = data.GroupName;
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打包原生文件
|
||||
/// </summary>
|
||||
[DisplayName("打包原生文件")]
|
||||
public class PackRawFile : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
string bundleName = data.AssetPath;
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.RawFileExtension);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打包着色器变种集合
|
||||
/// </summary>
|
||||
[DisplayName("打包着色器变种集合文件")]
|
||||
public class PackShaderVariants : IPackRule
|
||||
{
|
||||
public PackRuleResult GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
return DefaultPackRule.CreateShadersPackRuleResult();
|
||||
}
|
||||
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 打包着色器变种集合
|
||||
/// </summary>
|
||||
[DisplayName("打包着色器变种集合文件")]
|
||||
public class PackShaderVariants : IPackRule
|
||||
{
|
||||
public PackRuleResult GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
return DefaultPackRule.CreateShadersPackRuleResult();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 零冗余的共享资源打包规则
|
||||
/// </summary>
|
||||
public class ZeroRedundancySharedPackRule : ISharedPackRule
|
||||
{
|
||||
public PackRuleResult GetPackRuleResult(string assetPath)
|
||||
{
|
||||
string bundleName = Path.GetDirectoryName(assetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部冗余的共享资源打包规则
|
||||
/// </summary>
|
||||
public class FullRedundancySharedPackRule : ISharedPackRule
|
||||
{
|
||||
public PackRuleResult GetPackRuleResult(string assetPath)
|
||||
{
|
||||
PackRuleResult result = new PackRuleResult(string.Empty, string.Empty);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b8606481370397489cb3aa21e726d9a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -3,34 +3,34 @@ using System.Reflection;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器显示名字
|
||||
/// </summary>
|
||||
public class DisplayNameAttribute : Attribute
|
||||
{
|
||||
public string DisplayName;
|
||||
/// <summary>
|
||||
/// 编辑器显示名字
|
||||
/// </summary>
|
||||
public class DisplayNameAttribute : Attribute
|
||||
{
|
||||
public string DisplayName;
|
||||
|
||||
public DisplayNameAttribute(string name)
|
||||
{
|
||||
this.DisplayName = name;
|
||||
}
|
||||
}
|
||||
public DisplayNameAttribute(string name)
|
||||
{
|
||||
this.DisplayName = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DisplayNameAttributeHelper
|
||||
{
|
||||
internal static T GetAttribute<T>(Type type) where T : Attribute
|
||||
{
|
||||
return (T)type.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
public static class DisplayNameAttributeHelper
|
||||
{
|
||||
internal static T GetAttribute<T>(Type type) where T : Attribute
|
||||
{
|
||||
return (T)type.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
|
||||
internal static T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
|
||||
{
|
||||
return (T)methodInfo.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
internal static T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
|
||||
{
|
||||
return (T)methodInfo.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
|
||||
internal static T GetAttribute<T>(FieldInfo field) where T : Attribute
|
||||
{
|
||||
return (T)field.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
}
|
||||
internal static T GetAttribute<T>(FieldInfo field) where T : Attribute
|
||||
{
|
||||
return (T)field.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,28 +2,28 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public enum ECollectorType
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
|
||||
/// </summary>
|
||||
MainAssetCollector,
|
||||
[Serializable]
|
||||
public enum ECollectorType
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
|
||||
/// </summary>
|
||||
MainAssetCollector,
|
||||
|
||||
/// <summary>
|
||||
/// 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||
/// </summary>
|
||||
StaticAssetCollector,
|
||||
/// <summary>
|
||||
/// 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||
/// </summary>
|
||||
StaticAssetCollector,
|
||||
|
||||
/// <summary>
|
||||
/// 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||
/// 注意:如果依赖资源对象没有被主资源对象引用,则不参与打包构建。
|
||||
/// </summary>
|
||||
DependAssetCollector,
|
||||
/// <summary>
|
||||
/// 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||
/// 注意:如果依赖资源对象没有被主资源对象引用,则不参与打包构建。
|
||||
/// </summary>
|
||||
DependAssetCollector,
|
||||
|
||||
/// <summary>
|
||||
/// 该收集器类型不能被设置
|
||||
/// </summary>
|
||||
None,
|
||||
}
|
||||
/// <summary>
|
||||
/// 该收集器类型不能被设置
|
||||
/// </summary>
|
||||
None,
|
||||
}
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class RuleDisplayName
|
||||
{
|
||||
public string ClassName;
|
||||
public string DisplayName;
|
||||
}
|
||||
public class RuleDisplayName
|
||||
{
|
||||
public string ClassName;
|
||||
public string DisplayName;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user