diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/YooAssets/DecryptionServices.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/YooAssets/DecryptionServices.cs index c035ec8b..595f41f8 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/YooAssets/DecryptionServices.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/YooAssets/DecryptionServices.cs @@ -10,14 +10,29 @@ internal interface IDecryptStream Stream DecryptStream(DecryptFileInfo fileInfo); } - public class NoneDecryption : IDecryptionServices, IDecryptStream + internal interface IDecryptData { + byte[] DecryptData(DecryptFileInfo fileInfo); + } + + public class NoneDecryption : IDecryptionServices, IDecryptStream, IDecryptData + { + #region OxGFrame Implements + public byte[] DecryptData(DecryptFileInfo fileInfo) + { + string filePath = fileInfo.FileLoadPath; + if (File.Exists(filePath) == false) + return null; + return File.ReadAllBytes(filePath); + } + public Stream DecryptStream(DecryptFileInfo fileInfo) { string filePath = fileInfo.FileLoadPath; var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None); return fs; } + #endregion public uint GetManagedReadBufferSize() { @@ -35,10 +50,29 @@ public AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, o managedStream = this.DecryptStream(fileInfo); return AssetBundle.LoadFromStreamAsync(managedStream, fileInfo.ConentCRC, GetManagedReadBufferSize()); } + + public byte[] LoadRawFileData(DecryptFileInfo fileInfo) + { + return this.DecryptData(fileInfo); + } } - public class OffsetDecryption : IDecryptionServices, IDecryptStream + public class OffsetDecryption : IDecryptionServices, IDecryptStream, IDecryptData { + #region OxGFrame Implements + public byte[] DecryptData(DecryptFileInfo fileInfo) + { + OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; + string filePath = fileInfo.FileLoadPath; + int dummySize = Convert.ToInt32(decryptArgs[1].Decrypt()); + if (File.Exists(filePath) == false) + return null; + byte[] data = File.ReadAllBytes(filePath); + if (FileCryptogram.Offset.OffsetDecryptBytes(ref data, dummySize)) + return data; + return null; + } + public Stream DecryptStream(DecryptFileInfo fileInfo) { OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; @@ -46,6 +80,7 @@ public Stream DecryptStream(DecryptFileInfo fileInfo) int dummySize = Convert.ToInt32(decryptArgs[1].Decrypt()); return FileCryptogram.Offset.OffsetDecryptStream(filePath, dummySize); } + #endregion public uint GetManagedReadBufferSize() { @@ -63,10 +98,29 @@ public AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, o managedStream = this.DecryptStream(fileInfo); return AssetBundle.LoadFromStreamAsync(managedStream, fileInfo.ConentCRC, GetManagedReadBufferSize()); } + + public byte[] LoadRawFileData(DecryptFileInfo fileInfo) + { + return this.DecryptData(fileInfo); + } } - public class XorDecryption : IDecryptionServices, IDecryptStream + public class XorDecryption : IDecryptionServices, IDecryptStream, IDecryptData { + #region OxGFrame Implements + public byte[] DecryptData(DecryptFileInfo fileInfo) + { + OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; + string filePath = fileInfo.FileLoadPath; + byte xorKey = Convert.ToByte(decryptArgs[1].Decrypt()); + if (File.Exists(filePath) == false) + return null; + byte[] data = File.ReadAllBytes(filePath); + if (FileCryptogram.XOR.XorDecryptBytes(data, xorKey)) + return data; + return null; + } + public Stream DecryptStream(DecryptFileInfo fileInfo) { OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; @@ -74,6 +128,7 @@ public Stream DecryptStream(DecryptFileInfo fileInfo) byte xorKey = Convert.ToByte(decryptArgs[1].Decrypt()); return FileCryptogram.XOR.XorDecryptStream(filePath, xorKey); } + #endregion public uint GetManagedReadBufferSize() { @@ -91,10 +146,31 @@ public AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, o managedStream = this.DecryptStream(fileInfo); return AssetBundle.LoadFromStreamAsync(managedStream, fileInfo.ConentCRC, GetManagedReadBufferSize()); } + + public byte[] LoadRawFileData(DecryptFileInfo fileInfo) + { + return this.DecryptData(fileInfo); + } } - public class HT2XorDecryption : IDecryptionServices, IDecryptStream + public class HT2XorDecryption : IDecryptionServices, IDecryptStream, IDecryptData { + #region OxGFrame Implements + public byte[] DecryptData(DecryptFileInfo fileInfo) + { + OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; + string filePath = fileInfo.FileLoadPath; + byte hXorkey = Convert.ToByte(decryptArgs[1].Decrypt()); + byte tXorkey = Convert.ToByte(decryptArgs[2].Decrypt()); + byte jXorKey = Convert.ToByte(decryptArgs[3].Decrypt()); + if (File.Exists(filePath) == false) + return null; + byte[] data = File.ReadAllBytes(filePath); + if (FileCryptogram.HT2XOR.HT2XorDecryptBytes(data, hXorkey, tXorkey, jXorKey)) + return data; + return null; + } + public Stream DecryptStream(DecryptFileInfo fileInfo) { OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; @@ -104,6 +180,7 @@ public Stream DecryptStream(DecryptFileInfo fileInfo) byte jXorKey = Convert.ToByte(decryptArgs[3].Decrypt()); return FileCryptogram.HT2XOR.HT2XorDecryptStream(filePath, hXorkey, tXorkey, jXorKey); } + #endregion public uint GetManagedReadBufferSize() { @@ -121,10 +198,30 @@ public AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, o managedStream = this.DecryptStream(fileInfo); return AssetBundle.LoadFromStreamAsync(managedStream, fileInfo.ConentCRC, GetManagedReadBufferSize()); } + + public byte[] LoadRawFileData(DecryptFileInfo fileInfo) + { + return this.DecryptData(fileInfo); + } } - public class AesDecryption : IDecryptionServices, IDecryptStream + public class AesDecryption : IDecryptionServices, IDecryptStream, IDecryptData { + #region OxGFrame Implements + public byte[] DecryptData(DecryptFileInfo fileInfo) + { + OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; + string filePath = fileInfo.FileLoadPath; + string aesKey = decryptArgs[1].Decrypt(); + string aesIv = decryptArgs[2].Decrypt(); + if (File.Exists(filePath) == false) + return null; + byte[] data = File.ReadAllBytes(filePath); + if (FileCryptogram.AES.AesDecryptBytes(data, aesKey, aesIv)) + return data; + return null; + } + public Stream DecryptStream(DecryptFileInfo fileInfo) { OxGFrame.AssetLoader.Utility.SecureMemory.SecureString[] decryptArgs = BundleConfig.decryptArgs; @@ -133,6 +230,7 @@ public Stream DecryptStream(DecryptFileInfo fileInfo) string aesIv = decryptArgs[2].Decrypt(); return FileCryptogram.AES.AesDecryptStream(filePath, aesKey, aesIv); } + #endregion public uint GetManagedReadBufferSize() { @@ -150,5 +248,10 @@ public AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, o managedStream = this.DecryptStream(fileInfo); return AssetBundle.LoadFromStreamAsync(managedStream, fileInfo.ConentCRC, GetManagedReadBufferSize()); } + + public byte[] LoadRawFileData(DecryptFileInfo fileInfo) + { + return this.DecryptData(fileInfo); + } } -} +} \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/SimpleDiskUtils/Runtime/DiskUtils.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/SimpleDiskUtils/Runtime/DiskUtils.cs index 398d4345..406164b3 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/SimpleDiskUtils/Runtime/DiskUtils.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/SimpleDiskUtils/Runtime/DiskUtils.cs @@ -141,7 +141,7 @@ public static string[] GetDriveNames() /// /// The available space in MB. public static int CheckAvailableSpace(){ - DriveInfo drive = GetDrive (DEFAULT_DRIVE); + DriveInfo drive = new DriveInfo(DEFAULT_DRIVE); if (drive == null) return -1; return int.Parse((drive.AvailableFreeSpace / MEGA_BYTE).ToString()); @@ -152,7 +152,7 @@ public static int CheckAvailableSpace(){ /// /// The total space in MB. public static int CheckTotalSpace(){ - DriveInfo drive = GetDrive (DEFAULT_DRIVE); + DriveInfo drive = new DriveInfo(DEFAULT_DRIVE); if (drive == null) return -1; return int.Parse ((drive.TotalSize / MEGA_BYTE).ToString()); @@ -163,7 +163,7 @@ public static int CheckTotalSpace(){ /// /// The busy space in MB. public static int CheckBusySpace(){ - DriveInfo drive = GetDrive (DEFAULT_DRIVE); + DriveInfo drive = new DriveInfo(DEFAULT_DRIVE); if (drive == null) return -1; diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs index 45cd531b..b222318d 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs @@ -9,7 +9,7 @@ namespace YooAsset.Editor public static class AssetBundleBuilderHelper { /// - /// 获取默认的输出根路录 + /// 获取默认的输出根目录 /// public static string GetDefaultBuildOutputRoot() { diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs index 56051f51..dccf6080 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateReport.cs @@ -37,7 +37,7 @@ protected void CreateReportFile(BuildParametersContext buildParametersContext, B 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; // 构建参数 diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuiltinBuildPipeline.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuiltinBuildPipeline.cs index 2ac4058a..177803f0 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuiltinBuildPipeline.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuiltinBuildPipeline.cs @@ -8,8 +8,15 @@ public class BuiltinBuildPipeline : IBuildPipeline { public BuildResult Run(BuildParameters buildParameters, bool enableLog) { - AssetBundleBuilder builder = new AssetBundleBuilder(); - return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); + if (buildParameters is BuiltinBuildParameters) + { + AssetBundleBuilder builder = new AssetBundleBuilder(); + return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); + } + else + { + throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}"); + } } /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskEncription_RFBP.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskEncription_RFBP.cs new file mode 100644 index 00000000..0a9f366e --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskEncription_RFBP.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; +using System.IO; +using System.Collections; +using System.Collections.Generic; + +namespace YooAsset.Editor +{ + public class TaskEncryption_RFBP : TaskEncryption, IBuildTask + { + void IBuildTask.Run(BuildContext context) + { + var buildParameters = context.GetContextObject(); + var buildMapContext = context.GetContextObject(); + + var buildMode = buildParameters.Parameters.BuildMode; + if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) + { + EncryptingBundleFiles(buildParameters, buildMapContext); + } + } + } +} \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskEncription_RFBP.cs.meta b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskEncription_RFBP.cs.meta new file mode 100644 index 00000000..5dade931 --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskEncription_RFBP.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4401997215a8ab040893fbf62435db93 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildPipeline.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildPipeline.cs index 78651508..8358e918 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildPipeline.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildPipeline.cs @@ -11,8 +11,15 @@ public class RawFileBuildPipeline : IBuildPipeline { public BuildResult Run(BuildParameters buildParameters, bool enableLog) { - AssetBundleBuilder builder = new AssetBundleBuilder(); - return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); + if (buildParameters is RawFileBuildParameters) + { + AssetBundleBuilder builder = new AssetBundleBuilder(); + return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); + } + else + { + throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}"); + } } /// @@ -25,6 +32,7 @@ private List GetDefaultBuildPipeline() new TaskPrepare_RFBP(), new TaskGetBuildMap_RFBP(), new TaskBuilding_RFBP(), + new TaskEncryption_RFBP(), new TaskUpdateBundleInfo_RFBP(), new TaskCreateManifest_RFBP(), new TaskCreateReport_RFBP(), diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/SBPBuildTasks.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/SBPBuildTasks.cs index 7ba0d052..0e55e92d 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/SBPBuildTasks.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/SBPBuildTasks.cs @@ -28,7 +28,7 @@ public static IList Create(string builtInShaderBundleName) #endif buildTasks.Add(new CalculateAssetDependencyData()); buildTasks.Add(new StripUnusedSpriteSources()); - buildTasks.Add(new CreateBuiltInShadersBundle(builtInShaderBundleName)); + buildTasks.Add(new CreateBuiltInBundle(builtInShaderBundleName)); buildTasks.Add(new PostDependencyCallback()); // Packing diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildPipeline.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildPipeline.cs index db62db66..1e87ab90 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildPipeline.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildPipeline.cs @@ -8,8 +8,15 @@ public class ScriptableBuildPipeline : IBuildPipeline { public BuildResult Run(BuildParameters buildParameters, bool enableLog) { - AssetBundleBuilder builder = new AssetBundleBuilder(); - return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); + if (buildParameters is ScriptableBuildParameters) + { + AssetBundleBuilder builder = new AssetBundleBuilder(); + return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); + } + else + { + throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}"); + } } /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs index 60beadef..55fc367b 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/BuiltinBuildPipelineViewer.cs @@ -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 @@ public BuiltinBuildPipelineViewer(string packageName, BuildTarget buildTarget, V } /// - /// ִй + /// 执行构建 /// protected override void ExecuteBuild() { diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs index c6dd0572..063869f3 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleBuilder/VisualViewers/RawfileBuildpipelineViewer.cs @@ -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 @@ public RawfileBuildpipelineViewer(string packageName, BuildTarget buildTarget, V } /// - /// ִй + /// 执行构建 /// protected override void ExecuteBuild() { diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs index dbf96127..87374888 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs @@ -166,7 +166,7 @@ public List GetAllCollectAssets(CollectCommand command, AssetB 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 @@ private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBun 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 @@ private List GetAllDependencies(CollectCommand command, string mainAs continue; AssetInfo assetInfo = new AssetInfo(assetPath); - if (IsValidateAsset(command, assetInfo)) + if (command.IgnoreRule.IsIgnore(assetInfo) == false) result.Add(assetInfo); } return result; diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs index 234286fe..24124104 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs @@ -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 @@ public class AssetBundleCollectorConfig 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 @@ public static void ImportXmlConfig(string filePath) 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 @@ public static void ExportXmlConfig(string savePath) 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 @@ private static bool UpdateXmlConfig(XmlDocument xmlDoc) 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; } } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs index 702cfbab..4c8d7c84 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorPackage.cs @@ -36,14 +36,14 @@ public class AssetBundleCollectorPackage public bool IncludeAssetGUID = false; /// - /// 忽略Unity引擎无法识别的文件 + /// 自动收集所有着色器(所有着色器存储在一个资源包内) /// - public bool IgnoreDefaultType = true; + public bool AutoCollectShaders = true; /// - /// 自动收集所有着色器(所有着色器存储在一个资源包内) + /// 资源忽略规则名 /// - public bool AutoCollectShaders = true; + public string IgnoreRuleName = nameof(NormalIgnoreRule); /// /// 分组列表 @@ -56,6 +56,16 @@ public class AssetBundleCollectorPackage /// 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 @@ public void CheckConfigError() 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 @@ public bool FixConfigError() isFixed = true; } } + return isFixed; } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs index df00a1ed..2e468223 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs @@ -24,7 +24,6 @@ public class AssetBundleCollectorSetting : ScriptableObject /// public bool UniqueBundleName = false; - /// /// 包裹列表 /// @@ -100,13 +99,13 @@ public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName) 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); diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs index ace3cfe1..c0c41a25 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs @@ -21,6 +21,9 @@ public class AssetBundleCollectorSettingData private static readonly Dictionary _cacheFilterRuleTypes = new Dictionary(); private static readonly Dictionary _cacheFilterRuleInstance = new Dictionary(); + private static readonly Dictionary _cacheIgnoreRuleTypes = new Dictionary(); + private static readonly Dictionary _cacheIgnoreRuleInstance = new Dictionary(); + /// /// 配置数据是否被修改 /// @@ -129,6 +132,29 @@ static AssetBundleCollectorSettingData() _cacheActiveRuleTypes.Add(type.Name, type); } } + + // IIgnoreRule + { + // 清空缓存集合 + _cacheIgnoreRuleTypes.Clear(); + _cacheIgnoreRuleInstance.Clear(); + + // 获取所有类型 + List types = new List(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 @@ public static void FixFile() if (isFixed) { IsDirty = true; + Debug.Log("Fix package config error done !"); } } @@ -225,6 +252,18 @@ public static List GetFilterRuleNames() } return names; } + public static List GetIgnoreRuleNames() + { + List names = new List(); + 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(type); @@ -250,6 +289,10 @@ public static bool HasFilterRuleName(string ruleName) { 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 @@ public static IFilterRule GetFilterRuleInstance(string ruleName) 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) diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs index 0ce35519..f4691727 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs @@ -24,6 +24,7 @@ public static void OpenWindow() private List _addressRuleList; private List _packRuleList; private List _filterRuleList; + private List _ignoreRuleList; private VisualElement _helpBoxContainer; @@ -39,9 +40,9 @@ public static void OpenWindow() private Toggle _enableAddressableToogle; private Toggle _locationToLowerToogle; private Toggle _includeAssetGUIDToogle; - private Toggle _ignoreDefaultTypeToogle; private Toggle _autoCollectShadersToogle; - + private PopupField _ignoreRulePopupField; + private VisualElement _packageContainer; private ListView _packageListView; private TextField _packageNameTxt; @@ -77,6 +78,7 @@ public void CreateGUI() _addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames(); _packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames(); _filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames(); + _ignoreRuleList = AssetBundleCollectorSettingData.GetIgnoreRuleNames(); VisualElement root = this.rootVisualElement; @@ -151,17 +153,6 @@ public void CreateGUI() RefreshWindow(); } }); - _ignoreDefaultTypeToogle = root.Q("IgnoreDefaultType"); - _ignoreDefaultTypeToogle.RegisterValueChangedCallback(evt => - { - var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage; - if (selectPackage != null) - { - selectPackage.IgnoreDefaultType = evt.newValue; - AssetBundleCollectorSettingData.ModifyPackage(selectPackage); - RefreshWindow(); - } - }); _autoCollectShadersToogle = root.Q("AutoCollectShaders"); _autoCollectShadersToogle.RegisterValueChangedCallback(evt => { @@ -173,6 +164,25 @@ public void CreateGUI() RefreshWindow(); } }); + { + _ignoreRulePopupField = new PopupField(_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 public string PackageName { private set; get; } - /// - /// 忽略Unity引擎无法识别的文件 - /// - public bool IgnoreDefaultType { private set; get; } - /// /// 启用可寻址资源定位 /// @@ -48,17 +43,24 @@ public class CollectCommand /// public string ShadersBundleName { private set; get; } + /// + /// 忽略规则实例 + /// + 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(); diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs new file mode 100644 index 00000000..525ed02b --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs @@ -0,0 +1,11 @@ + +namespace YooAsset.Editor +{ + /// + /// 资源忽略规则接口 + /// + public interface IIgnoreRule + { + bool IsIgnore(AssetInfo assetInfo); + } +} \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs.meta b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs.meta new file mode 100644 index 00000000..42183c07 --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/CollectRules/IIgnoreRule.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bd55753dbb880fa449bf4e37b33d8ba7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultFilterRule.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultFilterRule.cs index 3befd04f..bd4fccb3 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultFilterRule.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultFilterRule.cs @@ -6,22 +6,6 @@ namespace YooAsset.Editor { - public class DefaultFilterRule - { - /// - /// 忽略的文件类型 - /// - private readonly static HashSet _ignoreFileExtensions = new HashSet() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" }; - - /// - /// 查询是否为忽略文件 - /// - public static bool IsIgnoreFile(string fileExtension) - { - return _ignoreFileExtensions.Contains(fileExtension); - } - } - [DisplayName("收集所有资源")] public class CollectAll : IFilterRule { @@ -70,6 +54,15 @@ public bool IsCollectAsset(FilterRuleData data) } } + [DisplayName("收集着色器")] + public class CollectShader : IFilterRule + { + public bool IsCollectAsset(FilterRuleData data) + { + return Path.GetExtension(data.AssetPath) == ".shader"; + } + } + [DisplayName("收集着色器变种集合")] public class CollectShaderVariants : IFilterRule { diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs new file mode 100644 index 00000000..f516e782 --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs @@ -0,0 +1,82 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace YooAsset.Editor +{ + public class DefaultIgnoreRule + { + /// + /// 忽略的文件类型 + /// + public readonly static HashSet IgnoreFileExtensions = new HashSet() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" }; + } + + /// + /// 适配常规的资源构建管线 + /// + public class NormalIgnoreRule : IIgnoreRule + { + /// + /// 查询是否为忽略文件 + /// + 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); + } + } + + /// + /// 适配原生文件构建管线 + /// + public class RawFileIgnoreRule : IIgnoreRule + { + /// + /// 查询是否为忽略文件 + /// + 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); + } + } +} \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs.meta b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs.meta new file mode 100644 index 00000000..c5ecb7ce --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultIgnoreRule.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9c1900577194bb4ab49ce4332ccc4bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultPackRule.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultPackRule.cs index f6633ed8..80960a57 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultPackRule.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultPackRule.cs @@ -147,6 +147,18 @@ PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data) } } + /// + /// 打包着色器 + /// + [DisplayName("打包着色器文件")] + public class PackShader : IPackRule + { + public PackRuleResult GetPackRuleResult(PackRuleData data) + { + return DefaultPackRule.CreateShadersPackRuleResult(); + } + } + /// /// 打包着色器变种集合 /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/ReportSummary.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/ReportSummary.cs index af67b443..1bc382d4 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/ReportSummary.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/ReportSummary.cs @@ -58,8 +58,8 @@ public class ReportSummary public bool EnableAddressable; public bool LocationToLower; public bool IncludeAssetGUID; - public bool IgnoreDefaultType; public bool AutoCollectShaders; + public string IgnoreRuleName; // 构建参数 public bool EnableSharePackRule; diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs index ed6ff977..7142dec2 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs @@ -72,8 +72,8 @@ public void FillViewData(BuildReport buildReport) _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)); diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/EditorTools.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/EditorTools.cs index c7283a22..03fbc34a 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/EditorTools.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Editor/EditorTools.cs @@ -496,14 +496,6 @@ public static long GetFileSize(string filePath) return fileInfo.Length; } - /// - /// 获取文件的哈希值 - /// - public static string GetFileCRC32(string filePath) - { - return HashUtility.FileCRC32(filePath); - } - /// /// 读取文件的所有文本内容 /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/CacheHelper.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/CacheHelper.cs index 7bed804c..f99cb6e5 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/CacheHelper.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/CacheHelper.cs @@ -111,7 +111,7 @@ private static EVerifyResult VerifyingInternal(string filePath, long fileSize, s // 再验证文件CRC if (verifyLevel == EVerifyLevel.High) { - string crc = HashUtility.FileCRC32(filePath); + string crc = HashUtility.FileCRC32Safely(filePath); if (crc == fileCRC) return EVerifyResult.Succeed; else diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentHelper.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentHelper.cs index e9e981e2..dd757a4f 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentHelper.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentHelper.cs @@ -15,7 +15,7 @@ public static string ConvertToWWWPath(string path) #elif UNITY_IPHONE return StringUtility.Format("file://{0}", path); #elif UNITY_ANDROID - if (path.StartsWith("jar:file//")) + if (path.StartsWith("jar:file://")) return path; else return StringUtility.Format("jar:file://{0}", path); @@ -23,6 +23,8 @@ public static string ConvertToWWWPath(string path) return new System.Uri(path).ToString(); #elif UNITY_STANDALONE return StringUtility.Format("file:///{0}", path); +#elif UNITY_OPENHARMONY + return path; #else return path; #endif diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentManager.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentManager.cs index 3b93500a..fc5f5eb0 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentManager.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/CacheSystem/PersistentManager.cs @@ -58,7 +58,12 @@ public void Initialize(string buildinRoot, string sandboxRoot, bool appendFileEx } 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 @@ public string GetSandboxPackageVersionFilePath() /// public void SaveSandboxPackageVersionFile(string version) { + YooLogger.Log($"Save package version : {version}"); string filePath = GetSandboxPackageVersionFilePath(); FileUtility.WriteAllText(filePath, version); } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs index d9a26981..11d49f93 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs @@ -99,7 +99,8 @@ private void DisposeWebRequest() { if (_webRequest != null) { - _webRequest.Dispose(); //注意:引擎底层会自动调用Abort方法 + //注意:引擎底层会自动调用Abort方法 + _webRequest.Dispose(); _webRequest = null; } } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs index 103066fc..0936a466 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs @@ -142,6 +142,7 @@ private void DisposeWebRequest() if (_webRequest != null) { + //注意:引擎底层会自动调用Abort方法 _webRequest.Dispose(); _webRequest = null; } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs index 65a95586..1feeee4a 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs @@ -14,52 +14,52 @@ internal interface IWebRequester /// /// 任务状态 /// - public ERequestStatus Status { get; } + ERequestStatus Status { get; } /// /// 下载进度(0f~1f) /// - public float DownloadProgress { get; } + float DownloadProgress { get; } /// /// 已经下载的总字节数 /// - public ulong DownloadedBytes { get; } + ulong DownloadedBytes { get; } /// /// 返回的网络错误 /// - public string RequestNetError { get; } + string RequestNetError { get; } /// /// 返回的HTTP CODE /// - public long RequestHttpCode { get; } + long RequestHttpCode { get; } /// /// 创建任务 /// - public void Create(string url, BundleInfo bundleInfo, params object[] args); + void Create(string url, BundleInfo bundleInfo, params object[] args); /// /// 更新任务 /// - public void Update(); + void Update(); /// /// 终止任务 /// - public void Abort(); + void Abort(); /// /// 是否已经完成(无论成功或失败) /// - public bool IsDone(); + bool IsDone(); /// /// 获取请求的对象 /// - public object GetRequestObject(); + object GetRequestObject(); } } \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/InitializeParameters.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/InitializeParameters.cs index 8925dbba..b66f40b6 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/InitializeParameters.cs @@ -150,5 +150,10 @@ public class WebPlayModeParameters : InitializeParameters /// 内置资源查询服务接口 /// public IBuildinQueryServices BuildinQueryServices = null; + + /// + /// 微信缓存查询服务接口 + /// + public IWechatQueryServices WechatQueryServices = null; } } \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/RawFileHandle.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/RawFileHandle.cs index 446e2fe3..9f9215ef 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/RawFileHandle.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/RawFileHandle.cs @@ -64,7 +64,6 @@ public void Dispose() this.ReleaseInternal(); } - /// /// 获取原生文件的二进制数据 /// @@ -73,7 +72,11 @@ public byte[] GetRawFileData() if (IsValidWithWarning == false) return null; string filePath = Provider.RawFilePath; - return FileUtility.ReadAllBytes(filePath); + if (Provider.RawFileInfo == null || + Provider.RawFileInfo.Bundle.Encrypted == false) + return FileUtility.ReadAllBytes(filePath); + else + return Provider.RawFileInfo.LoadRawFile(filePath); } /// @@ -84,7 +87,11 @@ public string GetRawFileText() if (IsValidWithWarning == false) return null; string filePath = Provider.RawFilePath; - return FileUtility.ReadAllText(filePath); + if (Provider.RawFileInfo == null || + Provider.RawFileInfo.Bundle.Encrypted == false) + return FileUtility.ReadAllText(filePath); + else + return FileUtility.BytesToText(Provider.RawFileInfo.LoadRawFile(filePath)); } /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs index fcca55f4..bdeaab31 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs @@ -37,6 +37,16 @@ public event System.Action Completed } } + /// + /// 等待异步执行完毕 + /// + internal void WaitForAsyncComplete() + { + if (IsValidWithWarning == false) + return; + Provider.WaitForAsyncComplete(); + } + /// /// 场景名称 /// @@ -90,28 +100,21 @@ public bool UnSuspend() 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; } /// @@ -171,5 +174,7 @@ public UnloadSceneOperation UnloadAsync() return operation; } } + + } } \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Loader/AssetBundleFileLoader.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Loader/AssetBundleFileLoader.cs index 5feca6ce..cdd66654 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Loader/AssetBundleFileLoader.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Loader/AssetBundleFileLoader.cs @@ -208,22 +208,47 @@ public override void Update() // Check error if (CacheBundle == null) { - _steps = ESteps.Done; - Status = EStatus.Failed; - LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}"; - YooLogger.Error(LastError); - // 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。 // 在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性! if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache) { var result = MainBundleInfo.VerifySelf(); - if (result != EVerifyResult.Succeed) + if (result == EVerifyResult.Succeed) { - YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}"); + // 说明:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。 + // 大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发! + byte[] fileData = FileUtility.ReadAllBytes(FileLoadPath); + if (fileData != null && fileData.Length > 0) + CacheBundle = AssetBundle.LoadFromMemory(fileData); + if (CacheBundle == null) + { + _steps = ESteps.Done; + Status = EStatus.Failed; + LastError = $"Failed to load assetBundle from memory : {MainBundleInfo.Bundle.BundleName}"; + YooLogger.Error(LastError); + } + else + { + _steps = ESteps.Done; + Status = EStatus.Succeed; + } + } + else + { + _steps = ESteps.Done; + Status = EStatus.Failed; + LastError = $"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}"; + YooLogger.Error(LastError); MainBundleInfo.CacheDiscard(); } } + else + { + _steps = ESteps.Done; + Status = EStatus.Failed; + LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}"; + YooLogger.Error(LastError); + } } else { diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs index febb030c..9d4a7508 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs @@ -31,6 +31,22 @@ internal UnloadSceneOperation(ProviderBase provider) { _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() { @@ -82,7 +98,6 @@ internal override void InternalOnUpdate() { _asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject); _provider.ResourceMgr.UnloadSubScene(_provider.SceneName); - _provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo); _steps = ESteps.Checking; } @@ -91,7 +106,7 @@ internal override void InternalOnUpdate() Progress = _asyncOp.progress; if (_asyncOp.isDone == false) return; - + _provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo); _steps = ESteps.Done; Status = EOperationStatus.Succeed; } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs index 4a104a83..0900fdb1 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs @@ -45,6 +45,7 @@ internal override void InternalOnUpdate() if (_steps == ESteps.Checking) { RawFilePath = OwnerBundle.FileLoadPath; + RawFileInfo = OwnerBundle.MainBundleInfo; InvokeCompletion(string.Empty, EOperationStatus.Succeed); } } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs index 97573557..eda57712 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs @@ -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() { @@ -35,6 +35,12 @@ internal override void InternalOnUpdate() // 1. 检测资源包 if (_steps == ESteps.CheckBundle) { + if (IsWaitForAsyncComplete) + { + DependBundles.WaitForAsyncComplete(); + OwnerBundle.WaitForAsyncComplete(); + } + if (DependBundles.IsDone() == false) return; if (OwnerBundle.IsDone() == false) @@ -60,53 +66,81 @@ internal override void InternalOnUpdate() // 2. 加载场景 if (_steps == ESteps.Loading) { - // 注意:如果场景不存在则返回NULL - _asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode); - if (_asyncOperation != null) + if (IsWaitForAsyncComplete || IsForceDestroyComplete) { - _asyncOperation.allowSceneActivation = !_suspendLoad; - _asyncOperation.priority = 100; - SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); + // 注意:场景同步加载方法不会立即加载场景,而是在下一帧加载。 + LoadSceneParameters parameters = new LoadSceneParameters(SceneMode); + SceneObject = SceneManager.LoadScene(MainAssetInfo.AssetPath, parameters); _steps = ESteps.Checking; } else { - string error = $"Failed to load scene : {MainAssetInfo.AssetPath}"; - YooLogger.Error(error); - InvokeCompletion(error, EOperationStatus.Failed); + // 注意:如果场景不存在异步加载方法返回NULL + // 注意:即使是异步加载也要在当帧获取到场景对象 + _asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode); + if (_asyncOperation != null) + { + _asyncOperation.allowSceneActivation = !_suspendLoadMode; + _asyncOperation.priority = 100; + SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); + _steps = ESteps.Checking; + } + else + { + string error = $"Failed to load scene : {MainAssetInfo.AssetPath}"; + YooLogger.Error(error); + InvokeCompletion(error, EOperationStatus.Failed); + } } } // 3. 检测加载结果 if (_steps == ESteps.Checking) { - Progress = _asyncOperation.progress; - if (_asyncOperation.isDone) + if (_asyncOperation != null) { - if (SceneObject.IsValid()) + if (IsWaitForAsyncComplete || IsForceDestroyComplete) { - InvokeCompletion(string.Empty, EOperationStatus.Succeed); + // 场景加载无法强制异步转同步 + YooLogger.Error("The scene is loading asyn !"); } else { - string error = $"The load scene is invalid : {MainAssetInfo.AssetPath}"; - YooLogger.Error(error); - InvokeCompletion(error, EOperationStatus.Failed); + // 注意:在业务层中途可以取消挂起 + if (_asyncOperation.allowSceneActivation == false) + { + if (_suspendLoadMode == false) + _asyncOperation.allowSceneActivation = true; + } + + Progress = _asyncOperation.progress; + if (_asyncOperation.isDone == false) + return; } } + + if (SceneObject.IsValid()) + { + InvokeCompletion(string.Empty, EOperationStatus.Succeed); + } + else + { + string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}"; + YooLogger.Error(error); + InvokeCompletion(error, EOperationStatus.Failed); + } } } /// /// 解除场景加载挂起操作 /// - public bool UnSuspendLoad() + public void UnSuspendLoad() { - if (_asyncOperation == null) - return false; - - _asyncOperation.allowSceneActivation = true; - return true; + if (IsDone == false) + { + _suspendLoadMode = false; + } } } } \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs index 8173b14c..11b55fd7 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs @@ -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() { @@ -57,41 +57,67 @@ internal override void InternalOnUpdate() // 2. 加载资源对象 if (_steps == ESteps.Loading) { - LoadSceneParameters loadSceneParameters = new LoadSceneParameters(); - loadSceneParameters.loadSceneMode = SceneMode; - _asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters); - if (_asyncOperation != null) + if (IsWaitForAsyncComplete || IsForceDestroyComplete) { - _asyncOperation.allowSceneActivation = !_suspendLoad; - _asyncOperation.priority = 100; - SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); + LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode); + SceneObject = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters); _steps = ESteps.Checking; } else { - string error = $"Failed to load scene : {MainAssetInfo.AssetPath}"; - YooLogger.Error(error); - InvokeCompletion(error, EOperationStatus.Failed); + LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode); + _asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters); + if (_asyncOperation != null) + { + _asyncOperation.allowSceneActivation = !_suspendLoadMode; + _asyncOperation.priority = 100; + SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); + _steps = ESteps.Checking; + } + else + { + string error = $"Failed to load scene : {MainAssetInfo.AssetPath}"; + YooLogger.Error(error); + InvokeCompletion(error, EOperationStatus.Failed); + } } } // 3. 检测加载结果 if (_steps == ESteps.Checking) { - Progress = _asyncOperation.progress; - if (_asyncOperation.isDone) + if (_asyncOperation != null) { - if (SceneObject.IsValid()) + if (IsWaitForAsyncComplete || IsForceDestroyComplete) { - InvokeCompletion(string.Empty, EOperationStatus.Succeed); + // 场景加载无法强制异步转同步 + YooLogger.Error("The scene is loading asyn !"); } else { - string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}"; - YooLogger.Error(error); - InvokeCompletion(error, EOperationStatus.Failed); + // 注意:在业务层中途可以取消挂起 + if (_asyncOperation.allowSceneActivation == false) + { + if (_suspendLoadMode == false) + _asyncOperation.allowSceneActivation = true; + } + + Progress = _asyncOperation.progress; + if (_asyncOperation.isDone == false) + return; } } + + if (SceneObject.IsValid()) + { + InvokeCompletion(string.Empty, EOperationStatus.Succeed); + } + else + { + string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}"; + YooLogger.Error(error); + InvokeCompletion(error, EOperationStatus.Failed); + } } #endif } @@ -99,13 +125,12 @@ internal override void InternalOnUpdate() /// /// 解除场景加载挂起操作 /// - public bool UnSuspendLoad() + public void UnSuspendLoad() { - if (_asyncOperation == null) - return false; - - _asyncOperation.allowSceneActivation = true; - return true; + if (IsDone == false) + { + _suspendLoadMode = false; + } } } } \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs index 5a54f112..a3211b1f 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs @@ -57,6 +57,11 @@ protected enum ESteps /// public string RawFilePath { protected set; get; } + /// + /// 原生文件信息 + /// + public BundleInfo RawFileInfo { protected set; get; } + /// /// 引用计数 /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/ResourceLoader.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/ResourceLoader.cs index 029c0b7e..81d6e023 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/ResourceLoader.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourceManager/ResourceLoader.cs @@ -14,6 +14,27 @@ public void Init(IDecryptionServices decryption, IDeliveryLoadServices delivery) _delivery = delivery; } + /// + /// 同步加载原生数据对象 + /// + /// + /// + /// + public byte[] LoadRawFile(BundleInfo bundleInfo, string fileLoadPath) + { + if (_decryption == null) + { + YooLogger.Error($"{nameof(IDecryptionServices)} is null ! when load raw file {bundleInfo.Bundle.BundleName}!"); + return null; + } + + DecryptFileInfo fileInfo = new DecryptFileInfo(); + fileInfo.BundleName = bundleInfo.Bundle.BundleName; + fileInfo.FileLoadPath = fileLoadPath; + fileInfo.ConentCRC = bundleInfo.Bundle.UnityCRC; + return _decryption.LoadRawFileData(fileInfo); + } + /// /// 同步加载资源包对象 /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/BundleInfo.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/BundleInfo.cs index 5a0dcd68..e56abad6 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/BundleInfo.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/BundleInfo.cs @@ -146,6 +146,13 @@ public DownloaderBase CreateUnpacker(int failedTryAgain, int timeout = 60) } #endregion + #region RawFile + internal byte[] LoadRawFile(string fileLoadPath) + { + return _assist.Loader.LoadRawFile(this, fileLoadPath); + } + #endregion + #region AssetBundle internal AssetBundle LoadAssetBundle(string fileLoadPath, out Stream managedStream) { diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs index f7a7fa1c..e67993c6 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs @@ -332,6 +332,7 @@ internal override void InternalOnUpdate() { PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion; _impl.ActiveManifest = _loadBuildinManifestOp.Manifest; + _impl.FlushManifestVersionFile(); //注意:解压内置清单并加载成功后保存该清单版本。 _steps = ESteps.PackageCaching; } else diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs index 57baf65c..9ff63e11 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs @@ -77,7 +77,7 @@ internal override void InternalOnUpdate() return; } - string fileHash = HashUtility.FileMD5(_manifestFilePath); + string fileHash = HashUtility.FileMD5Safely(_manifestFilePath); if (fileHash != _queryCachePackageHashOp.PackageHash) { _steps = ESteps.Done; diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs index 1db57746..0019b211 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs @@ -63,7 +63,6 @@ private enum ESteps TryLoadCacheManifest, DownloadManifest, LoadCacheManifest, - CheckDeserializeManifest, Done, } diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs index de073072..5b9cc70d 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs @@ -10,6 +10,7 @@ internal class WebPlayModeImpl : IPlayMode, IBundleQuery private ResourceAssist _assist; private IBuildinQueryServices _buildinQueryServices; private IRemoteServices _remoteServices; + private IWechatQueryServices _wechatQueryServices; public readonly string PackageName; public DownloadManager Download @@ -34,11 +35,12 @@ public WebPlayModeImpl(string packageName) /// /// 异步初始化 /// - 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 @@ private List ConvertToDownloadList(List downloadList) } // 查询相关 -#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); diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 6b668412..0629bdb1 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -184,7 +184,8 @@ public InitializationOperation InitializeAsync(InitializeParameters parameters) var initializeParameters = parameters as WebPlayModeParameters; initializeOperation = webPlayModeImpl.InitializeAsync(assist, initializeParameters.BuildinQueryServices, - initializeParameters.RemoteServices); + initializeParameters.RemoteServices, + initializeParameters.WechatQueryServices); } else { @@ -413,10 +414,13 @@ public ClearAllCacheFilesOperation ClearAllCacheFilesAsync() return operation; } + /// + /// 获取指定版本的缓存信息 + /// public GetAllCacheFileInfosOperation GetAllCacheFileInfosAsync(string packageVersion) { DebugCheckInitialize(); - + var operation = new GetAllCacheFileInfosOperation(_persistentMgr, _cacheMgr, packageVersion); OperationSystem.StartOperation(PackageName, operation); return operation; @@ -599,6 +603,29 @@ private RawFileHandle LoadRawFileInternal(AssetInfo assetInfo, bool waitForAsync #endregion #region 场景加载 + /// + /// 同步加载场景 + /// + /// 场景的定位地址 + /// 场景加载模式 + public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single) + { + DebugCheckInitialize(); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + return LoadSceneInternal(assetInfo, true, sceneMode, false, 0); + } + + /// + /// 同步加载场景 + /// + /// 场景的资源信息 + /// 场景加载模式 + public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single) + { + DebugCheckInitialize(); + return LoadSceneInternal(assetInfo, true, sceneMode, false, 0); + } + /// /// 异步加载场景 /// @@ -610,8 +637,7 @@ public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = Loa { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - var handle = _resourceMgr.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority); - return handle; + return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority); } /// @@ -624,7 +650,16 @@ public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = Loa public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 0) { DebugCheckInitialize(); + return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority); + } + + private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, bool suspendLoad, uint priority) + { + DebugCheckAssetLoadMethod(nameof(LoadAssetAsync)); + DebugCheckAssetLoadType(assetInfo.AssetType); var handle = _resourceMgr.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority); + if (waitForAsyncComplete) + handle.WaitForAsyncComplete(); return handle; } #endregion diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IDecryptionServices.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IDecryptionServices.cs index a85877e1..1322a560 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IDecryptionServices.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IDecryptionServices.cs @@ -40,5 +40,12 @@ public interface IDecryptionServices /// 注意:加载流对象在资源包对象释放的时候会自动释放 /// AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream); + + /// + /// 同步方式获取解密原生文件的二进制数据 + /// + /// + /// + byte[] LoadRawFileData(DecryptFileInfo fileInfo); } } \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IWechatQueryServices.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IWechatQueryServices.cs new file mode 100644 index 00000000..c225bdb5 --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IWechatQueryServices.cs @@ -0,0 +1,15 @@ + +namespace YooAsset +{ + public interface IWechatQueryServices + { + /// + /// 查询是否为微信缓存的资源文件 + /// + /// 包裹名称 + /// 文件名称(包含文件的后缀格式) + /// 文件哈希值 + /// 返回查询结果 + bool Query(string packageName, string fileName, string fileCRC); + } +} \ No newline at end of file diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta new file mode 100644 index 00000000..e7455b44 --- /dev/null +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Services/IWechatQueryServices.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e6b28ce9425f5eb4f972dcda9fd864f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Utility/YooUtility.cs index 550a6826..e5f4ad1c 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/Utility/YooUtility.cs @@ -115,6 +115,18 @@ public static string Format(string format, params object[] args) /// internal static class FileUtility { + /// + /// 字节数据转换成文本数据 + /// + /// + /// + public static string BytesToText(byte[] data) + { + UTF8Encoding utf8 = new UTF8Encoding(); + string txt = utf8.GetString(data); + return txt; + } + /// /// 读取文件的文本数据 /// @@ -214,13 +226,21 @@ public static string StringSHA1(string str) /// 获取文件的Hash值 /// public static string FileSHA1(string filePath) + { + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + return StreamSHA1(fs); + } + } + + /// + /// 获取文件的Hash值 + /// + 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 +286,21 @@ public static string StringMD5(string str) /// 获取文件的MD5 /// public static string FileMD5(string filePath) + { + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + return StreamMD5(fs); + } + } + + /// + /// 获取文件的MD5 + /// + 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 +344,21 @@ public static string StringCRC32(string str) /// 获取文件的CRC32 /// public static string FileCRC32(string filePath) + { + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + return StreamCRC32(fs); + } + } + + /// + /// 获取文件的CRC32 + /// + 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) { diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/YooAssetsExtension.cs b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/YooAssetsExtension.cs index 927aa82f..edaf7cf6 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/YooAssetsExtension.cs +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/Runtime/YooAssetsExtension.cs @@ -156,6 +156,28 @@ public static RawFileHandle LoadRawFileAsync(string location, uint priority = 0) #endregion #region 场景加载 + /// + /// 同步加载场景 + /// + /// 场景的定位地址 + /// 场景加载模式 + public static SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single) + { + DebugCheckDefaultPackageValid(); + return _defaultPackage.LoadSceneSync(location, sceneMode); + } + + /// + /// 同步加载场景 + /// + /// 场景的资源信息 + /// 场景加载模式 + public static SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single) + { + DebugCheckDefaultPackageValid(); + return _defaultPackage.LoadSceneSync(assetInfo, sceneMode); + } + /// /// 异步加载场景 /// diff --git a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/package.json b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/package.json index e11449b9..6863ffcf 100644 --- a/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/package.json +++ b/Assets/OxGFrame/AssetLoader/ThirdParty/YooAsset/package.json @@ -31,7 +31,7 @@ }, "relatedPackages": {}, "dependencies": { - "com.unity.scriptablebuildpipeline": "1.21.21", + "com.unity.scriptablebuildpipeline": "2.1.3", "com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0", "com.unity.modules.unitywebrequestassetbundle": "1.0.0" diff --git a/Assets/OxGFrame/CHANGELOG.md b/Assets/OxGFrame/CHANGELOG.md index 1cf6aeee..2c0e3dd8 100644 --- a/Assets/OxGFrame/CHANGELOG.md +++ b/Assets/OxGFrame/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +## [2.11.0] -2024-05-12 +- Updated YooAsset commits. +- Updated Scriptable Build Pipeline to v2.1.3 (Unity). +- Added YooAsset can support RawFile encryption. +- Added Hotfixer can new PackageInfoWithBuild to CheckHotfix method. +- Optimized Support Hotfix to be loaded using other threads (WebGL is not supported). + ## [2.10.5] -2024-04-17 - Fixed SimpleDiskUtils compile error issue on WIN. diff --git a/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixFsm/HotfixFsmStates.cs b/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixFsm/HotfixFsmStates.cs index d06c7040..4da20eb2 100644 --- a/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixFsm/HotfixFsmStates.cs +++ b/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixFsm/HotfixFsmStates.cs @@ -75,12 +75,16 @@ void IStateNode.OnExit() private async UniTask _InitHotfixPackage() { - AppPackageInfoWithBuild packageInfo = new AppPackageInfoWithBuild() + PackageInfoWithBuild packageInfoWithBuild = HotfixManager.GetInstance().packageInfoWithBuild; + if (packageInfoWithBuild == null) { - buildMode = BundleConfig.BuildMode.ScriptableBuildPipeline, - packageName = HotfixManager.GetInstance().packageName - }; - bool isInitialized = await AssetPatcher.InitAppPackage(packageInfo); + packageInfoWithBuild = new AppPackageInfoWithBuild() + { + buildMode = BundleConfig.BuildMode.ScriptableBuildPipeline, + packageName = HotfixManager.GetInstance().packageName + }; + } + bool isInitialized = await AssetPatcher.InitPackage(packageInfoWithBuild); if (isInitialized) this._machine.ChangeState(); else HotfixEvents.HotfixInitFailed.SendEventMessage(); } @@ -330,8 +334,16 @@ private async UniTask _LoadAOTAssemblies() foreach (var dllName in aotMetaAssemblyFiles) { var dll = await AssetLoaders.LoadAssetAsync(HotfixManager.GetInstance().packageName, dllName); +#if !UNITY_WEBGL + // 切換至其他線程 + await UniTask.SwitchToThreadPool(); +#endif // 加載 assembly 對應的 dll, 會自動為它 hook, 一旦 aot 泛型函數的 native 函數不存在, 用解釋器版本代碼 LoadImageErrorCode err = RuntimeApi.LoadMetadataForAOTAssembly(dll.bytes, mode); +#if !UNITY_WEBGL + // 切回至主線程 + await UniTask.SwitchToMainThread(); +#endif // Unload after load AssetLoaders.UnloadAsset(dllName); Logging.Print($"Load AOT Assembly: {dllName}, mode: {mode}, ret: {err}"); @@ -400,7 +412,16 @@ private async UniTask _LoadHotfixAssemblies() else { var dll = await AssetLoaders.LoadAssetAsync(HotfixManager.GetInstance().packageName, dllName); +#if !UNITY_WEBGL + // 切換至其他線程 + await UniTask.SwitchToThreadPool(); +#endif + // 加載熱更 dlls hotfixAsm = Assembly.Load(dll.bytes); +#if !UNITY_WEBGL + // 切回至主線程 + await UniTask.SwitchToMainThread(); +#endif // Unload after load AssetLoaders.UnloadAsset(dllName); } diff --git a/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixManager.cs b/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixManager.cs index 468055f6..a022f5f7 100644 --- a/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixManager.cs +++ b/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfix/HotfixManager.cs @@ -1,4 +1,5 @@ -using OxGFrame.Hotfixer.HotfixEvent; +using OxGFrame.AssetLoader.Bundle; +using OxGFrame.Hotfixer.HotfixEvent; using OxGFrame.Hotfixer.HotfixFsm; using OxGKit.LoggingSystem; using System.Collections.Generic; @@ -12,6 +13,7 @@ namespace OxGFrame.Hotfixer internal class HotfixManager { public string packageName { get; private set; } + public PackageInfoWithBuild packageInfoWithBuild { get; private set; } = null; public ResourceDownloaderOperation mainDownloader; private bool _isCheck = false; @@ -165,6 +167,36 @@ public void CheckHotfix(string packageName, string[] aotAssemblies, string[] hot Logging.PrintWarning("Hotfix Checking..."); } } + + public void CheckHotfix(PackageInfoWithBuild packageInfoWithBuild, string[] aotAssemblies, string[] hotfixAssemblies) + { + if (this._isDone) + { + Logging.Print("Hotfix all are loaded."); + return; + } + + if (!this._isCheck) + { + this._isCheck = true; + + // Hotfix package name + this.packageInfoWithBuild = packageInfoWithBuild; + + // Add AOT assemblies + this._aotAssemblies = aotAssemblies; + + // Add Hotfix assemblies + this._hotfixAssemblies = hotfixAssemblies; + + // Run hotfix procedure + this._hotfixFsm.Run(); + } + else + { + Logging.PrintWarning("Hotfix Checking..."); + } + } #endregion #region Hotfix Flag diff --git a/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfixers.cs b/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfixers.cs index 73753497..0f5d6f10 100644 --- a/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfixers.cs +++ b/Assets/OxGFrame/Hotfixer/Scripts/Runtime/Hotfixers.cs @@ -1,3 +1,4 @@ +using OxGFrame.AssetLoader.Bundle; using System.Reflection; namespace OxGFrame.Hotfixer @@ -5,7 +6,7 @@ namespace OxGFrame.Hotfixer public static class Hotfixers { /// - /// Start hotfix files download and load all + /// Start hotfix files download and load all (default is AppPackageInfoWithBuild) /// /// /// @@ -15,6 +16,17 @@ public static void CheckHotfix(string packageName, string[] aotAssemblies, strin HotfixManager.GetInstance().CheckHotfix(packageName, aotAssemblies, hotfixAssemblies); } + /// + /// Start hotfix files download and load all + /// + /// + /// + /// + public static void CheckHotfix(PackageInfoWithBuild packageInfoWithBuild, string[] aotAssemblies, string[] hotfixAssemblies) + { + HotfixManager.GetInstance().CheckHotfix(packageInfoWithBuild, aotAssemblies, hotfixAssemblies); + } + /// /// Get hotfix assembly /// diff --git a/Assets/OxGFrame/package.json b/Assets/OxGFrame/package.json index 36040a30..45c5e0af 100644 --- a/Assets/OxGFrame/package.json +++ b/Assets/OxGFrame/package.json @@ -2,7 +2,7 @@ "name": "com.michaelo.oxgframe", "displayName": "OxGFrame", "description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, OSX, Android, iOS, WebGL.", - "version": "2.10.5", + "version": "2.11.0", "unity": "2021.3", "license": "MIT", "samples": [ @@ -83,7 +83,7 @@ } ], "dependencies": { - "com.unity.scriptablebuildpipeline": "1.21.22" + "com.unity.scriptablebuildpipeline": "2.1.3" }, "author": { "name": "MichaelO", diff --git a/Packages/manifest.json b/Packages/manifest.json index 72cba242..4d6fbec8 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -19,7 +19,7 @@ "com.unity.memoryprofiler": "0.7.1-preview.1", "com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.render-pipelines.universal": "12.1.13", - "com.unity.scriptablebuildpipeline": "1.21.7", + "com.unity.scriptablebuildpipeline": "2.1.3", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.8", "com.unity.timeline": "1.6.5", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index c0d8448e..95f878f3 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -5,14 +5,14 @@ "depth": 0, "source": "git", "dependencies": {}, - "hash": "67c487f521087a3887e6c8817dff3cd264aa4f20" + "hash": "95922aec1ed8eb385caa68b7662e9caa9f9685c6" }, "com.cysharp.unitask": { "version": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask", "depth": 0, "source": "git", "dependencies": {}, - "hash": "0c8057c66852e7d720966ef076d4924ebb27e80c" + "hash": "fbe0bf85155f42f8832205f7b3ac3df571ada33e" }, "com.domybest.lwmybox": { "version": "https://github.com/michael811125/LWMyBox.git", @@ -21,7 +21,7 @@ "dependencies": { "com.unity.ugui": "1.0.0" }, - "hash": "9816f6cb6b3475b762488ba716d6953caab611d5" + "hash": "42b343614ebe621cb9a3470f3c400eaaa8cf6f1b" }, "com.jeffjadulco.guidregenerator": { "version": "https://github.com/jeffjadulco/unity-guid-regenerator.git", @@ -35,14 +35,14 @@ "depth": 0, "source": "git", "dependencies": {}, - "hash": "79948ba60ee32a71558ef3b916844eff3913595f" + "hash": "f0278d119d59ac53b353d8ab4e12b5eaa3413ede" }, "com.michaelo.oxgkit.utilities": { "version": "https://github.com/michael811125/OxGKit.git?path=Assets/OxGKit/Utilities/Scripts", "depth": 0, "source": "git", "dependencies": {}, - "hash": "ba952548433885b05744ae660e8c4e5c9d836794" + "hash": "f0278d119d59ac53b353d8ab4e12b5eaa3413ede" }, "com.unity.2d.animation": { "version": "7.0.13", @@ -217,7 +217,7 @@ } }, "com.unity.scriptablebuildpipeline": { - "version": "1.21.7", + "version": "2.1.3", "depth": 0, "source": "registry", "dependencies": {},