Compare commits

..

2 Commits

Author SHA1 Message Date
MichaelO
e984d69c48 Merge 0b4f6d6639 into 4d2df5b705 2025-03-13 18:59:05 +08:00
MichaelO
0b4f6d6639 Updated to use StreamingAssets to request BuildinCatalog.json 2025-03-12 19:07:41 +08:00
20 changed files with 155 additions and 167 deletions

View File

@@ -2,15 +2,6 @@
All notable changes to this package will be documented in this file.
## [2.3.5-preview] - 2025-03-14
### Fixed
- (#502) 修复了原生缓存文件由于文件格式变动导致的加载本地缓存文件失败的问题。
- (#504) 修复了MacOS平台Offline Play Mode模式请求本地资源清单失败的问题。
- (#506) 修复了v2.3x版本LoadAllAssets方法计算依赖Bundle不完整的问题。
- (#506) 修复了微信小游戏文件系统在启用加密算法后卸载bundle报错的问题。
## [2.3.4-preview] - 2025-03-08
### Improvements

View File

@@ -15,6 +15,7 @@ namespace YooAsset.Editor
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
}
}
}

View File

@@ -16,6 +16,7 @@ namespace YooAsset.Editor
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
}
}
}

View File

@@ -15,6 +15,7 @@ namespace YooAsset.Editor
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
}
}
}

View File

@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
/// <summary>
/// 内置资源清单目录
/// </summary>
internal class DefaultBuildinFileCatalog : ScriptableObject
[Serializable]
internal class DefaultBuildinFileCatalog
{
[Serializable]
public class FileWrapper

View File

@@ -338,8 +338,8 @@ namespace YooAsset
}
public string GetCatalogFileLoadPath()
{
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
string fileName = DefaultBuildinFileSystemDefine.BuildinCatalogFileName;
return PathUtility.Combine(YooAssetSettingsData.GetRequestYooDefaultBuildinRoot(), PackageName, fileName);
}
/// <summary>

View File

@@ -5,22 +5,16 @@ using UnityEngine;
namespace YooAsset
{
public class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
public class DefaultBuildinFileSystemBuild
{
public int callbackOrder { get { return 0; } }
/// <summary>
/// 在构建应用程序前自动生成内置资源目录文件
/// 原理搜索StreamingAssets目录下的所有资源文件然后将这些文件信息写入文件并存储在Resources目录下。
/// 输出包裹的内置资源目录文件
/// </summary>
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
/// <exception cref="System.Exception"></exception>
public static void ExportBuildinCatalogFile()
{
YooLogger.Log("Begin to create catalog file !");
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
if (UnityEditor.AssetDatabase.DeleteAsset(savePath))
UnityEditor.AssetDatabase.Refresh();
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists == false)
@@ -87,7 +81,7 @@ namespace YooAsset
}
// 创建内置清单实例
var buildinFileCatalog = ScriptableObject.CreateInstance<DefaultBuildinFileCatalog>();
var buildinFileCatalog = new DefaultBuildinFileCatalog();
buildinFileCatalog.PackageName = packageName;
buildinFileCatalog.PackageVersion = packageVersion;
@@ -111,6 +105,8 @@ namespace YooAsset
continue;
if (fileInfo.Name == $"{packageName}_{packageVersion}.report")
continue;
if (fileInfo.Name == DefaultBuildinFileSystemDefine.BuildinCatalogFileName)
continue;
string fileName = fileInfo.Name;
if (fileMapping.TryGetValue(fileName, out string bundleGUID))
@@ -125,18 +121,13 @@ namespace YooAsset
}
// 创建输出目录
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath();
string fullPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
FileUtility.CreateFileDirectory(saveFilePath);
// 创建输出文件
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
#if UNITY_2019
UnityEditor.AssetDatabase.SaveAssets();
#else
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
#endif
File.WriteAllText(saveFilePath, JsonUtility.ToJson(buildinFileCatalog, false));
UnityEditor.AssetDatabase.Refresh();
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
return true;

View File

@@ -6,6 +6,6 @@ namespace YooAsset
/// <summary>
/// 内置清单文件名称
/// </summary>
public const string BuildinCatalogFileName = "BuildinCatalog.asset";
public const string BuildinCatalogFileName = "BuildinCatalog.json";
}
}

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
@@ -8,9 +9,11 @@ namespace YooAsset
{
None,
LoadCatalog,
WaitForRequest,
Done,
}
private UnityWebRequest _request;
private readonly DefaultBuildinFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
@@ -28,12 +31,39 @@ namespace YooAsset
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
if (_steps == ESteps.LoadCatalog)
{
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
_request = UnityWebRequest.Get(catalogFilePath);
_request.SendWebRequest();
_steps = ESteps.WaitForRequest;
return;
}
if (_steps == ESteps.WaitForRequest)
{
// 等待请求完成
if (!_request.isDone)
return;
if (_request.result != UnityWebRequest.Result.Success)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load catalog file: {_request.error}";
return;
}
// 解析 JSON
string jsonText = _request.downloadHandler.text;
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
if (catalog == null)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load catalog file : {catalogFilePath}";
@@ -42,6 +72,8 @@ namespace YooAsset
if (catalog.PackageName != _fileSystem.PackageName)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
@@ -55,6 +87,8 @@ namespace YooAsset
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}

View File

@@ -333,13 +333,6 @@ namespace YooAsset
{
return _records.Keys.ToList();
}
public RecordFileElement GetRecordFileElement(PackageBundle bundle)
{
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element))
return element;
else
return null;
}
public string GetTempFilePath(PackageBundle bundle)
{
@@ -391,10 +384,10 @@ namespace YooAsset
public EFileVerifyResult VerifyCacheFile(PackageBundle bundle)
{
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element) == false)
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement wrapper) == false)
return EFileVerifyResult.CacheNotFound;
EFileVerifyResult result = FileVerifyHelper.FileVerify(element.DataFilePath, element.DataFileSize, element.DataFileCRC, EFileVerifyLevel.High);
EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
return result;
}
public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)
@@ -434,10 +427,22 @@ namespace YooAsset
}
public bool DeleteCacheBundleFile(string bundleGUID)
{
if (_records.TryGetValue(bundleGUID, out RecordFileElement element))
if (_records.TryGetValue(bundleGUID, out RecordFileElement wrapper))
{
_records.Remove(bundleGUID);
return element.DeleteFolder();
try
{
string dataFilePath = wrapper.DataFilePath;
FileInfo fileInfo = new FileInfo(dataFilePath);
if (fileInfo.Exists)
fileInfo.Directory.Delete(true);
_records.Remove(bundleGUID);
return true;
}
catch (Exception e)
{
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
return false;
}
}
else
{

View File

@@ -1,6 +1,4 @@
using System;
using System.IO;

namespace YooAsset
{
internal class RecordFileElement
@@ -9,7 +7,7 @@ namespace YooAsset
public string DataFilePath { private set; get; }
public string DataFileCRC { private set; get; }
public long DataFileSize { private set; get; }
public RecordFileElement(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
{
InfoFilePath = infoFilePath;
@@ -17,31 +15,5 @@ namespace YooAsset
DataFileCRC = dataFileCRC;
DataFileSize = dataFileSize;
}
/// <summary>
/// 删除记录文件
/// </summary>
public bool DeleteFolder()
{
try
{
string directory = Path.GetDirectoryName(InfoFilePath);
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
if (directoryInfo.Exists)
{
directoryInfo.Delete(true);
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
return false;
}
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using UnityEngine;
namespace YooAsset
@@ -261,30 +260,9 @@ namespace YooAsset
{
if (_fileSystem.Exists(_bundle))
{
// 注意:缓存的原生文件的格式,可能会在业务端根据需求发生变动!
// 注意:这里需要校验文件格式,如果不一致对本地文件进行修正!
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
if (File.Exists(filePath) == false)
{
try
{
var recordFileElement = _fileSystem.GetRecordFileElement(_bundle);
File.Move(recordFileElement.DataFilePath, filePath);
_steps = ESteps.LoadCacheRawBundle;
}
catch (Exception e)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Faild rename raw data file : {e.Message}";
}
}
else
{
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadCacheRawBundle;
}
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
_steps = ESteps.LoadCacheRawBundle;
}
else
{

View File

@@ -7,10 +7,9 @@ namespace YooAsset
private enum ESteps
{
None,
CheckManifest,
CheckArgs,
GetClearCacheFiles,
ClearFilterCacheFiles,
GetTagsCacheFiles,
ClearTagsCacheFiles,
Done,
}
@@ -30,27 +29,13 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.CheckManifest;
_steps = ESteps.CheckArgs;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckManifest)
{
if (_manifest == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !";
}
else
{
_steps = ESteps.CheckArgs;
}
}
if (_steps == ESteps.CheckArgs)
{
if (_clearParam == null)
@@ -82,17 +67,17 @@ namespace YooAsset
return;
}
_steps = ESteps.GetClearCacheFiles;
_steps = ESteps.GetTagsCacheFiles;
}
if (_steps == ESteps.GetClearCacheFiles)
if (_steps == ESteps.GetTagsCacheFiles)
{
_clearBundleGUIDs = GetBundleGUIDsByTag();
_clearBundleGUIDs = GetTagsBundleGUIDs();
_clearFileTotalCount = _clearBundleGUIDs.Count;
_steps = ESteps.ClearFilterCacheFiles;
_steps = ESteps.ClearTagsCacheFiles;
}
if (_steps == ESteps.ClearFilterCacheFiles)
if (_steps == ESteps.ClearTagsCacheFiles)
{
for (int i = _clearBundleGUIDs.Count - 1; i >= 0; i--)
{
@@ -115,7 +100,7 @@ namespace YooAsset
}
}
}
private List<string> GetBundleGUIDsByTag()
private List<string> GetTagsBundleGUIDs()
{
var allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
List<string> result = new List<string>(allBundleGUIDs.Count);

View File

@@ -8,7 +8,6 @@ namespace YooAsset
private enum ESteps
{
None,
CheckManifest,
GetUnusedCacheFiles,
ClearUnusedCacheFiles,
Done,
@@ -20,7 +19,7 @@ namespace YooAsset
private int _unusedFileTotalCount = 0;
private ESteps _steps = ESteps.None;
internal ClearUnusedCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest)
{
_fileSystem = fileSystem;
@@ -28,29 +27,15 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.CheckManifest;
_steps = ESteps.GetUnusedCacheFiles;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckManifest)
{
if (_manifest == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !";
}
else
{
_steps = ESteps.GetUnusedCacheFiles;
}
}
if (_steps == ESteps.GetUnusedCacheFiles)
{
{
_unusedBundleGUIDs = GetUnusedBundleGUIDs();
_unusedFileTotalCount = _unusedBundleGUIDs.Count;
_steps = ESteps.ClearUnusedCacheFiles;

View File

@@ -8,7 +8,6 @@ namespace YooAsset
private enum ESteps
{
None,
CheckManifest,
ClearUnusedCacheFiles,
Done,
}
@@ -25,27 +24,13 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.CheckManifest;
_steps = ESteps.ClearUnusedCacheFiles;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckManifest)
{
if (_manifest == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Can not found active package manifest !";
}
else
{
_steps = ESteps.ClearUnusedCacheFiles;
}
}
if (_steps == ESteps.ClearUnusedCacheFiles)
{
try

View File

@@ -92,7 +92,12 @@ namespace YooAsset
if (_fileSystem.AppendFileExtension)
{
string dataFileExtension = FindDataFileExtension(chidDirectory);
if (string.IsNullOrEmpty(dataFileExtension) == false)
if (string.IsNullOrEmpty(dataFileExtension))
{
//注意:覆盖安装的情况下,缓存文件可能会没有后缀格式,需要删除重新下载!
dataFilePath = string.Empty;
}
else
{
dataFilePath += dataFileExtension;
}

View File

@@ -3,6 +3,7 @@ using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
@@ -12,9 +13,11 @@ namespace YooAsset
{
None,
LoadCatalog,
WaitForRequest,
Done,
}
private UnityWebRequest _request;
private readonly DefaultWebServerFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
@@ -36,12 +39,39 @@ namespace YooAsset
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
if (_steps == ESteps.LoadCatalog)
{
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
_request = UnityWebRequest.Get(catalogFilePath);
_request.SendWebRequest();
_steps = ESteps.WaitForRequest;
return;
}
if (_steps == ESteps.WaitForRequest)
{
// 等待请求完成
if (!_request.isDone)
return;
if (_request.result != UnityWebRequest.Result.Success)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load web server catalog file: {_request.error}";
return;
}
// 解析 JSON
string jsonText = _request.downloadHandler.text;
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
if (catalog == null)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load web server catalog file : {catalogFilePath}";
@@ -50,6 +80,8 @@ namespace YooAsset
if (catalog.PackageName != _fileSystem.PackageName)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Web server catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
@@ -64,6 +96,8 @@ namespace YooAsset
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}

View File

@@ -263,7 +263,7 @@ namespace YooAsset
/// <param name="clearParam">执行参数</param>
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
{
DebugCheckInitialize(false);
DebugCheckInitialize();
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
@@ -276,7 +276,7 @@ namespace YooAsset
/// <param name="clearParam">执行参数</param>
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
{
DebugCheckInitialize(false);
DebugCheckInitialize();
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;

View File

@@ -220,6 +220,26 @@ namespace YooAsset
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
internal static string GetRequestYooDefaultBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return GetRequestStreamingAssetsPath();
else
return PathUtility.Combine(GetRequestStreamingAssetsPath(), Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取UnityWebRequest StreamingAssets的路径 (OSX and iOS 需要加 file://)
/// </summary>
internal static string GetRequestStreamingAssetsPath()
{
#if UNITY_STANDALONE_OSX || UNITY_IOS
return $"file://{Application.streamingAssetsPath}";
#else
return Application.streamingAssetsPath;
#endif
}
#endregion
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "2.3.5-preview",
"version": "2.3.4-preview",
"unity": "2019.4",
"description": "unity3d resources management system.",
"author": {