升级YooAsset->2.1.1、UniTask->2.5.4

升级YooAsset->2.1.1、UniTask->2.5.4
This commit is contained in:
ALEXTANG
2024-04-15 19:37:42 +08:00
parent 83bea559e4
commit d75c1c8c93
88 changed files with 955 additions and 361 deletions

View File

@@ -9,7 +9,7 @@ namespace YooAsset.Editor
public static class AssetBundleBuilderHelper
{
/// <summary>
/// 获取默认的输出根
/// 获取默认的输出根
/// </summary>
public static string GetDefaultBuildOutputRoot()
{

View File

@@ -37,7 +37,7 @@ namespace YooAsset.Editor
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.IgnoreDefaultType = buildMapContext.Command.IgnoreDefaultType;
buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
// 构建参数

View File

@@ -1,4 +1,4 @@
#if UNITY_2019_4_OR_NEWER
#if UNITY_2019_4_OR_NEWER
using System;
using System.IO;
using System.Linq;
@@ -18,7 +18,7 @@ namespace YooAsset.Editor
}
/// <summary>
/// ִ<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>
/// 执行构建
/// </summary>
protected override void ExecuteBuild()
{

View File

@@ -1,4 +1,4 @@
#if UNITY_2019_4_OR_NEWER
#if UNITY_2019_4_OR_NEWER
using System;
using System.IO;
using System.Linq;
@@ -20,7 +20,7 @@ namespace YooAsset.Editor
}
/// <summary>
/// ִ<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>
/// 执行构建
/// </summary>
protected override void ExecuteBuild()
{

View File

@@ -166,7 +166,7 @@ namespace YooAsset.Editor
foreach (string assetPath in findAssets)
{
var assetInfo = new AssetInfo(assetPath);
if (IsValidateAsset(command, assetInfo) && IsCollectAsset(group, assetInfo))
if (command.IgnoreRule.IsIgnore(assetInfo) == false && IsCollectAsset(group, assetInfo))
{
if (result.ContainsKey(assetPath) == false)
{
@@ -228,37 +228,6 @@ namespace YooAsset.Editor
return collectAssetInfo;
}
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(assetInfo.AssetPath))
return false;
// 忽略编辑器下的类型资源
if (assetInfo.AssetType == typeof(LightingDataAsset))
return false;
// 忽略Unity引擎无法识别的文件
if (command.IgnoreDefaultType)
{
if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
{
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
return false;
}
}
if (DefaultFilterRule.IsIgnoreFile(assetInfo.FileExtension))
return false;
return true;
}
private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo)
{
// 根据规则设置过滤资源文件
@@ -312,7 +281,7 @@ namespace YooAsset.Editor
continue;
AssetInfo assetInfo = new AssetInfo(assetPath);
if (IsValidateAsset(command, assetInfo))
if (command.IgnoreRule.IsIgnore(assetInfo) == false)
result.Add(assetInfo);
}
return result;

View File

@@ -10,7 +10,7 @@ namespace YooAsset.Editor
{
public class AssetBundleCollectorConfig
{
public const string ConfigVersion = "v2.0.0";
public const string ConfigVersion = "v2.1";
public const string XmlVersion = "Version";
public const string XmlCommon = "Common";
@@ -25,7 +25,7 @@ namespace YooAsset.Editor
public const string XmlEnableAddressable = "AutoAddressable";
public const string XmlLocationToLower = "LocationToLower";
public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
public const string XmlIgnoreDefaultType = "IgnoreDefaultType";
public const string XmlIgnoreRuleName = "IgnoreRuleName";
public const string XmlGroup = "Group";
public const string XmlGroupActiveRule = "GroupActiveRule";
@@ -101,7 +101,7 @@ namespace YooAsset.Editor
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;
package.IgnoreRuleName = packageElement.GetAttribute(XmlIgnoreRuleName);
packages.Add(package);
// 读取分组配置
@@ -213,7 +213,7 @@ namespace YooAsset.Editor
packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString());
packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString());
packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString());
packageElement.SetAttribute(XmlIgnoreDefaultType, package.IgnoreDefaultType.ToString());
packageElement.SetAttribute(XmlIgnoreRuleName, package.IgnoreRuleName);
root.AppendChild(packageElement);
// 设置分组配置
@@ -258,6 +258,23 @@ namespace YooAsset.Editor
if (configVersion == ConfigVersion)
return true;
// v2.0.0 -> v2.1
if (configVersion == "v2.0.0")
{
// 读取包裹配置
var packageNodeList = root.GetElementsByTagName(XmlPackage);
foreach (var packageNode in packageNodeList)
{
XmlElement packageElement = packageNode as XmlElement;
if (packageElement.HasAttribute(XmlIgnoreRuleName) == false)
packageElement.SetAttribute(XmlIgnoreRuleName, nameof(NormalIgnoreRule));
}
// 更新版本
root.SetAttribute(XmlVersion, "v2.1");
return UpdateXmlConfig(xmlDoc);
}
return false;
}
}

View File

@@ -35,16 +35,16 @@ namespace YooAsset.Editor
/// </summary>
public bool IncludeAssetGUID = false;
/// <summary>
/// 忽略Unity引擎无法识别的文件
/// </summary>
public bool IgnoreDefaultType = true;
/// <summary>
/// 自动收集所有着色器(所有着色器存储在一个资源包内)
/// </summary>
public bool AutoCollectShaders = true;
/// <summary>
/// 资源忽略规则名
/// </summary>
public string IgnoreRuleName = nameof(NormalIgnoreRule);
/// <summary>
/// 分组列表
/// </summary>
@@ -56,6 +56,16 @@ namespace YooAsset.Editor
/// </summary>
public void CheckConfigError()
{
if (string.IsNullOrEmpty(IgnoreRuleName))
{
throw new Exception($"{nameof(IgnoreRuleName)} is null or empty !");
}
else
{
if (AssetBundleCollectorSettingData.HasIgnoreRuleName(IgnoreRuleName) == false)
throw new Exception($"Invalid {nameof(IIgnoreRule)} class type : {IgnoreRuleName} in package : {PackageName}");
}
foreach (var group in Groups)
{
group.CheckConfigError();
@@ -68,6 +78,14 @@ namespace YooAsset.Editor
public bool FixConfigError()
{
bool isFixed = false;
if (string.IsNullOrEmpty(IgnoreRuleName))
{
Debug.LogWarning($"Set the {nameof(IgnoreRuleName)} to {nameof(NormalIgnoreRule)}");
IgnoreRuleName = nameof(NormalIgnoreRule);
isFixed = true;
}
foreach (var group in Groups)
{
if (group.FixConfigError())
@@ -75,6 +93,7 @@ namespace YooAsset.Editor
isFixed = true;
}
}
return isFixed;
}

View File

@@ -24,7 +24,6 @@ namespace YooAsset.Editor
/// </summary>
public bool UniqueBundleName = false;
/// <summary>
/// 包裹列表
/// </summary>
@@ -100,13 +99,13 @@ namespace YooAsset.Editor
package.CheckConfigError();
// 创建资源收集命令
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
CollectCommand command = new CollectCommand(buildMode, packageName,
package.EnableAddressable,
package.LocationToLower,
package.IncludeAssetGUID,
package.IgnoreDefaultType,
package.AutoCollectShaders,
UniqueBundleName);
UniqueBundleName, ignoreRule);
// 获取收集的资源集合
CollectResult collectResult = new CollectResult(command);

View File

@@ -21,6 +21,9 @@ namespace YooAsset.Editor
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> _cacheIgnoreRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IIgnoreRule> _cacheIgnoreRuleInstance = new Dictionary<string, IIgnoreRule>();
/// <summary>
/// 配置数据是否被修改
/// </summary>
@@ -129,6 +132,29 @@ namespace YooAsset.Editor
_cacheActiveRuleTypes.Add(type.Name, type);
}
}
// IIgnoreRule
{
// 清空缓存集合
_cacheIgnoreRuleTypes.Clear();
_cacheIgnoreRuleInstance.Clear();
// 获取所有类型
List<Type> types = new List<Type>(100)
{
typeof(NormalIgnoreRule),
typeof(RawFileIgnoreRule),
};
var customTypes = EditorTools.GetAssignableTypes(typeof(IIgnoreRule));
types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++)
{
Type type = types[i];
if (_cacheIgnoreRuleTypes.ContainsKey(type.Name) == false)
_cacheIgnoreRuleTypes.Add(type.Name, type);
}
}
}
private static AssetBundleCollectorSetting _setting = null;
@@ -165,6 +191,7 @@ namespace YooAsset.Editor
if (isFixed)
{
IsDirty = true;
Debug.Log("Fix package config error done !");
}
}
@@ -225,6 +252,18 @@ namespace YooAsset.Editor
}
return names;
}
public static List<RuleDisplayName> GetIgnoreRuleNames()
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheIgnoreRuleTypes)
{
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);
@@ -250,6 +289,10 @@ namespace YooAsset.Editor
{
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
}
public static bool HasIgnoreRuleName(string ruleName)
{
return _cacheIgnoreRuleTypes.Keys.Contains(ruleName);
}
public static IActiveRule GetActiveRuleInstance(string ruleName)
{
@@ -319,6 +362,23 @@ namespace YooAsset.Editor
throw new Exception($"{nameof(IFilterRule)} is invalid{ruleName}");
}
}
public static IIgnoreRule GetIgnoreRuleInstance(string ruleName)
{
if (_cacheIgnoreRuleInstance.TryGetValue(ruleName, out IIgnoreRule instance))
return instance;
// 如果不存在创建类的实例
if (_cacheIgnoreRuleTypes.TryGetValue(ruleName, out Type type))
{
instance = (IIgnoreRule)Activator.CreateInstance(type);
_cacheIgnoreRuleInstance.Add(ruleName, instance);
return instance;
}
else
{
throw new Exception($"{nameof(IIgnoreRule)} is invalid{ruleName}");
}
}
// 公共参数编辑相关
public static void ModifyShowPackageView(bool showPackageView)

View File

@@ -24,6 +24,7 @@ namespace YooAsset.Editor
private List<RuleDisplayName> _addressRuleList;
private List<RuleDisplayName> _packRuleList;
private List<RuleDisplayName> _filterRuleList;
private List<RuleDisplayName> _ignoreRuleList;
private VisualElement _helpBoxContainer;
@@ -39,9 +40,9 @@ namespace YooAsset.Editor
private Toggle _enableAddressableToogle;
private Toggle _locationToLowerToogle;
private Toggle _includeAssetGUIDToogle;
private Toggle _ignoreDefaultTypeToogle;
private Toggle _autoCollectShadersToogle;
private PopupField<RuleDisplayName> _ignoreRulePopupField;
private VisualElement _packageContainer;
private ListView _packageListView;
private TextField _packageNameTxt;
@@ -77,6 +78,7 @@ namespace YooAsset.Editor
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
_ignoreRuleList = AssetBundleCollectorSettingData.GetIgnoreRuleNames();
VisualElement root = this.rootVisualElement;
@@ -151,17 +153,6 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
_ignoreDefaultTypeToogle = root.Q<Toggle>("IgnoreDefaultType");
_ignoreDefaultTypeToogle.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage != null)
{
selectPackage.IgnoreDefaultType = evt.newValue;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
RefreshWindow();
}
});
_autoCollectShadersToogle = root.Q<Toggle>("AutoCollectShaders");
_autoCollectShadersToogle.RegisterValueChangedCallback(evt =>
{
@@ -173,6 +164,25 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
{
_ignoreRulePopupField = new PopupField<RuleDisplayName>(_ignoreRuleList, 0);
_ignoreRulePopupField.label = "File Ignore Rule";
_ignoreRulePopupField.name = "IgnoreRulePopupField";
_ignoreRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
_ignoreRulePopupField.style.width = 300;
_ignoreRulePopupField.formatListItemCallback = FormatListItemCallback;
_ignoreRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
_ignoreRulePopupField.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if(selectPackage != null)
{
selectPackage.IgnoreRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
}
});
_setting2Container.Add(_ignoreRulePopupField);
}
// 配置修复按钮
var fixBtn = root.Q<Button>("FixButton");
@@ -475,8 +485,8 @@ namespace YooAsset.Editor
_enableAddressableToogle.SetValueWithoutNotify(selectPackage.EnableAddressable);
_locationToLowerToogle.SetValueWithoutNotify(selectPackage.LocationToLower);
_includeAssetGUIDToogle.SetValueWithoutNotify(selectPackage.IncludeAssetGUID);
_ignoreDefaultTypeToogle.SetValueWithoutNotify(selectPackage.IgnoreDefaultType);
_autoCollectShadersToogle.SetValueWithoutNotify(selectPackage.AutoCollectShaders);
_ignoreRulePopupField.SetValueWithoutNotify(GetIgnoreRuleIndex(selectPackage.IgnoreRuleName));
}
else
{
@@ -970,7 +980,7 @@ namespace YooAsset.Editor
if (collector.IsValid() == false)
{
Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}");
collector.CheckConfigError();
return;
}
@@ -980,14 +990,15 @@ namespace YooAsset.Editor
try
{
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(_ignoreRulePopupField.value.ClassName);
CollectCommand command = new CollectCommand(EBuildMode.SimulateBuild,
_packageNameTxt.value,
_enableAddressableToogle.value,
_locationToLowerToogle.value,
_includeAssetGUIDToogle.value,
_ignoreDefaultTypeToogle.value,
_autoCollectShadersToogle.value,
_uniqueBundleNameToogle.value);
_uniqueBundleNameToogle.value,
ignoreRule);
collector.CheckConfigError();
collectAssetInfos = collector.GetAllCollectAssets(command, group);
}
@@ -1078,6 +1089,15 @@ namespace YooAsset.Editor
}
return 0;
}
private RuleDisplayName GetIgnoreRuleIndex(string ruleName)
{
for (int i = 0; i < _ignoreRuleList.Count; i++)
{
if (_ignoreRuleList[i].ClassName == ruleName)
return _ignoreRuleList[i];
}
return _ignoreRuleList[0];
}
private RuleDisplayName GetActiveRuleIndex(string ruleName)
{
for (int i = 0; i < _activeRuleList.Count; i++)

View File

@@ -21,7 +21,6 @@
<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>

View File

@@ -13,11 +13,6 @@ namespace YooAsset.Editor
/// </summary>
public string PackageName { private set; get; }
/// <summary>
/// 忽略Unity引擎无法识别的文件
/// </summary>
public bool IgnoreDefaultType { private set; get; }
/// <summary>
/// 启用可寻址资源定位
/// </summary>
@@ -48,17 +43,24 @@ namespace YooAsset.Editor
/// </summary>
public string ShadersBundleName { private set; get; }
/// <summary>
/// 忽略规则实例
/// </summary>
public IIgnoreRule IgnoreRule { private set; get; }
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool locationToLower, bool includeAssetGUID, bool ignoreDefaultType, bool autoCollectShaders, bool uniqueBundleName)
public CollectCommand(EBuildMode buildMode, string packageName,
bool enableAddressable, bool locationToLower, bool includeAssetGUID,
bool autoCollectShaders, bool uniqueBundleName, IIgnoreRule ignoreRule)
{
BuildMode = buildMode;
PackageName = packageName;
EnableAddressable = enableAddressable;
LocationToLower = locationToLower;
IncludeAssetGUID = includeAssetGUID;
IgnoreDefaultType = ignoreDefaultType;
AutoCollectShaders = autoCollectShaders;
UniqueBundleName = uniqueBundleName;
IgnoreRule = ignoreRule;
// 着色器统一全名称
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();

View File

@@ -0,0 +1,11 @@

namespace YooAsset.Editor
{
/// <summary>
/// 资源忽略规则接口
/// </summary>
public interface IIgnoreRule
{
bool IsIgnore(AssetInfo assetInfo);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd55753dbb880fa449bf4e37b33d8ba7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -6,22 +6,6 @@ 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" };
/// <summary>
/// 查询是否为忽略文件
/// </summary>
public static bool IsIgnoreFile(string fileExtension)
{
return _ignoreFileExtensions.Contains(fileExtension);
}
}
[DisplayName("收集所有资源")]
public class CollectAll : IFilterRule
{
@@ -70,6 +54,15 @@ namespace YooAsset.Editor
}
}
[DisplayName("收集着色器")]
public class CollectShader : IFilterRule
{
public bool IsCollectAsset(FilterRuleData data)
{
return Path.GetExtension(data.AssetPath) == ".shader";
}
}
[DisplayName("收集着色器变种集合")]
public class CollectShaderVariants : IFilterRule
{

View File

@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
public class DefaultIgnoreRule
{
/// <summary>
/// 忽略的文件类型
/// </summary>
public readonly static HashSet<string> IgnoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
}
/// <summary>
/// 适配常规的资源构建管线
/// </summary>
public class NormalIgnoreRule : IIgnoreRule
{
/// <summary>
/// 查询是否为忽略文件
/// </summary>
public bool IsIgnore(AssetInfo assetInfo)
{
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
{
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
return true;
}
// 忽略文件夹
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
return true;
// 忽略编辑器下的类型资源
if (assetInfo.AssetType == typeof(LightingDataAsset))
return true;
if (assetInfo.AssetType == typeof(LightmapParameters))
return true;
// 忽略Unity引擎无法识别的文件
if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
{
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
return true;
}
return DefaultIgnoreRule.IgnoreFileExtensions.Contains(assetInfo.FileExtension);
}
}
/// <summary>
/// 适配原生文件构建管线
/// </summary>
public class RawFileIgnoreRule : IIgnoreRule
{
/// <summary>
/// 查询是否为忽略文件
/// </summary>
public bool IsIgnore(AssetInfo assetInfo)
{
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
{
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
return true;
}
// 忽略文件夹
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
return true;
// 忽略编辑器下的类型资源
if (assetInfo.AssetType == typeof(LightingDataAsset))
return true;
if (assetInfo.AssetType == typeof(LightmapParameters))
return true;
return DefaultIgnoreRule.IgnoreFileExtensions.Contains(assetInfo.FileExtension);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b9c1900577194bb4ab49ce4332ccc4bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -147,6 +147,18 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 打包着色器
/// </summary>
[DisplayName("打包着色器文件")]
public class PackShader : IPackRule
{
public PackRuleResult GetPackRuleResult(PackRuleData data)
{
return DefaultPackRule.CreateShadersPackRuleResult();
}
}
/// <summary>
/// 打包着色器变种集合
/// </summary>

View File

@@ -58,8 +58,8 @@ namespace YooAsset.Editor
public bool EnableAddressable;
public bool LocationToLower;
public bool IncludeAssetGUID;
public bool IgnoreDefaultType;
public bool AutoCollectShaders;
public string IgnoreRuleName;
// 构建参数
public bool EnableSharePackRule;

View File

@@ -72,8 +72,8 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("Enable Addressable", $"{buildReport.Summary.EnableAddressable}"));
_items.Add(new ItemWrapper("Location To Lower", $"{buildReport.Summary.LocationToLower}"));
_items.Add(new ItemWrapper("Include Asset GUID", $"{buildReport.Summary.IncludeAssetGUID}"));
_items.Add(new ItemWrapper("Ignore Default Type", $"{buildReport.Summary.IgnoreDefaultType}"));
_items.Add(new ItemWrapper("Auto Collect Shaders", $"{buildReport.Summary.AutoCollectShaders}"));
_items.Add(new ItemWrapper("Ignore Rule Name", $"{buildReport.Summary.IgnoreRuleName}"));
_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("Build Params", string.Empty));

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 07a483743a0f68e4cb55a38570d1b7cd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -111,7 +111,7 @@ namespace YooAsset
// 再验证文件CRC
if (verifyLevel == EVerifyLevel.High)
{
string crc = HashUtility.FileCRC32(filePath);
string crc = HashUtility.FileCRC32Safely(filePath);
if (crc == fileCRC)
return EVerifyResult.Succeed;
else

View File

@@ -23,6 +23,8 @@ namespace YooAsset
return new System.Uri(path).ToString();
#elif UNITY_STANDALONE
return StringUtility.Format("file:///{0}", path);
#elif UNITY_OPENHARMONY
return path;
#else
return path;
#endif

View File

@@ -58,7 +58,12 @@ namespace YooAsset
}
private static string CreateDefaultBuildinRoot()
{
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
string path = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#if UNITY_OPENHARMONY
return $"file://{path}";
#else
return path;
#endif
}
private static string CreateDefaultSandboxRoot()
{
@@ -176,6 +181,7 @@ namespace YooAsset
/// </summary>
public void SaveSandboxPackageVersionFile(string version)
{
YooLogger.Log($"Save package version : {version}");
string filePath = GetSandboxPackageVersionFilePath();
FileUtility.WriteAllText(filePath, version);
}

View File

@@ -150,5 +150,10 @@ namespace YooAsset
/// 内置资源查询服务接口
/// </summary>
public IBuildinQueryServices BuildinQueryServices = null;
/// <summary>
/// 微信缓存查询服务接口
/// </summary>
public IWechatQueryServices WechatQueryServices = null;
}
}

View File

@@ -100,28 +100,21 @@ namespace YooAsset
if (IsValidWithWarning == false)
return false;
if (SceneObject.IsValid())
if (Provider is DatabaseSceneProvider)
{
if (Provider is DatabaseSceneProvider)
{
var temp = Provider as DatabaseSceneProvider;
return temp.UnSuspendLoad();
}
else if (Provider is BundledSceneProvider)
{
var temp = Provider as BundledSceneProvider;
return temp.UnSuspendLoad();
}
else
{
throw new System.NotImplementedException();
}
var provider = Provider as DatabaseSceneProvider;
provider.UnSuspendLoad();
}
else if (Provider is BundledSceneProvider)
{
var provider = Provider as BundledSceneProvider;
provider.UnSuspendLoad();
}
else
{
YooLogger.Warning($"Scene is invalid : {SceneObject.name}");
return false;
throw new System.NotImplementedException();
}
return true;
}
/// <summary>

View File

@@ -31,6 +31,22 @@ namespace YooAsset
{
_error = null;
_provider = provider;
// 注意:卸载场景前必须先解除挂起操作
if (provider is DatabaseSceneProvider)
{
var temp = provider as DatabaseSceneProvider;
temp.UnSuspendLoad();
}
else if (provider is BundledSceneProvider)
{
var temp = provider as BundledSceneProvider;
temp.UnSuspendLoad();
}
else
{
throw new System.NotImplementedException();
}
}
internal override void InternalOnStart()
{

View File

@@ -9,14 +9,14 @@ namespace YooAsset
internal sealed class BundledSceneProvider : ProviderBase
{
public readonly LoadSceneMode SceneMode;
private readonly bool _suspendLoad;
private AsyncOperation _asyncOperation;
private bool _suspendLoadMode;
public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
{
SceneMode = sceneMode;
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_suspendLoad = suspendLoad;
_suspendLoadMode = suspendLoad;
}
internal override void InternalOnStart()
{
@@ -80,7 +80,7 @@ namespace YooAsset
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
_asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
_steps = ESteps.Checking;
@@ -106,6 +106,13 @@ namespace YooAsset
}
else
{
// 注意:在业务层中途可以取消挂起
if (_asyncOperation.allowSceneActivation == false)
{
if (_suspendLoadMode == false)
_asyncOperation.allowSceneActivation = true;
}
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone == false)
return;
@@ -128,13 +135,12 @@ namespace YooAsset
/// <summary>
/// 解除场景加载挂起操作
/// </summary>
public bool UnSuspendLoad()
public void UnSuspendLoad()
{
if (_asyncOperation == null)
return false;
_asyncOperation.allowSceneActivation = true;
return true;
if (IsDone == false)
{
_suspendLoadMode = false;
}
}
}
}

View File

@@ -9,14 +9,14 @@ namespace YooAsset
internal sealed class DatabaseSceneProvider : ProviderBase
{
public readonly LoadSceneMode SceneMode;
private readonly bool _suspendLoad;
private bool _suspendLoadMode;
private AsyncOperation _asyncOperation;
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
{
SceneMode = sceneMode;
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_suspendLoad = suspendLoad;
_suspendLoadMode = suspendLoad;
}
internal override void InternalOnStart()
{
@@ -69,7 +69,7 @@ namespace YooAsset
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
_asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
_steps = ESteps.Checking;
@@ -95,6 +95,13 @@ namespace YooAsset
}
else
{
// 注意:在业务层中途可以取消挂起
if (_asyncOperation.allowSceneActivation == false)
{
if (_suspendLoadMode == false)
_asyncOperation.allowSceneActivation = true;
}
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone == false)
return;
@@ -118,13 +125,12 @@ namespace YooAsset
/// <summary>
/// 解除场景加载挂起操作
/// </summary>
public bool UnSuspendLoad()
public void UnSuspendLoad()
{
if (_asyncOperation == null)
return false;
_asyncOperation.allowSceneActivation = true;
return true;
if (IsDone == false)
{
_suspendLoadMode = false;
}
}
}
}

View File

@@ -332,6 +332,7 @@ namespace YooAsset
{
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
_impl.FlushManifestVersionFile(); //注意:解压内置清单并加载成功后保存该清单版本。
_steps = ESteps.PackageCaching;
}
else

View File

@@ -77,7 +77,7 @@ namespace YooAsset
return;
}
string fileHash = HashUtility.FileMD5(_manifestFilePath);
string fileHash = HashUtility.FileMD5Safely(_manifestFilePath);
if (fileHash != _queryCachePackageHashOp.PackageHash)
{
_steps = ESteps.Done;

View File

@@ -63,7 +63,6 @@ namespace YooAsset
TryLoadCacheManifest,
DownloadManifest,
LoadCacheManifest,
CheckDeserializeManifest,
Done,
}

View File

@@ -10,6 +10,7 @@ namespace YooAsset
private ResourceAssist _assist;
private IBuildinQueryServices _buildinQueryServices;
private IRemoteServices _remoteServices;
private IWechatQueryServices _wechatQueryServices;
public readonly string PackageName;
public DownloadManager Download
@@ -34,11 +35,12 @@ namespace YooAsset
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices)
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices, IWechatQueryServices wechatQueryServices)
{
_assist = assist;
_buildinQueryServices = buildinQueryServices;
_remoteServices = remoteServices;
_wechatQueryServices = wechatQueryServices;
var operation = new WebPlayModeInitializationOperation(this);
OperationSystem.StartOperation(PackageName, operation);
@@ -65,23 +67,13 @@ namespace YooAsset
}
// 查询相关
#if UNITY_WECHAT_GAME
private WeChatWASM.WXFileSystemManager _wxFileSystemMgr;
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
if (_wxFileSystemMgr == null)
_wxFileSystemMgr = WeChatWASM.WX.GetFileSystemManager();
string filePath = WeChatWASM.WX.env.USER_DATA_PATH + packageBundle.FileName;
string result = _wxFileSystemMgr.AccessSync(filePath);
return result.Equals("access:ok");
if (_wechatQueryServices != null)
return _wechatQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
else
return false;
}
#else
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return false;
}
#endif
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);

View File

@@ -184,7 +184,8 @@ namespace YooAsset
var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
initializeParameters.BuildinQueryServices,
initializeParameters.RemoteServices);
initializeParameters.RemoteServices,
initializeParameters.WechatQueryServices);
}
else
{

View File

@@ -0,0 +1,15 @@

namespace YooAsset
{
public interface IWechatQueryServices
{
/// <summary>
/// 查询是否为微信缓存的资源文件
/// </summary>
/// <param name="packageName">包裹名称</param>
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
/// <param name="fileCRC">文件哈希值</param>
/// <returns>返回查询结果</returns>
bool Query(string packageName, string fileName, string fileCRC);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6b28ce9425f5eb4f972dcda9fd864f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -214,13 +214,21 @@ namespace YooAsset
/// 获取文件的Hash值
/// </summary>
public static string FileSHA1(string filePath)
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamSHA1(fs);
}
}
/// <summary>
/// 获取文件的Hash值
/// </summary>
public static string FileSHA1Safely(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamSHA1(fs);
}
return FileSHA1(filePath);
}
catch (Exception e)
{
@@ -266,13 +274,21 @@ namespace YooAsset
/// 获取文件的MD5
/// </summary>
public static string FileMD5(string filePath)
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamMD5(fs);
}
}
/// <summary>
/// 获取文件的MD5
/// </summary>
public static string FileMD5Safely(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamMD5(fs);
}
return FileMD5(filePath);
}
catch (Exception e)
{
@@ -316,13 +332,21 @@ namespace YooAsset
/// 获取文件的CRC32
/// </summary>
public static string FileCRC32(string filePath)
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamCRC32(fs);
}
}
/// <summary>
/// 获取文件的CRC32
/// </summary>
public static string FileCRC32Safely(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamCRC32(fs);
}
return FileCRC32(filePath);
}
catch (Exception e)
{