diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs
index 8615626..c42d344 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs
@@ -202,6 +202,7 @@ namespace YooAsset.Editor
buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = _buildTarget;
buildParameters.BuildVersion = _buildVersionField.value;
+ buildParameters.EnableAddressable = AssetBundleGrouperSettingData.Setting.EnableAddressable;
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
buildParameters.AppendFileExtension = _appendExtensionToggle.value;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
index 80f3c77..3e1f53e 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
@@ -11,6 +11,11 @@ namespace YooAsset.Editor
///
public string BundleName { private set; get; }
+ ///
+ /// 可寻址地址
+ ///
+ public string Address { private set; get; }
+
///
/// 资源路径
///
@@ -53,8 +58,9 @@ namespace YooAsset.Editor
public List AllDependAssetInfos { private set; get; }
- public BuildAssetInfo(string assetPath, bool isRawAsset, bool notWriteToAssetList)
+ public BuildAssetInfo(string address, string assetPath, bool isRawAsset, bool notWriteToAssetList)
{
+ Address = address;
AssetPath = assetPath;
IsRawAsset = isRawAsset;
NotWriteToAssetList = notWriteToAssetList;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs
index 598dcf7..c12fc52 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs
@@ -26,7 +26,7 @@ namespace YooAsset.Editor
{
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
{
- var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList);
+ var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList);
buildAssetInfo.SetBundleName(collectAssetInfo.BundleName);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
@@ -100,7 +100,7 @@ namespace YooAsset.Editor
var buildAssetInfo = pair.Value;
if (buildAssetInfo.BundleNameIsValid() == false)
{
- string shaderBundleName = AssetBundleCollector.CollectShaderBundleName(buildAssetInfo.AssetPath);
+ string shaderBundleName = AssetBundleGrouperSettingHelper.CollectShaderBundleName(buildAssetInfo.AssetPath);
if (string.IsNullOrEmpty(shaderBundleName) == false)
{
buildAssetInfo.SetBundleName(shaderBundleName);
@@ -108,7 +108,7 @@ namespace YooAsset.Editor
else
{
string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath));
- bundleName = AssetBundleCollector.CorrectBundleName(bundleName, false);
+ bundleName = AssetBundleGrouperSettingHelper.CorrectBundleName(bundleName, false);
buildAssetInfo.SetBundleName(bundleName);
}
}
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
index b7d54a4..a7887fa 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
@@ -29,6 +29,11 @@ namespace YooAsset.Editor
///
public int BuildVersion;
+ ///
+ /// 启用可寻址资源定位
+ ///
+ public bool EnableAddressable = false;
+
///
/// 启用自动分包机制
/// 说明:自动分包机制可以实现资源零冗余
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs
index 4fb2ce6..9dbdbc9 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs
@@ -33,6 +33,11 @@ namespace YooAsset.Editor
///
public int BuildVersion;
+ ///
+ /// 启用可寻址资源定位
+ ///
+ public bool EnableAddressable;
+
///
/// 启用自动分包机制
///
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs
index a29a15e..7d4d9bd 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs
@@ -28,10 +28,11 @@ namespace YooAsset.Editor
// 创建新补丁清单
PatchManifest patchManifest = new PatchManifest();
+ patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable;
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags;
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
- patchManifest.AssetList = GetAllPatchAsset(buildMapContext, patchManifest);
+ patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
// 创建补丁清单文件
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
@@ -126,7 +127,8 @@ namespace YooAsset.Editor
///
/// 获取资源列表
///
- private List GetAllPatchAsset(BuildMapContext buildMapContext, PatchManifest patchManifest)
+ private List GetAllPatchAsset(AssetBundleBuilder.BuildParametersContext buildParameters,
+ BuildMapContext buildMapContext, PatchManifest patchManifest)
{
List result = new List(1000);
foreach (var bundleInfo in buildMapContext.BundleInfos)
@@ -135,6 +137,10 @@ namespace YooAsset.Editor
foreach (var assetInfo in assetInfos)
{
PatchAsset patchAsset = new PatchAsset();
+ if (buildParameters.Parameters.EnableAddressable)
+ patchAsset.Address = assetInfo.Address;
+ else
+ patchAsset.Address = string.Empty;
patchAsset.AssetPath = assetInfo.AssetPath;
patchAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, patchManifest);
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs
index 703607a..f3c0c14 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs
@@ -29,6 +29,7 @@ namespace YooAsset.Editor
buildReport.Summary.BuildSeconds = buildParameters.GetBuildingSeconds();
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
+ buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.AutoCollectShaders = AssetBundleGrouperSettingData.Setting.AutoCollectShaders;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
index fb0431b..3ef2fed 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
if (isRawFile)
{
if (bundleInfo.BuildinAssets.Count != 1)
- throw new Exception("The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
+ throw new Exception($"The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
continue;
}
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs
index 895ebcb..f185ebf 100644
--- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs
@@ -14,6 +14,11 @@ namespace YooAsset.Editor
///
public string CollectPath = string.Empty;
+ ///
+ /// 寻址规则类名
+ ///
+ public string AddressRuleName = string.Empty;
+
///
/// 打包规则类名
///
@@ -24,6 +29,7 @@ namespace YooAsset.Editor
///
public string FilterRuleName = string.Empty;
+
///
/// 不写入资源列表
///
@@ -34,9 +40,22 @@ namespace YooAsset.Editor
///
public string AssetTags = string.Empty;
- [NonSerialized]
- public object UserData;
+ ///
+ /// 收集器是否有效
+ ///
+ public bool IsValid()
+ {
+ if (AssetDatabase.LoadAssetAtPath(CollectPath) == null)
+ return false;
+ if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false)
+ return false;
+ if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false)
+ return false;
+ if (AssetBundleGrouperSettingData.HasAddressRuleName(AddressRuleName) == false)
+ return false;
+ return true;
+ }
///
/// 检测配置错误
@@ -51,6 +70,9 @@ namespace YooAsset.Editor
if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false)
throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName}");
+
+ if (AssetBundleGrouperSettingData.HasAddressRuleName(AddressRuleName) == false)
+ throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName}");
}
///
@@ -58,6 +80,7 @@ namespace YooAsset.Editor
///
public List GetAllCollectAssets(AssetBundleGrouper grouper)
{
+ Dictionary adressTemper = new Dictionary(1000);
Dictionary result = new Dictionary(1000);
bool isRawAsset = PackRuleName == nameof(PackRawFile);
@@ -74,9 +97,10 @@ namespace YooAsset.Editor
continue;
if (result.ContainsKey(assetPath) == false)
{
+ string address = GetAddress(grouper, assetPath);
string bundleName = GetBundleName(grouper, assetPath, isRawAsset);
List assetTags = GetAssetTags(grouper);
- var collectAssetInfo = new CollectAssetInfo(bundleName, assetPath, assetTags, isRawAsset, NotWriteToAssetList);
+ var collectAssetInfo = new CollectAssetInfo(bundleName, address, assetPath, assetTags, isRawAsset, NotWriteToAssetList);
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
result.Add(assetPath, collectAssetInfo);
}
@@ -94,9 +118,10 @@ namespace YooAsset.Editor
if (isRawAsset && NotWriteToAssetList)
UnityEngine.Debug.LogWarning($"Are you sure raw file are not write to asset list : {assetPath}");
+ string address = GetAddress(grouper, assetPath);
string bundleName = GetBundleName(grouper, assetPath, isRawAsset);
List assetTags = GetAssetTags(grouper);
- var collectAssetInfo = new CollectAssetInfo(bundleName, assetPath, assetTags, isRawAsset, NotWriteToAssetList);
+ var collectAssetInfo = new CollectAssetInfo(bundleName, address, assetPath, assetTags, isRawAsset, NotWriteToAssetList);
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
result.Add(assetPath, collectAssetInfo);
}
@@ -106,10 +131,28 @@ namespace YooAsset.Editor
}
}
+ // 检测可寻址地址是否重复
+ if (AssetBundleGrouperSettingData.Setting.EnableAddressable)
+ {
+ foreach (var collectInfo in result)
+ {
+ string address = collectInfo.Value.Address;
+ if (adressTemper.ContainsKey(address) == false)
+ {
+ adressTemper.Add(address, address);
+ }
+ else
+ {
+ throw new Exception($"The address is existed : {address} in collector : {CollectPath}");
+ }
+ }
+ }
+
// 返回列表
return result.Values.ToList();
}
+
private bool IsValidateAsset(string assetPath)
{
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
@@ -143,9 +186,18 @@ namespace YooAsset.Editor
IFilterRule filterRuleInstance = AssetBundleGrouperSettingData.GetFilterRuleInstance(FilterRuleName);
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath));
}
+ private string GetAddress(AssetBundleGrouper grouper, string assetPath)
+ {
+ if (NotWriteToAssetList)
+ return assetPath;
+
+ IAddressRule addressRuleInstance = AssetBundleGrouperSettingData.GetAddressRuleInstance(AddressRuleName);
+ string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, grouper.GrouperName));
+ return adressValue;
+ }
private string GetBundleName(AssetBundleGrouper grouper, string assetPath, bool isRawAsset)
{
- string shaderBundleName = CollectShaderBundleName(assetPath);
+ string shaderBundleName = AssetBundleGrouperSettingHelper.CollectShaderBundleName(assetPath);
if (string.IsNullOrEmpty(shaderBundleName) == false)
return shaderBundleName;
@@ -153,7 +205,7 @@ namespace YooAsset.Editor
{
IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName);
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName));
- return CorrectBundleName(bundleName, isRawAsset);
+ return AssetBundleGrouperSettingHelper.CorrectBundleName(bundleName, isRawAsset);
}
}
private List GetAssetTags(AssetBundleGrouper grouper)
@@ -178,40 +230,5 @@ namespace YooAsset.Editor
}
return result;
}
-
- ///
- /// 收集着色器的资源包名称
- ///
- public static string CollectShaderBundleName(string assetPath)
- {
- // 如果自动收集所有的着色器
- if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders)
- {
- System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
- if (assetType == typeof(UnityEngine.Shader))
- {
- string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
- return CorrectBundleName(bundleName, false);
- }
- }
- return null;
- }
-
- ///
- /// 修正资源包名称
- ///
- public static string CorrectBundleName(string bundleName, bool isRawBundle)
- {
- if (isRawBundle)
- {
- string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.RawFileVariant}";
- return EditorTools.GetRegularPath(fullName).ToLower();
- }
- else
- {
- string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
- return EditorTools.GetRegularPath(fullName).ToLower(); ;
- }
- }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs
index 7046ac2..7d9e3fd 100644
--- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs
@@ -36,7 +36,7 @@ namespace YooAsset.Editor
///
public void CheckConfigError()
{
- foreach(var collector in Collectors)
+ foreach (var collector in Collectors)
{
collector.CheckConfigError();
}
@@ -47,13 +47,14 @@ namespace YooAsset.Editor
///
public List GetAllCollectAssets()
{
+ Dictionary adressTemper = new Dictionary(10000);
Dictionary result = new Dictionary(10000);
- foreach(var collector in Collectors)
+ foreach (var collector in Collectors)
{
var temper = collector.GetAllCollectAssets(this);
- foreach(var assetInfo in temper)
+ foreach (var assetInfo in temper)
{
- if(result.ContainsKey(assetInfo.AssetPath) == false)
+ if (result.ContainsKey(assetInfo.AssetPath) == false)
{
result.Add(assetInfo.AssetPath, assetInfo);
}
@@ -63,6 +64,24 @@ namespace YooAsset.Editor
}
}
}
+
+ // 检测可寻址地址是否重复
+ if (AssetBundleGrouperSettingData.Setting.EnableAddressable)
+ {
+ foreach (var collectInfo in result)
+ {
+ string address = collectInfo.Value.Address;
+ if (adressTemper.ContainsKey(address) == false)
+ {
+ adressTemper.Add(address, address);
+ }
+ else
+ {
+ throw new Exception($"The address is existed : {address} in grouper : {GrouperName}");
+ }
+ }
+ }
+
return result.Values.ToList();
}
}
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperConfig.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperConfig.cs
index c0cb7ef..ffd4ccf 100644
--- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperConfig.cs
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperConfig.cs
@@ -18,6 +18,7 @@ namespace YooAsset.Editor
public const string XmlGrouperDesc = "GrouperDesc";
public const string XmlCollector = "Collector";
public const string XmlDirectory = "CollectPath";
+ public const string XmlAddressRule = "AddressRule";
public const string XmlPackRule = "PackRule";
public const string XmlFilterRule = "FilterRule";
public const string XmlNotWriteToAssetList = "NotWriteToAssetList";
@@ -82,6 +83,8 @@ namespace YooAsset.Editor
XmlElement collectorElement = collectorNode as XmlElement;
if (collectorElement.HasAttribute(XmlDirectory) == false)
throw new Exception($"Not found attribute {XmlDirectory} 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)
@@ -93,6 +96,7 @@ namespace YooAsset.Editor
AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectorElement.GetAttribute(XmlDirectory);
+ collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
collector.NotWriteToAssetList = collectorElement.GetAttribute(XmlNotWriteToAssetList) == "True" ? true : false;
@@ -146,6 +150,7 @@ namespace YooAsset.Editor
{
var collectorElement = xmlDoc.CreateElement(XmlCollector);
collectorElement.SetAttribute(XmlDirectory, collector.CollectPath);
+ collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName);
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
collectorElement.SetAttribute(XmlNotWriteToAssetList, collector.NotWriteToAssetList.ToString());
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs
index fe3c4ac..de8e5af 100644
--- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs
@@ -8,6 +8,11 @@ namespace YooAsset.Editor
{
public class AssetBundleGrouperSetting : ScriptableObject
{
+ ///
+ /// 是否启用可寻址资源定位
+ ///
+ public bool EnableAddressable = false;
+
///
/// 自动收集着色器
///
@@ -40,6 +45,7 @@ namespace YooAsset.Editor
///
public List GetAllCollectAssets()
{
+ Dictionary adressTemper = new Dictionary(10000);
Dictionary result = new Dictionary(10000);
foreach (var grouper in Groupers)
{
@@ -56,6 +62,24 @@ namespace YooAsset.Editor
}
}
}
+
+ // 检测可寻址地址是否重复
+ if (EnableAddressable)
+ {
+ foreach (var collectInfo in result)
+ {
+ string address = collectInfo.Value.Address;
+ if (adressTemper.ContainsKey(address) == false)
+ {
+ adressTemper.Add(address, address);
+ }
+ else
+ {
+ throw new Exception($"The address is existed : {address}");
+ }
+ }
+ }
+
return result.Values.ToList();
}
}
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs
index 620dffb..9cc7d8a 100644
--- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs
@@ -9,6 +9,9 @@ namespace YooAsset.Editor
{
public class AssetBundleGrouperSettingData
{
+ private static readonly Dictionary _cacheAddressRuleTypes = new Dictionary();
+ private static readonly Dictionary _cacheAddressRuleInstance = new Dictionary();
+
private static readonly Dictionary _cachePackRuleTypes = new Dictionary();
private static readonly Dictionary _cachePackRuleInstance = new Dictionary();
@@ -32,6 +35,18 @@ namespace YooAsset.Editor
}
}
+ public static List GetAddressRuleNames()
+ {
+ if (_setting == null)
+ LoadSettingData();
+
+ List names = new List();
+ foreach (var pair in _cacheAddressRuleTypes)
+ {
+ names.Add(pair.Key);
+ }
+ return names;
+ }
public static List GetPackRuleNames()
{
if (_setting == null)
@@ -56,6 +71,15 @@ namespace YooAsset.Editor
}
return names;
}
+ public static bool HasAddressRuleName(string ruleName)
+ {
+ foreach (var pair in _cacheAddressRuleTypes)
+ {
+ if (pair.Key == ruleName)
+ return true;
+ }
+ return false;
+ }
public static bool HasPackRuleName(string ruleName)
{
foreach (var pair in _cachePackRuleTypes)
@@ -75,6 +99,7 @@ namespace YooAsset.Editor
return false;
}
+
///
/// 加载配置文件
///
@@ -148,6 +173,31 @@ namespace YooAsset.Editor
_cacheFilterRuleTypes.Add(type.Name, type);
}
}
+
+ // IAddressRule
+ {
+ // 清空缓存集合
+ _cacheAddressRuleTypes.Clear();
+ _cacheAddressRuleInstance.Clear();
+
+ // 获取所有类型
+ List types = new List(100)
+ {
+ typeof(AddressByFileName),
+ typeof(AddressByCollectorAndFileName),
+ typeof(AddressByGrouperAndFileName)
+ };
+
+ TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom();
+ var customTypes = collection.ToList();
+ 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);
+ }
+ }
}
///
@@ -176,6 +226,23 @@ namespace YooAsset.Editor
}
// 实例类相关
+ 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))
@@ -211,6 +278,13 @@ namespace YooAsset.Editor
}
}
+ // 可寻址编辑相关
+ public static void ModifyAddressable(bool enableAddressable)
+ {
+ Setting.EnableAddressable = enableAddressable;
+ IsDirty = true;
+ }
+
// 着色器编辑相关
public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName)
{
@@ -220,12 +294,10 @@ namespace YooAsset.Editor
}
// 资源分组编辑相关
- public static void CreateGrouper(string grouperName, string grouperDesc, string assetTags)
+ public static void CreateGrouper(string grouperName)
{
AssetBundleGrouper grouper = new AssetBundleGrouper();
grouper.GrouperName = grouperName;
- grouper.GrouperDesc = grouperDesc;
- grouper.AssetTags = assetTags;
Setting.Groupers.Add(grouper);
IsDirty = true;
}
@@ -249,13 +321,13 @@ namespace YooAsset.Editor
}
// 资源收集器编辑相关
- public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string packRuleName, string filterRuleName, bool notWriteToAssetList)
+ public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string addressRuleName, string packRuleName, string filterRuleName)
{
AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectPath;
+ collector.AddressRuleName = addressRuleName;
collector.PackRuleName = packRuleName;
collector.FilterRuleName = filterRuleName;
- collector.NotWriteToAssetList = notWriteToAssetList;
grouper.Collectors.Add(collector);
IsDirty = true;
}
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingHelper.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingHelper.cs
new file mode 100644
index 0000000..bac9b84
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingHelper.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.IO;
+using UnityEditor;
+
+namespace YooAsset.Editor
+{
+ public static class AssetBundleGrouperSettingHelper
+ {
+ ///
+ /// 收集着色器的资源包名称
+ ///
+ public static string CollectShaderBundleName(string assetPath)
+ {
+ // 如果自动收集所有的着色器
+ if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders)
+ {
+ System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
+ if (assetType == typeof(UnityEngine.Shader))
+ {
+ string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
+ return CorrectBundleName(bundleName, false);
+ }
+ }
+ return null;
+ }
+
+ ///
+ /// 修正资源包名称
+ ///
+ public static string CorrectBundleName(string bundleName, bool isRawBundle)
+ {
+ if (isRawBundle)
+ {
+ string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.RawFileVariant}";
+ return EditorTools.GetRegularPath(fullName).ToLower();
+ }
+ else
+ {
+ string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
+ return EditorTools.GetRegularPath(fullName).ToLower(); ;
+ }
+ }
+
+
+ #region 编辑器下运行时支持
+ private static readonly Dictionary _locationDic = new Dictionary(1000);
+
+ public static void InitEditorPlayMode(bool enableAddressable)
+ {
+ _locationDic.Clear();
+
+ if (enableAddressable)
+ {
+ var collectAssetList = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets();
+ foreach (var collectAsset in collectAssetList)
+ {
+ if (collectAsset.NotWriteToAssetList)
+ continue;
+
+ string address = collectAsset.Address;
+ if (_locationDic.ContainsKey(address))
+ UnityEngine.Debug.LogWarning($"Address have existed : {address}");
+ else
+ _locationDic.Add(address, collectAsset);
+ }
+ }
+ else
+ {
+ var collectAssetList = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets();
+ foreach (var collectAsset in collectAssetList)
+ {
+ if (collectAsset.NotWriteToAssetList)
+ continue;
+
+ // 添加原始路径
+ string assetPath = collectAsset.AssetPath;
+ if (_locationDic.ContainsKey(assetPath))
+ UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPath}");
+ else
+ _locationDic.Add(assetPath, collectAsset);
+
+ // 添加去掉后缀名的路径
+ if (Path.HasExtension(assetPath))
+ {
+ string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath);
+ if (_locationDic.ContainsKey(assetPathWithoutExtension))
+ UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPathWithoutExtension}");
+ else
+ _locationDic.Add(assetPathWithoutExtension, collectAsset);
+ }
+ }
+ }
+ }
+ public static string ConvertLocationToAssetPath(string location)
+ {
+ // 检测地址合法性
+ CheckLocation(location);
+
+ if (_locationDic.ContainsKey(location))
+ {
+ return _locationDic[location].AssetPath;
+ }
+ else
+ {
+ UnityEngine.Debug.LogWarning($"Not found asset in grouper setting : {location}");
+ return string.Empty;
+ }
+ }
+ private static void CheckLocation(string location)
+ {
+ if (string.IsNullOrEmpty(location))
+ {
+ UnityEngine.Debug.LogError("location param is null or empty!");
+ }
+ else
+ {
+ // 检查路径末尾是否有空格
+ int index = location.LastIndexOf(" ");
+ if (index != -1)
+ {
+ if (location.Length == index + 1)
+ UnityEngine.Debug.LogWarning($"Found blank character in location : \"{location}\"");
+ }
+
+ if (location.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
+ UnityEngine.Debug.LogWarning($"Found illegal character in location : \"{location}\"");
+ }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingHelper.cs.meta b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingHelper.cs.meta
new file mode 100644
index 0000000..7dc11b8
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingHelper.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f94918fa1ea63c34fa0e49fdad4119cf
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs
index b0dda56..b51b5f7 100644
--- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs
@@ -19,10 +19,12 @@ namespace YooAsset.Editor
window.minSize = new Vector2(800, 600);
}
+ private List _addressRuleList;
private List _packRuleList;
private List _filterRuleList;
private ListView _grouperListView;
private ScrollView _collectorScrollView;
+ private Toggle _enableAddressableToogle;
private Toggle _autoCollectShaderToogle;
private TextField _shaderBundleNameTxt;
private TextField _grouperNameTxt;
@@ -34,9 +36,10 @@ namespace YooAsset.Editor
{
Undo.undoRedoPerformed -= RefreshWindow;
Undo.undoRedoPerformed += RefreshWindow;
-
+
VisualElement root = this.rootVisualElement;
+ _addressRuleList = AssetBundleGrouperSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleGrouperSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames();
@@ -59,7 +62,12 @@ namespace YooAsset.Editor
var importBtn = root.Q
public string BundleName { private set; get; }
+ ///
+ /// 可寻址地址
+ ///
+ public string Address { private set; get; }
+
///
/// 资源路径
///
@@ -36,17 +41,10 @@ namespace YooAsset.Editor
public List DependAssets = new List();
- public CollectAssetInfo(string bundleName, string assetPath, List assetTags, bool isRawAsset, bool notWriteToAssetList)
+ public CollectAssetInfo(string bundleName, string address, string assetPath, List assetTags, bool isRawAsset, bool notWriteToAssetList)
{
BundleName = bundleName;
- AssetPath = assetPath;
- AssetTags = assetTags;
- IsRawAsset = isRawAsset;
- NotWriteToAssetList = notWriteToAssetList;
- }
- public CollectAssetInfo(string assetPath, List assetTags, bool isRawAsset, bool notWriteToAssetList)
- {
- BundleName = string.Empty;
+ Address = address;
AssetPath = assetPath;
AssetTags = assetTags;
IsRawAsset = isRawAsset;
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultAddressRule.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultAddressRule.cs
new file mode 100644
index 0000000..1dfef4b
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultAddressRule.cs
@@ -0,0 +1,40 @@
+using System.IO;
+
+namespace YooAsset.Editor
+{
+ ///
+ /// 以文件名为定位地址
+ ///
+ public class AddressByFileName : IAddressRule
+ {
+ string IAddressRule.GetAssetAddress(AddressRuleData data)
+ {
+ return Path.GetFileNameWithoutExtension(data.AssetPath);
+ }
+ }
+
+ ///
+ /// 以组名+文件名为定位地址
+ ///
+ public class AddressByGrouperAndFileName : IAddressRule
+ {
+ string IAddressRule.GetAssetAddress(AddressRuleData data)
+ {
+ string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
+ return $"{data.GrouperName}_{fileName}";
+ }
+ }
+
+ ///
+ /// 以收集器名+文件名为定位地址
+ ///
+ public class AddressByCollectorAndFileName : IAddressRule
+ {
+ string IAddressRule.GetAssetAddress(AddressRuleData data)
+ {
+ string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
+ string collectorName = Path.GetFileNameWithoutExtension(data.CollectPath);
+ return $"{collectorName}_{fileName}";
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultAddressRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultAddressRule.cs.meta
new file mode 100644
index 0000000..f846065
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultAddressRule.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6df37bfd87103a54ca60c0c467a5f33b
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/IAddressRule.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/IAddressRule.cs
new file mode 100644
index 0000000..ae2b2c5
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/IAddressRule.cs
@@ -0,0 +1,25 @@
+
+namespace YooAsset.Editor
+{
+ public struct AddressRuleData
+ {
+ public string AssetPath;
+ public string CollectPath;
+ public string GrouperName;
+
+ public AddressRuleData(string assetPath, string collectPath, string grouperName)
+ {
+ AssetPath = assetPath;
+ CollectPath = collectPath;
+ GrouperName = grouperName;
+ }
+ }
+
+ ///
+ /// 寻址规则接口
+ ///
+ public interface IAddressRule
+ {
+ string GetAssetAddress(AddressRuleData data);
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/IAddressRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleGrouper/IAddressRule.cs.meta
new file mode 100644
index 0000000..b54e10c
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleGrouper/IAddressRule.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 426a4ff47699b6844946329f54a89128
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs
index a0e55b9..e07f987 100644
--- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs
+++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs
@@ -67,6 +67,7 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("构建耗时", $"{buildReport.Summary.BuildSeconds}秒"));
_items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}"));
_items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}"));
+ _items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));
_items.Add(new ItemWrapper("启用自动分包机制", $"{buildReport.Summary.EnableAutoCollect}"));
_items.Add(new ItemWrapper("追加文件扩展名", $"{buildReport.Summary.AppendFileExtension}"));
_items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.AutoCollectShaders}"));
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs
index 3a4d905..aaa3868 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs
@@ -8,6 +8,7 @@ namespace YooAsset
internal sealed class BundledSceneProvider : BundledProvider
{
public readonly LoadSceneMode SceneMode;
+ private readonly string _sceneName;
private readonly bool _activateOnLoad;
private readonly int _priority;
private AsyncOperation _asyncOp;
@@ -25,6 +26,7 @@ namespace YooAsset
: base(scenePath, null)
{
SceneMode = sceneMode;
+ _sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
_activateOnLoad = activateOnLoad;
_priority = priority;
}
@@ -68,7 +70,7 @@ namespace YooAsset
// 2. 加载场景
if (Status == EStatus.Loading)
{
- _asyncOp = SceneManager.LoadSceneAsync(AssetName, SceneMode);
+ _asyncOp = SceneManager.LoadSceneAsync(_sceneName, SceneMode);
if (_asyncOp != null)
{
_asyncOp.allowSceneActivation = true;
@@ -78,7 +80,7 @@ namespace YooAsset
else
{
Status = EStatus.Fail;
- LastError = $"Failed to load scene : {AssetName}";
+ LastError = $"Failed to load scene : {_sceneName}";
YooLogger.Error(LastError);
InvokeCompletion();
}
@@ -89,7 +91,7 @@ namespace YooAsset
{
if (_asyncOp.isDone)
{
- SceneObject = SceneManager.GetSceneByName(AssetName);
+ SceneObject = SceneManager.GetSceneByName(_sceneName);
if (SceneObject.IsValid() && _activateOnLoad)
SceneManager.SetActiveScene(SceneObject);
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs
index a3e20d8..e06f712 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs
@@ -5,6 +5,11 @@ namespace YooAsset
[Serializable]
internal class PatchAsset
{
+ ///
+ /// 可寻址地址
+ ///
+ public string Address;
+
///
/// 资源路径
///
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
index 035f4f6..90aa164 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
@@ -12,6 +12,11 @@ namespace YooAsset
[Serializable]
internal class PatchManifest
{
+ ///
+ /// 启用可寻址资源定位
+ ///
+ public bool EnableAddressable;
+
///
/// 资源版本号
///
@@ -45,6 +50,12 @@ namespace YooAsset
[NonSerialized]
public readonly Dictionary Assets = new Dictionary();
+ ///
+ /// 可寻址地址映射集合
+ ///
+ [NonSerialized]
+ public readonly Dictionary AddressDic = new Dictionary();
+
///
/// 获取内置资源标签列表
@@ -108,6 +119,22 @@ namespace YooAsset
}
}
+ ///
+ /// 可寻址地址转换为资源路径
+ ///
+ public string ConvertAddress(string address)
+ {
+ if (AddressDic.TryGetValue(address, out string assetPath))
+ {
+ return assetPath;
+ }
+ else
+ {
+ YooLogger.Warning($"Not found address in patch manifest : {address}");
+ return string.Empty;
+ }
+ }
+
///
/// 序列化
@@ -155,6 +182,19 @@ namespace YooAsset
}
}
+ // Address
+ if (patchManifest.EnableAddressable)
+ {
+ foreach (var patchAsset in patchManifest.AssetList)
+ {
+ string address = patchAsset.Address;
+ if (patchManifest.AddressDic.ContainsKey(address))
+ throw new Exception($"Address have existed : {address}");
+ else
+ patchManifest.AddressDic.Add(address, patchAsset.AssetPath);
+ }
+ }
+
return patchManifest;
}
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
index f812784..ed534fd 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
@@ -31,6 +31,10 @@ namespace YooAsset
BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
}
+ string IBundleServices.ConvertAddress(string address)
+ {
+ throw new Exception($"Editor play mode not support addressable.");
+ }
string IBundleServices.GetBundleName(string assetPath)
{
return assetPath;
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index c8482e7..5447b10 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -237,6 +237,10 @@ namespace YooAsset
return bundleInfo;
}
}
+ string IBundleServices.ConvertAddress(string address)
+ {
+ return LocalPatchManifest.ConvertAddress(address);
+ }
string IBundleServices.GetBundleName(string assetPath)
{
return LocalPatchManifest.GetBundleName(assetPath);
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
index 73b0bc2..467b676 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
@@ -56,6 +56,10 @@ namespace YooAsset
return bundleInfo;
}
}
+ string IBundleServices.ConvertAddress(string address)
+ {
+ return AppPatchManifest.ConvertAddress(address);
+ }
string IBundleServices.GetBundleName(string assetPath)
{
return AppPatchManifest.GetBundleName(assetPath);
diff --git a/Assets/YooAsset/Runtime/Services/AddressLocationServices.cs b/Assets/YooAsset/Runtime/Services/AddressLocationServices.cs
deleted file mode 100644
index 577e124..0000000
--- a/Assets/YooAsset/Runtime/Services/AddressLocationServices.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-
-namespace YooAsset
-{
- public class AddressLocationServices : ILocationServices
- {
- public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
- {
- throw new System.NotImplementedException("该功能暂未支持!");
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs b/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs
deleted file mode 100644
index dd9789e..0000000
--- a/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-using System.IO;
-using UnityEngine;
-
-namespace YooAsset
-{
- public class DefaultLocationServices : ILocationServices
- {
- private readonly string _resourceRoot;
-
- public DefaultLocationServices(string resourceRoot)
- {
- if (string.IsNullOrEmpty(resourceRoot) == false)
- _resourceRoot = PathHelper.GetRegularPath(resourceRoot);
- }
- public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
- {
-#if UNITY_EDITOR
- CheckLocation(location);
-#endif
-
- if (playMode == YooAssets.EPlayMode.EditorPlayMode)
- {
- string filePath = CombineAssetPath(_resourceRoot, location);
- return FindDatabaseAssetPath(filePath);
- }
- else
- {
- return CombineAssetPath(_resourceRoot, location);
- }
- }
-
- ///
- /// 合并资源路径
- ///
- private static string CombineAssetPath(string root, string location)
- {
- if (string.IsNullOrEmpty(root))
- return location;
- else
- return $"{root}/{location}";
- }
-
- ///
- /// 获取AssetDatabase的加载路径
- ///
- private static string FindDatabaseAssetPath(string filePath)
- {
-#if UNITY_EDITOR
- if (File.Exists(filePath))
- return filePath;
-
- // AssetDatabase加载资源需要提供文件后缀格式,然而资源定位地址并没有文件格式信息。
- // 所以我们通过查找该文件所在文件夹内同名的首个文件来确定AssetDatabase的加载路径。
- // 注意:AssetDatabase.FindAssets() 返回文件内包括递归文件夹内所有资源的GUID
- string fileName = Path.GetFileName(filePath);
- string directory = PathHelper.GetDirectory(filePath);
- string[] guids = UnityEditor.AssetDatabase.FindAssets(string.Empty, new[] { directory });
- for (int i = 0; i < guids.Length; i++)
- {
- string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[i]);
-
- if (UnityEditor.AssetDatabase.IsValidFolder(assetPath))
- continue;
-
- string assetDirectory = PathHelper.GetDirectory(assetPath);
- if (assetDirectory != directory)
- continue;
-
- string assetName = Path.GetFileNameWithoutExtension(assetPath);
- if (assetName == fileName)
- return assetPath;
- }
-
- // 没有找到同名的资源文件
- YooLogger.Warning($"Not found asset : {filePath}");
- return filePath;
-#else
- throw new System.NotImplementedException();
-#endif
- }
-
-#if UNITY_EDITOR
- private void CheckLocation(string location)
- {
- if (string.IsNullOrEmpty(location))
- {
- YooLogger.Error("location param is null or empty!");
- }
- else
- {
- // 检查路径末尾是否有空格
- int index = location.LastIndexOf(" ");
- if (index != -1)
- {
- if (location.Length == index + 1)
- YooLogger.Warning($"Found blank character in location : \"{location}\"");
- }
-
- if (location.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
- YooLogger.Warning($"Found illegal character in location : \"{location}\"");
- }
- }
-#endif
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/Services/IBundleServices.cs b/Assets/YooAsset/Runtime/Services/IBundleServices.cs
index 4d5717c..a6b8ea9 100644
--- a/Assets/YooAsset/Runtime/Services/IBundleServices.cs
+++ b/Assets/YooAsset/Runtime/Services/IBundleServices.cs
@@ -8,6 +8,11 @@ namespace YooAsset
///
BundleInfo GetBundleInfo(string bundleName);
+ ///
+ /// 可寻址地址转换为资源路径
+ ///
+ string ConvertAddress(string address);
+
///
/// 获取资源所属的资源包名称
///
diff --git a/Assets/YooAsset/Runtime/Services/LocationServices.meta b/Assets/YooAsset/Runtime/Services/LocationServices.meta
new file mode 100644
index 0000000..7825f00
--- /dev/null
+++ b/Assets/YooAsset/Runtime/Services/LocationServices.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 6e400ee1e8b3556479bfa493ff7fe778
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs b/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs
new file mode 100644
index 0000000..4e1ca0a
--- /dev/null
+++ b/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs
@@ -0,0 +1,29 @@
+
+namespace YooAsset
+{
+ public class AddressLocationServices : ILocationServices
+ {
+ public AddressLocationServices()
+ {
+#if UNITY_EDITOR
+ LocationServicesHelper.InitEditorPlayMode(true);
+#endif
+ }
+
+ public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
+ {
+ if (playMode == YooAssets.EPlayMode.EditorPlayMode)
+ {
+#if UNITY_EDITOR
+ return LocationServicesHelper.ConvertLocationToAssetPath(location);
+#else
+ throw new System.NotImplementedException();
+#endif
+ }
+ else
+ {
+ return YooAssets.ConvertAddress(location);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/Services/AddressLocationServices.cs.meta b/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/Services/AddressLocationServices.cs.meta
rename to Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs.meta
diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs b/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs
new file mode 100644
index 0000000..6b6a3b8
--- /dev/null
+++ b/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs
@@ -0,0 +1,42 @@
+
+namespace YooAsset
+{
+ public class DefaultLocationServices : ILocationServices
+ {
+ private readonly string _resourceRoot;
+
+ public DefaultLocationServices(string resourceRoot)
+ {
+ if (string.IsNullOrEmpty(resourceRoot) == false)
+ _resourceRoot = PathHelper.GetRegularPath(resourceRoot);
+
+#if UNITY_EDITOR
+ LocationServicesHelper.InitEditorPlayMode(false);
+#endif
+ }
+
+ public string ConvertLocationToAssetPath(YooAssets.EPlayMode playMode, string location)
+ {
+ location = CombineAssetPath(_resourceRoot, location);
+ if (playMode == YooAssets.EPlayMode.EditorPlayMode)
+ {
+#if UNITY_EDITOR
+ return LocationServicesHelper.ConvertLocationToAssetPath(location);
+#else
+ throw new System.NotImplementedException();
+#endif
+ }
+ else
+ {
+ return location;
+ }
+ }
+ private string CombineAssetPath(string root, string location)
+ {
+ if (string.IsNullOrEmpty(root))
+ return location;
+ else
+ return $"{root}/{location}";
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs.meta b/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs.meta
rename to Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs.meta
diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/LocationServicesHelper.cs b/Assets/YooAsset/Runtime/Services/LocationServices/LocationServicesHelper.cs
new file mode 100644
index 0000000..4896edb
--- /dev/null
+++ b/Assets/YooAsset/Runtime/Services/LocationServices/LocationServicesHelper.cs
@@ -0,0 +1,32 @@
+#if UNITY_EDITOR
+using System.Reflection;
+
+namespace YooAsset
+{
+ internal static class LocationServicesHelper
+ {
+ private static System.Type AssetBundleGrouperSettingHelperClassType;
+
+ public static void InitEditorPlayMode(bool enableAddressable)
+ {
+ AssetBundleGrouperSettingHelperClassType = Assembly.Load("YooAsset.Editor").GetType("YooAsset.Editor.AssetBundleGrouperSettingHelper");
+ InvokePublicStaticMethod(AssetBundleGrouperSettingHelperClassType, "InitEditorPlayMode", enableAddressable);
+ }
+ public static string ConvertLocationToAssetPath(string location)
+ {
+ return (string)InvokePublicStaticMethod(AssetBundleGrouperSettingHelperClassType, "ConvertLocationToAssetPath", location);
+ }
+
+ private static object InvokePublicStaticMethod(System.Type type, string method, params object[] parameters)
+ {
+ var methodInfo = type.GetMethod(method, BindingFlags.Public | BindingFlags.Static);
+ if (methodInfo == null)
+ {
+ UnityEngine.Debug.LogError($"{type.FullName} not found method : {method}");
+ return null;
+ }
+ return methodInfo.Invoke(null, parameters);
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/LocationServicesHelper.cs.meta b/Assets/YooAsset/Runtime/Services/LocationServices/LocationServicesHelper.cs.meta
new file mode 100644
index 0000000..ad96bf6
--- /dev/null
+++ b/Assets/YooAsset/Runtime/Services/LocationServices/LocationServicesHelper.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b39dcdab07554ca4ab4ace5ca97aee78
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs
index c063127..0c2062f 100644
--- a/Assets/YooAsset/Runtime/YooAssets.cs
+++ b/Assets/YooAsset/Runtime/YooAssets.cs
@@ -377,18 +377,16 @@ namespace YooAsset
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
- IBundleServices bundleServices = _offlinePlayModeImpl;
- string bundleName = bundleServices.GetBundleName(assetPath);
- BundleInfo bundleInfo = bundleServices.GetBundleInfo(bundleName);
+ string bundleName = _bundleServices.GetBundleName(assetPath);
+ BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName);
RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.ProcessOperaiton(operation);
return operation;
}
else if (_playMode == EPlayMode.HostPlayMode)
{
- IBundleServices bundleServices = _hostPlayModeImpl;
- string bundleName = bundleServices.GetBundleName(assetPath);
- BundleInfo bundleInfo = bundleServices.GetBundleInfo(bundleName);
+ string bundleName = _bundleServices.GetBundleName(assetPath);
+ BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName);
RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.ProcessOperaiton(operation);
return operation;
@@ -650,9 +648,6 @@ namespace YooAsset
#endregion
#region 内部方法
- ///
- /// 更新资源系统
- ///
internal static void InternalUpdate()
{
// 更新异步请求操作
@@ -675,6 +670,10 @@ namespace YooAsset
}
}
}
+ internal static string ConvertAddress(string address)
+ {
+ return _bundleServices.ConvertAddress(address);
+ }
#endregion
}
}
\ No newline at end of file