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
136 changed files with 546 additions and 2238 deletions

View File

@@ -2,135 +2,6 @@
All notable changes to this package will be documented in this file.
## [2.3.9] - 2025-05-13
### Improvements
- 增加了YOO_ASSET_EXPERIMENT宏用于控制实验性代码的开关。
- 构建管线目前会输出构建日志到输出目录下,方便查看引擎在构建时主动清空的控制台日志。
- 优化了收集器tag传染扩散逻辑避免Group里配置了Tag导致的无意义的警告信息。
- 扩展工程内PanelMonitor代码默认关闭状态。
### Fixed
- (#528) 修复了AssetDependencyDatabase在查询引擎资源对象是否存在的时效问题。
### Added
- (#542) 新增了资源管理系统销毁方法。
该方法会销毁所有的资源包裹和异步操作任务以及卸载所有AssetBundle对象
```csharp
public class YooAssets
{
/// <summary>
/// 销毁资源系统
/// </summary>
public static void Destroy();
}
```
- 新增了SBP构建管线的构建参数
```csharp
/// <summary>
/// 从AssetBundle文件头里剥离Unity版本信息
/// </summary>
public bool StripUnityVersion = false;
```
- 新增了构建错误码BuiltinShadersBundleNameIsNull
## [2.3.8] - 2025-04-17
### Improvements
- 扩展工程里增加了“图集丢失变白块的解决方案”的相关代码。
### Fixed
- (#528) 修复了微信小游戏平台WXFSClearUnusedBundleFiles无法清理的问题。
- (#531) 修复了微信小游戏平台WXFSClearUnusedBundleFiles没有适配BundleName_HashName命名方式。
- (#533) 修复了Editor程序集下无法访问YooAsset.Editor程序集里的internal字段的问题。
- (#534) 修复了资源报告窗口AssetView视图里依赖资源包列表显示不准确的问题。
## [2.3.7] - 2025-04-01
### Improvements
- (#526) 运行时资源清单的哈希值验证兼容了MD5和CRC32两种方式。
- (#515) 优化了资源路径大小写不敏感的逻辑代码减少字符串操作产生的GC。
- (#523) UnloadUnusedAssetsOperation方法支持了分帧处理。
### Fixed
- (#520) 修复了UWP平台获取WWW加载路径未适配的问题。
### Added
- 新增了文件系统初始化参数INSTALL_CLEAR_MODE
```csharp
/// <summary>
/// 覆盖安装清理模式
/// </summary>
public enum EOverwriteInstallClearMode
{
/// <summary>
/// 不做任何处理
/// </summary>
None = 0,
/// <summary>
/// 清理所有缓存文件(包含资源文件和清单文件)
/// </summary>
ClearAllCacheFiles = 1,
/// <summary>
/// 清理所有缓存的资源文件
/// </summary>
ClearAllBundleFiles = 2,
/// <summary>
/// 清理所有缓存的清单文件
/// </summary>
ClearAllManifestFiles = 3,
}
```
- 新增了初始化参数BundleLoadingMaxConcurrency
```csharp
public abstract class InitializeParameters
{
/// <summary>
/// 同时加载Bundle文件的最大并发数
/// </summary>
public int BundleLoadingMaxConcurrency = int.MaxValue;
}
```
## [2.3.6] - 2025-03-25
### Improvements
- 构建管线新增了TaskCreateCatalog任务节点。
- 内置文件系统的catalog文件现在存储在streammingAssets目录下。
### Fixed
- (#486) 修复了微信小游戏文件系统调用ClearUnusedBundleFiles时候的异常。
## [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

@@ -1,5 +0,0 @@
using System.Runtime.CompilerServices;
// 外部友元
[assembly: InternalsVisibleTo("YooAsset.EditorExtension")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor")]

View File

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

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
#if YOO_ASSET_EXPERIMENT
namespace YooAsset.Editor
{
public class MacroDefine
@@ -16,4 +15,3 @@ namespace YooAsset.Editor
};
}
}
#endif

View File

@@ -5,7 +5,6 @@ using System.Text;
using System.Xml;
using UnityEditor;
#if YOO_ASSET_EXPERIMENT
namespace YooAsset.Editor
{
[InitializeOnLoad]
@@ -23,21 +22,13 @@ namespace YooAsset.Editor
return content;
// 将修改后的XML结构重新输出为文本
using (var memoryStream = new MemoryStream())
{
var writerSettings = new XmlWriterSettings
{
Indent = true,
Encoding = new UTF8Encoding(false), //无BOM
OmitXmlDeclaration = false
};
using (var xmlWriter = XmlWriter.Create(memoryStream, writerSettings))
{
xmlDoc.Save(xmlWriter);
}
return Encoding.UTF8.GetString(memoryStream.ToArray());
}
var stringWriter = new StringWriter();
var writerSettings = new XmlWriterSettings();
writerSettings.Indent = true;
var xmlWriter = XmlWriter.Create(stringWriter, writerSettings);
xmlDoc.WriteTo(xmlWriter);
xmlWriter.Flush();
return stringWriter.ToString();
}
/// <summary>
@@ -103,4 +94,3 @@ namespace YooAsset.Editor
}
}
}
#endif

View File

@@ -32,9 +32,8 @@ namespace YooAsset.Editor
var buildParametersContext = new BuildParametersContext(buildParameters);
_buildContext.SetContextObject(buildParametersContext);
// 初始化日志系统
string logFilePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/buildInfo.log";
BuildLogger.InitLogger(enableLog, logFilePath);
// 初始化日志
BuildLogger.InitLogger(enableLog);
// 执行构建流程
BuildLogger.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}");
@@ -51,9 +50,6 @@ namespace YooAsset.Editor
BuildLogger.Error(buildResult.ErrorInfo);
}
// 关闭日志系统
BuildLogger.Shuntdown();
return buildResult;
}
}

View File

@@ -1,23 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
namespace YooAsset.Editor
{
public class TaskCreateCatalog
{
/// <summary>
/// 生成内置资源记录文件
/// </summary>
internal void CreateCatalogFile(BuildParametersContext buildParametersContext)
{
string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory();
string buildPackageName = buildParametersContext.Parameters.PackageName;
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(buildPackageName, buildinRootDirectory);
// 刷新目录
AssetDatabase.Refresh();
}
}
}

View File

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

View File

@@ -30,7 +30,7 @@ namespace YooAsset.Editor
// 创建新补丁清单
PackageManifest manifest = new PackageManifest();
manifest.FileVersion = ManifestDefine.FileVersion;
manifest.FileVersion = YooAssetSettings.ManifestFileVersion;
manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;

View File

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

View File

@@ -1,20 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
public class TaskCreateCatalog_BBP : TaskCreateCatalog, IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
CreateCatalogFile(buildParametersContext);
}
}
}
}

View File

@@ -36,7 +36,6 @@ namespace YooAsset.Editor
new TaskCreateReport_BBP(),
new TaskCreatePackage_BBP(),
new TaskCopyBuildinFiles_BBP(),
new TaskCreateCatalog_BBP()
};
return pipeline;
}

View File

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

View File

@@ -1,20 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
public class TaskCreateCatalog_RFBP : TaskCreateCatalog, IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
CreateCatalogFile(buildParametersContext);
}
}
}
}

View File

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

View File

@@ -38,7 +38,6 @@ namespace YooAsset.Editor
new TaskCreateReport_RFBP(),
new TaskCreatePackage_RFBP(),
new TaskCopyBuildinFiles_RFBP(),
new TaskCreateCatalog_RFBP()
};
return pipeline;
}

View File

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

View File

@@ -1,20 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
public class TaskCreateCatalog_SBP : TaskCreateCatalog, IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
CreateCatalogFile(buildParametersContext);
}
}
}
}

View File

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

View File

@@ -11,7 +11,7 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
var buildParameters = buildParametersContext.Parameters;
// 检测基础构建参数
buildParametersContext.CheckBuildParameters();
@@ -50,13 +50,6 @@ namespace YooAsset.Editor
{
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
}
// 检测内置着色器资源包名称
if (string.IsNullOrEmpty(buildParameters.BuiltinShadersBundleName))
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.BuiltinShadersBundleNameIsNull, $"Builtin shaders bundle name is null. It will cause resource redundancy !");
BuildLogger.Warning(warning);
}
}
}
}

View File

@@ -14,11 +14,6 @@ namespace YooAsset.Editor
/// </summary>
public ECompressOption CompressOption = ECompressOption.Uncompressed;
/// <summary>
/// 从AssetBundle文件头里剥离Unity版本信息
/// </summary>
public bool StripUnityVersion = false;
/// <summary>
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
/// </summary>
@@ -75,9 +70,6 @@ namespace YooAsset.Editor
else
throw new System.NotImplementedException(CompressOption.ToString());
if (StripUnityVersion)
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.StripUnityVersion;
if (DisableWriteTypeTree)
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;

View File

@@ -36,7 +36,6 @@ namespace YooAsset.Editor
new TaskCreateReport_SBP(),
new TaskCreatePackage_SBP(),
new TaskCopyBuildinFiles_SBP(),
new TaskCreateCatalog_SBP()
};
return pipeline;
}

View File

@@ -2,100 +2,37 @@
using System.IO;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
namespace YooAsset.Editor
{
internal static class BuildLogger
{
private const int MAX_LOG_BUFFER_SIZE = 1024 * 1024 * 2; //2MB
private static bool _enableLog = true;
private static string _logFilePath;
private static readonly object _lockObj = new object();
private static readonly StringBuilder _logBuilder = new StringBuilder(MAX_LOG_BUFFER_SIZE);
/// <summary>
/// 初始化日志系统
/// </summary>
public static void InitLogger(bool enableLog, string logFilePath)
public static void InitLogger(bool enableLog)
{
_enableLog = enableLog;
_logFilePath = logFilePath;
_logBuilder.Clear();
if (_enableLog)
{
if (string.IsNullOrEmpty(_logFilePath))
throw new Exception("Log file path is null or empty !");
Debug.Log($"Logger initialized at {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
}
}
/// <summary>
/// 关闭日志系统
/// </summary>
public static void Shuntdown()
{
if (_enableLog)
{
lock (_lockObj)
{
try
{
if (File.Exists(_logFilePath))
File.Delete(_logFilePath);
FileUtility.CreateFileDirectory(_logFilePath);
File.WriteAllText(_logFilePath, _logBuilder.ToString(), Encoding.UTF8);
_logBuilder.Clear();
}
catch (Exception ex)
{
Debug.LogError($"Failed to write log file: {ex.Message}");
}
}
}
}
public static void Log(string message)
{
if (_enableLog)
{
WriteLog("INFO", message);
Debug.Log(message);
}
}
public static void Warning(string message)
{
if (_enableLog)
{
WriteLog("WARN", message);
Debug.LogWarning(message);
}
Debug.LogWarning(message);
}
public static void Error(string message)
{
if (_enableLog)
{
WriteLog("ERROR", message);
Debug.LogError(message);
}
Debug.LogError(message);
}
public static string GetErrorMessage(ErrorCode code, string message)
{
return $"[ErrorCode{(int)code}] {message}";
}
private static void WriteLog(string level, string message)
{
lock (_lockObj)
{
string logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{level}] {message}";
_logBuilder.AppendLine(logEntry);
}
}
}
}

View File

@@ -15,7 +15,6 @@ namespace YooAsset.Editor
BuildPipelineIsNullOrEmpty = 116,
BuildBundleTypeIsUnknown = 117,
RecommendScriptBuildPipeline = 130,
BuiltinShadersBundleNameIsNull = 131,
// TaskGetBuildMap
RemoveInvalidTags = 200,

View File

@@ -1,6 +1,9 @@

namespace YooAsset
namespace YooAsset.Editor
{
/// <summary>
/// 补丁包内的文件样式
/// </summary>
public enum EFileNameStyle
{
/// <summary>

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5e81f00e510f07947873055518f5d1c6
guid: 84c5eff5dedf53343897e83f6b10eea6
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -259,13 +259,10 @@ namespace YooAsset.Editor
}
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
{
List<string> result = EditorTools.StringToStringList(AssetTags, ';');
if (CollectorType == ECollectorType.MainAssetCollector)
{
List<string> temps = EditorTools.StringToStringList(group.AssetTags, ';');
result.AddRange(temps);
}
return result;
List<string> tags = EditorTools.StringToStringList(group.AssetTags, ';');
List<string> temper = EditorTools.StringToStringList(AssetTags, ';');
tags.AddRange(temper);
return tags;
}
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
{

View File

@@ -70,7 +70,7 @@ namespace YooAsset.Editor
foreach (var cacheInfoPair in _database)
{
var assetPath = cacheInfoPair.Key;
var assetGUID = AssetDatabase.AssetPathToGUID(assetPath, AssetPathToGUIDOptions.OnlyExistingAssets);
var assetGUID = AssetDatabase.AssetPathToGUID(assetPath);
if (string.IsNullOrEmpty(assetGUID))
{
removeList.Add(assetPath);

View File

@@ -296,7 +296,6 @@ namespace YooAsset.Editor
string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json";
string fileContent = JsonUtility.ToJson(_currentReport, true);
FileUtility.WriteAllText(filePath, fileContent);
Debug.Log($"Debug report file saved : {filePath}");
}
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)

View File

@@ -238,8 +238,9 @@ namespace YooAsset.Editor
ReportAssetInfo assetInfo = assetTableData.AssetInfo;
// 填充依赖数据
var sourceDatas = new List<ITableData>(assetInfo.DependBundles.Count);
foreach (string dependBundleName in assetInfo.DependBundles)
var mainBundle = _buildReport.GetBundleInfo(assetInfo.MainBundleName);
var sourceDatas = new List<ITableData>(mainBundle.DependBundles.Count);
foreach (string dependBundleName in mainBundle.DependBundles)
{
var dependBundle = _buildReport.GetBundleInfo(dependBundleName);
var rowData = new DependTableData();

View File

@@ -1,10 +1,7 @@
using System.Runtime.CompilerServices;
// 内部友元
[assembly: InternalsVisibleTo("YooAsset.Editor")]
[assembly: InternalsVisibleTo("YooAsset.Test.Editor")]
// 外部友元
[assembly: InternalsVisibleTo("YooAsset.RuntimeExtension")]
[assembly: InternalsVisibleTo("YooAsset.EditorExtension")]
[assembly: InternalsVisibleTo("YooAsset.RuntimeExtension")]
[assembly: InternalsVisibleTo("YooAsset.Test.Editor")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor")]

View File

@@ -0,0 +1,30 @@

namespace YooAsset
{
internal class DownloadParam
{
public readonly int FailedTryAgain;
public readonly int Timeout;
/// <summary>
/// 导入的本地文件路径
/// </summary>
public string ImportFilePath { set; get; }
/// <summary>
/// 主资源地址
/// </summary>
public string MainURL { set; get; }
/// <summary>
/// 备用资源地址
/// </summary>
public string FallbackURL { set; get; }
public DownloadParam(int failedTryAgain, int timeout)
{
FailedTryAgain = failedTryAgain;
Timeout = timeout;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8fe3d00b03dc9c64a96b7acfdf99b54c
guid: 56ea224b45d314e4a86b558404e9b6c8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -67,7 +67,7 @@ namespace YooAsset
}
#elif UNITY_STANDALONE_OSX
url = new System.Uri(path).ToString();
#elif UNITY_STANDALONE || UNITY_WSA
#elif UNITY_STANDALONE
url = StringUtility.Format("file:///{0}", path);
#else
throw new System.NotImplementedException();

View File

@@ -1,21 +0,0 @@

namespace YooAsset
{
internal class CatalogDefine
{
/// <summary>
/// 文件极限大小100MB
/// </summary>
public const int FileMaxSize = 104857600;
/// <summary>
/// 文件头标记
/// </summary>
public const uint FileSign = 0x133C5EE;
/// <summary>
/// 文件格式版本
/// </summary>
public const string FileVersion = "1.0.0";
}
}

View File

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

View File

@@ -1,102 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
internal static class CatalogTools
{
/// <summary>
/// 序列化JSON文件
/// </summary>
public static void SerializeToJson(string savePath, DefaultBuildinFileCatalog catalog)
{
string json = JsonUtility.ToJson(catalog, true);
FileUtility.WriteAllText(savePath, json);
}
/// <summary>
/// 反序列化JSON文件
/// </summary>
public static DefaultBuildinFileCatalog DeserializeFromJson(string jsonContent)
{
return JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonContent);
}
/// <summary>
/// 序列化(二进制文件)
/// </summary>
public static void SerializeToBinary(string savePath, DefaultBuildinFileCatalog catalog)
{
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
// 创建缓存器
BufferWriter buffer = new BufferWriter(CatalogDefine.FileMaxSize);
// 写入文件标记
buffer.WriteUInt32(CatalogDefine.FileSign);
// 写入文件版本
buffer.WriteUTF8(CatalogDefine.FileVersion);
// 写入文件头信息
buffer.WriteUTF8(catalog.PackageName);
buffer.WriteUTF8(catalog.PackageVersion);
// 写入资源包列表
buffer.WriteInt32(catalog.Wrappers.Count);
for (int i = 0; i < catalog.Wrappers.Count; i++)
{
var fileWrapper = catalog.Wrappers[i];
buffer.WriteUTF8(fileWrapper.BundleGUID);
buffer.WriteUTF8(fileWrapper.FileName);
}
// 写入文件流
buffer.WriteToStream(fs);
fs.Flush();
}
}
/// <summary>
/// 反序列化(二进制文件)
/// </summary>
public static DefaultBuildinFileCatalog DeserializeFromBinary(byte[] binaryData)
{
// 创建缓存器
BufferReader buffer = new BufferReader(binaryData);
// 读取文件标记
uint fileSign = buffer.ReadUInt32();
if (fileSign != CatalogDefine.FileSign)
throw new Exception("Invalid catalog file !");
// 读取文件版本
string fileVersion = buffer.ReadUTF8();
if (fileVersion != CatalogDefine.FileVersion)
throw new Exception($"The catalog file version are not compatible : {fileVersion} != {CatalogDefine.FileVersion}");
DefaultBuildinFileCatalog catalog = new DefaultBuildinFileCatalog();
{
// 读取文件头信息
catalog.FileVersion = fileVersion;
catalog.PackageName = buffer.ReadUTF8();
catalog.PackageVersion = buffer.ReadUTF8();
// 读取资源包列表
int fileCount = buffer.ReadInt32();
catalog.Wrappers = new List<DefaultBuildinFileCatalog.FileWrapper>(fileCount);
for (int i = 0; i < fileCount; i++)
{
var fileWrapper = new DefaultBuildinFileCatalog.FileWrapper();
fileWrapper.BundleGUID = buffer.ReadUTF8();
fileWrapper.FileName = buffer.ReadUTF8();
catalog.Wrappers.Add(fileWrapper);
}
}
return catalog;
}
}
}

View File

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

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.Collections.Generic;
namespace YooAsset
@@ -15,12 +14,13 @@ namespace YooAsset
{
public string BundleGUID;
public string FileName;
}
/// <summary>
/// 文件版本
/// </summary>
public string FileVersion;
public FileWrapper(string bundleGUID, string fileName)
{
BundleGUID = bundleGUID;
FileName = fileName;
}
}
/// <summary>
/// 包裹名称

View File

@@ -58,11 +58,6 @@ namespace YooAsset
/// </summary>
public EFileVerifyLevel FileVerifyLevel { private set; get; } = EFileVerifyLevel.Middle;
/// <summary>
/// 自定义参数:覆盖安装缓存清理模式
/// </summary>
public EOverwriteInstallClearMode InstallClearMode { private set; get; } = EOverwriteInstallClearMode.ClearAllManifestFiles;
/// <summary>
/// 自定义参数:数据文件追加文件格式
/// </summary>
@@ -109,15 +104,15 @@ namespace YooAsset
var operation = new DBFSRequestPackageVersionOperation(this);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{
return _unpackFileSystem.ClearCacheFilesAsync(manifest, options);
return _unpackFileSystem.ClearCacheFilesAsync(manifest, clearMode, clearParam);
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{
// 注意:业务层的解压下载器会依赖内置文件系统的下载方法
options.ImportFilePath = GetBuildinFileLoadPath(bundle);
return _unpackFileSystem.DownloadFileAsync(bundle, options);
param.ImportFilePath = GetBuildinFileLoadPath(bundle);
return _unpackFileSystem.DownloadFileAsync(bundle, param);
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{
@@ -150,10 +145,6 @@ namespace YooAsset
{
FileVerifyLevel = (EFileVerifyLevel)value;
}
else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
{
InstallClearMode = (EOverwriteInstallClearMode)value;
}
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
{
AppendFileExtension = Convert.ToBoolean(value);
@@ -193,7 +184,6 @@ namespace YooAsset
_unpackFileSystem = new DefaultUnpackFileSystem();
_unpackFileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.INSTALL_CLEAR_MODE, InstallClearMode);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, AppendFileExtension);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, DecryptionServices);
_unpackFileSystem.OnCreate(packageName, null);
@@ -346,9 +336,10 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(_packageRoot, fileName);
}
public string GetCatalogBinaryFileLoadPath()
public string GetCatalogFileLoadPath()
{
return PathUtility.Combine(_packageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
string fileName = DefaultBuildinFileSystemDefine.BuildinCatalogFileName;
return PathUtility.Combine(YooAssetSettingsData.GetRequestYooDefaultBuildinRoot(), PackageName, fileName);
}
/// <summary>

View File

@@ -5,15 +5,13 @@ 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 !");
@@ -84,24 +82,9 @@ namespace YooAsset
// 创建内置清单实例
var buildinFileCatalog = new DefaultBuildinFileCatalog();
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion;
buildinFileCatalog.PackageName = packageName;
buildinFileCatalog.PackageVersion = packageVersion;
// 创建白名单查询集合
HashSet<string> whiteFileList = new HashSet<string>
{
"link.xml",
"buildlogtep.json",
$"{packageName}.version",
$"{packageName}_{packageVersion}.bytes",
$"{packageName}_{packageVersion}.hash",
$"{packageName}_{packageVersion}.json",
$"{packageName}_{packageVersion}.report",
DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName,
DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName
};
// 记录所有内置资源文件
DirectoryInfo rootDirectory = new DirectoryInfo(pacakgeDirectory);
FileInfo[] fileInfos = rootDirectory.GetFiles();
@@ -110,15 +93,25 @@ namespace YooAsset
if (fileInfo.Extension == ".meta")
continue;
if (whiteFileList.Contains(fileInfo.Name))
if (fileInfo.Name == "link.xml" || fileInfo.Name == "buildlogtep.json")
continue;
if (fileInfo.Name == $"{packageName}.version")
continue;
if (fileInfo.Name == $"{packageName}_{packageVersion}.bytes")
continue;
if (fileInfo.Name == $"{packageName}_{packageVersion}.hash")
continue;
if (fileInfo.Name == $"{packageName}_{packageVersion}.json")
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))
{
var wrapper = new DefaultBuildinFileCatalog.FileWrapper();
wrapper.BundleGUID = bundleGUID;
wrapper.FileName = fileName;
var wrapper = new DefaultBuildinFileCatalog.FileWrapper(bundleGUID, fileName);
buildinFileCatalog.Wrappers.Add(wrapper);
}
else
@@ -127,20 +120,16 @@ namespace YooAsset
}
}
// 创建输出文件
string jsonFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}";
if (File.Exists(jsonFilePath))
File.Delete(jsonFilePath);
CatalogTools.SerializeToJson(jsonFilePath, buildinFileCatalog);
// 创建输出目录
string fullPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
FileUtility.CreateFileDirectory(saveFilePath);
// 创建输出文件
string binaryFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName}";
if (File.Exists(binaryFilePath))
File.Delete(binaryFilePath);
CatalogTools.SerializeToBinary(binaryFilePath, buildinFileCatalog);
File.WriteAllText(saveFilePath, JsonUtility.ToJson(buildinFileCatalog, false));
UnityEditor.AssetDatabase.Refresh();
Debug.Log($"Succeed to save buildin file catalog : {binaryFilePath}");
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
return true;
}
}

View File

@@ -4,13 +4,8 @@ namespace YooAsset
internal class DefaultBuildinFileSystemDefine
{
/// <summary>
/// 内置清单JSON文件名称
/// 内置清单文件名称
/// </summary>
public const string BuildinCatalogJsonFileName = "BuildinCatalog.json";
/// <summary>
/// 内置清单二进制文件名称
/// </summary>
public const string BuildinCatalogBinaryFileName = "BuildinCatalog.bytes";
public const string BuildinCatalogFileName = "BuildinCatalog.json";
}
}

View File

@@ -1,4 +1,5 @@
using System;
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
@@ -7,84 +8,89 @@ namespace YooAsset
private enum ESteps
{
None,
RequestData,
LoadCatalog,
WaitForRequest,
Done,
}
private UnityWebRequest _request;
private readonly DefaultBuildinFileSystem _fileSystem;
private UnityWebDataRequestOperation _webDataRequestOp;
private ESteps _steps = ESteps.None;
internal LoadBuildinCatalogFileOperation(DefaultBuildinFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
_steps = ESteps.RequestData;
_steps = ESteps.LoadCatalog;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestData)
{
if (_webDataRequestOp == null)
{
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_webDataRequestOp = new UnityWebDataRequestOperation(url);
_webDataRequestOp.StartOperation();
AddChildOperation(_webDataRequestOp);
}
_webDataRequestOp.UpdateOperation();
if (_webDataRequestOp.IsDone == false)
return;
if (_webDataRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadCatalog;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _webDataRequestOp.Error;
}
}
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
if (_steps == ESteps.LoadCatalog)
{
try
{
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result);
if (catalog.PackageName != _fileSystem.PackageName)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
return;
}
_request = UnityWebRequest.Get(catalogFilePath);
_request.SendWebRequest();
_steps = ESteps.WaitForRequest;
return;
}
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
}
if (_steps == ESteps.WaitForRequest)
{
// 等待请求完成
if (!_request.isDone)
return;
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (Exception e)
if (_request.result != UnityWebRequest.Result.Success)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load catalog file : {e.Message}";
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}";
return;
}
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}";
return;
}
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}

View File

@@ -69,7 +69,8 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
string fileHash = HashUtility.BytesCRC32(_webDataRequestOp.Result);
if (fileHash == _packageHash)
{
_steps = ESteps.LoadManifest;
}

View File

@@ -65,11 +65,6 @@ namespace YooAsset
/// </summary>
public EFileVerifyLevel FileVerifyLevel { private set; get; } = EFileVerifyLevel.Middle;
/// <summary>
/// 自定义参数:覆盖安装缓存清理模式
/// </summary>
public EOverwriteInstallClearMode InstallClearMode { private set; get; } = EOverwriteInstallClearMode.ClearAllManifestFiles;
/// <summary>
/// 自定义参数:数据文件追加文件格式
/// </summary>
@@ -120,43 +115,43 @@ namespace YooAsset
var operation = new DCFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{
if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString())
if (clearMode == EFileClearMode.ClearAllBundleFiles.ToString())
{
var operation = new ClearAllCacheBundleFilesOperation(this);
return operation;
}
else if (options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
else if (clearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
{
var operation = new ClearUnusedCacheBundleFilesOperation(this, manifest);
return operation;
}
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
else if (clearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
{
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, manifest, options.ClearParam);
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, manifest, clearParam);
return operation;
}
else if (options.ClearMode == EFileClearMode.ClearAllManifestFiles.ToString())
else if (clearMode == EFileClearMode.ClearAllManifestFiles.ToString())
{
var operation = new ClearAllCacheManifestFilesOperation(this);
return operation;
}
else if (options.ClearMode == EFileClearMode.ClearUnusedManifestFiles.ToString())
else if (clearMode == EFileClearMode.ClearUnusedManifestFiles.ToString())
{
var operation = new ClearUnusedCacheManifestFilesOperation(this, manifest);
return operation;
}
else
{
string error = $"Invalid clear mode : {options.ClearMode}";
string error = $"Invalid clear mode : {clearMode}";
var operation = new FSClearCacheFilesCompleteOperation(error);
return operation;
}
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{
var downloader = DownloadCenter.DownloadFileAsync(bundle, options);
var downloader = DownloadCenter.DownloadFileAsync(bundle, param);
downloader.Reference(); //增加下载器的引用计数
// 注意:将下载器进行包裹,可以避免父类任务终止的时候,连带子任务里的下载器也一起被终止!
@@ -193,10 +188,6 @@ namespace YooAsset
{
FileVerifyLevel = (EFileVerifyLevel)value;
}
else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
{
InstallClearMode = (EOverwriteInstallClearMode)value;
}
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
{
AppendFileExtension = Convert.ToBoolean(value);
@@ -236,8 +227,8 @@ namespace YooAsset
_packageRoot = packageRoot;
_cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName);
_cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
_tempFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.TempFilesFolderName);
_cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
}
public virtual void OnDestroy()
{
@@ -342,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)
{
@@ -400,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)
@@ -443,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
{
@@ -509,18 +505,7 @@ namespace YooAsset
}
/// <summary>
/// 删除所有缓存的资源文件
/// </summary>
public void DeleteAllBundleFiles()
{
if (Directory.Exists(_cacheBundleFilesRoot))
{
Directory.Delete(_cacheBundleFilesRoot, true);
}
}
/// <summary>
/// 删除所有缓存的清单文件
/// 删除所有清单文件
/// </summary>
public void DeleteAllManifestFiles()
{

View File

@@ -1,29 +0,0 @@

namespace YooAsset
{
/// <summary>
/// 覆盖安装清理模式
/// </summary>
public enum EOverwriteInstallClearMode
{
/// <summary>
/// 不做任何处理
/// </summary>
None = 0,
/// <summary>
/// 清理所有缓存文件(包含资源文件和清单文件)
/// </summary>
ClearAllCacheFiles = 1,
/// <summary>
/// 清理所有缓存的资源文件
/// </summary>
ClearAllBundleFiles = 2,
/// <summary>
/// 清理所有缓存的清单文件
/// </summary>
ClearAllManifestFiles = 3,
}
}

View File

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

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

@@ -46,32 +46,9 @@ namespace YooAsset
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
if (appFootPrint.IsDirty())
{
if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.None)
{
YooLogger.Warning("Do nothing when overwrite install application !");
}
else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllCacheFiles)
{
_fileSystem.DeleteAllBundleFiles();
_fileSystem.DeleteAllManifestFiles();
YooLogger.Warning("Delete all cache files when overwrite install application !");
}
else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllBundleFiles)
{
_fileSystem.DeleteAllBundleFiles();
YooLogger.Warning("Delete all bundle files when overwrite install application !");
}
else if (_fileSystem.InstallClearMode == EOverwriteInstallClearMode.ClearAllManifestFiles)
{
_fileSystem.DeleteAllManifestFiles();
YooLogger.Warning("Delete all manifest files when overwrite install application !");
}
else
{
throw new System.NotImplementedException(_fileSystem.InstallClearMode.ToString());
}
_fileSystem.DeleteAllManifestFiles();
appFootPrint.Coverage(_fileSystem.PackageName);
YooLogger.Warning("Delete manifest files when application foot print dirty !");
}
_steps = ESteps.SearchCacheFiles;

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using UnityEngine;
namespace YooAsset
@@ -58,8 +57,8 @@ namespace YooAsset
// 注意边玩边下下载器引用计数没有Release
if (_downloadFileOp == null)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
_downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp);
}
@@ -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
{
@@ -297,8 +275,8 @@ namespace YooAsset
// 注意边玩边下下载器引用计数没有Release
if (_downloadFileOp == null)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
_downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp);
}

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

@@ -74,7 +74,7 @@ namespace YooAsset
/// <summary>
/// 创建下载任务
/// </summary>
public FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{
// 查询旧的下载器
if (_downloaders.TryGetValue(bundle.BundleGUID, out var oldDownloader))
@@ -83,29 +83,29 @@ namespace YooAsset
}
// 设置请求URL
if (string.IsNullOrEmpty(options.ImportFilePath))
if (string.IsNullOrEmpty(param.ImportFilePath))
{
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(bundle.FileName);
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(bundle.FileName);
param.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(bundle.FileName);
param.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(bundle.FileName);
}
else
{
// 注意:把本地文件路径指定为远端下载地址
options.MainURL = DownloadSystemHelper.ConvertToWWWPath(options.ImportFilePath);
options.FallbackURL = options.MainURL;
param.MainURL = DownloadSystemHelper.ConvertToWWWPath(param.ImportFilePath);
param.FallbackURL = param.MainURL;
}
// 创建新的下载器
DefaultDownloadFileOperation newDownloader;
if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize)
{
newDownloader = new DownloadResumeFileOperation(_fileSystem, bundle, options);
newDownloader = new DownloadResumeFileOperation(_fileSystem, bundle, param);
AddChildOperation(newDownloader);
_downloaders.Add(bundle.BundleGUID, newDownloader);
}
else
{
newDownloader = new DownloadNormalFileOperation(_fileSystem, bundle, options);
newDownloader = new DownloadNormalFileOperation(_fileSystem, bundle, param);
AddChildOperation(newDownloader);
_downloaders.Add(bundle.BundleGUID, newDownloader);
}

View File

@@ -12,13 +12,13 @@ namespace YooAsset
private string _tempFilePath;
private ESteps _steps = ESteps.None;
internal DownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
internal DownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
_isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Options.MainURL);
_isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Param.MainURL);
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists;
}

View File

@@ -15,13 +15,13 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
internal DownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
internal DownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
_isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Options.MainURL);
_isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Param.MainURL);
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists;
}

View File

@@ -59,7 +59,8 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
string fileHash = HashUtility.BytesCRC32(_fileData);
if (fileHash == _packageHash)
{
_steps = ESteps.LoadManifest;
}

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

@@ -66,12 +66,12 @@ namespace YooAsset
var operation = new DEFSRequestPackageVersionOperation(this);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{
var operation = new FSClearCacheFilesCompleteOperation();
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{
throw new System.NotImplementedException();
}

View File

@@ -59,7 +59,8 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
string fileHash = HashUtility.BytesCRC32(_fileData);
if (fileHash == _packageHash)
{
_steps = ESteps.LoadManifest;
}

View File

@@ -14,8 +14,7 @@ namespace YooAsset
base.OnCreate(packageName, rootDirectory);
// 注意:重写保存根目录和临时目录
_cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveBundleFilesFolderName);
_cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveManifestFilesFolderName);
_cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName);
_tempFilesRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName);
}
}

View File

@@ -11,13 +11,8 @@ namespace YooAsset
/// <summary>
/// 保存的资源文件的文件夹名称
/// </summary>
public const string SaveBundleFilesFolderName = "UnpackBundleFiles";
/// <summary>
/// 保存的清单文件的文件夹名称
/// </summary>
public const string SaveManifestFilesFolderName = "UnpackManifestFiles";
public const string SaveFilesFolderName = "UnpackFiles";
/// <summary>
/// 下载的临时文件的文件夹名称
/// </summary>

View File

@@ -73,12 +73,12 @@ namespace YooAsset
var operation = new DWRFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{
var operation = new FSClearCacheFilesCompleteOperation();
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{
throw new System.NotImplementedException();
}

View File

@@ -34,19 +34,19 @@ namespace YooAsset
{
if (_downloadAssetBundleOp == null)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
downloadParam.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
downloadParam.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
if (_bundle.Encrypted)
{
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, options);
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, downloadParam);
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}
else
{
_downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, options);
_downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, downloadParam);
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}

View File

@@ -72,7 +72,8 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
string fileHash = HashUtility.BytesCRC32(_webDataRequestOp.Result);
if (fileHash == _packageHash)
{
_steps = ESteps.LoadManifest;
}

View File

@@ -82,12 +82,12 @@ namespace YooAsset
var operation = new DWSFSRequestPackageVersionOperation(this, timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{
var operation = new FSClearCacheFilesCompleteOperation();
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{
throw new System.NotImplementedException();
}
@@ -198,9 +198,10 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName);
}
public string GetCatalogBinaryFileLoadPath()
public string GetCatalogFileLoadPath()
{
return PathUtility.Combine(_webPackageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
}
/// <summary>

View File

@@ -34,20 +34,20 @@ namespace YooAsset
{
if (_downloadAssetBundleOp == null)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
options.MainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
options.FallbackURL = options.MainURL;
downloadParam.MainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
downloadParam.FallbackURL = downloadParam.MainURL;
if (_bundle.Encrypted)
{
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, options);
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, downloadParam);
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}
else
{
_downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, options);
_downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, downloadParam);
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}

View File

@@ -2,6 +2,8 @@
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
@@ -10,84 +12,94 @@ namespace YooAsset
private enum ESteps
{
None,
RequestData,
LoadCatalog,
WaitForRequest,
Done,
}
private UnityWebRequest _request;
private readonly DefaultWebServerFileSystem _fileSystem;
private UnityWebDataRequestOperation _webDataRequestOp;
private ESteps _steps = ESteps.None;
/// <summary>
/// 内置清单版本
/// </summary>
public string PackageVersion { private set; get; }
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalStart()
{
_steps = ESteps.RequestData;
_steps = ESteps.LoadCatalog;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestData)
{
if (_webDataRequestOp == null)
{
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
_webDataRequestOp = new UnityWebDataRequestOperation(url);
_webDataRequestOp.StartOperation();
AddChildOperation(_webDataRequestOp);
}
_webDataRequestOp.UpdateOperation();
if (_webDataRequestOp.IsDone == false)
return;
if (_webDataRequestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadCatalog;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _webDataRequestOp.Error;
}
}
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
if (_steps == ESteps.LoadCatalog)
{
try
{
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result);
if (catalog.PackageName != _fileSystem.PackageName)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
return;
}
_request = UnityWebRequest.Get(catalogFilePath);
_request.SendWebRequest();
_steps = ESteps.WaitForRequest;
return;
}
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultWebServerFileSystem.FileWrapper(wrapper.FileName);
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
}
if (_steps == ESteps.WaitForRequest)
{
// 等待请求完成
if (!_request.isDone)
return;
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (Exception e)
if (_request.result != UnityWebRequest.Result.Success)
{
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to load catalog file : {e.Message}";
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}";
return;
}
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}";
return;
}
PackageVersion = catalog.PackageVersion;
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultWebServerFileSystem.FileWrapper(wrapper.FileName);
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
_request.Dispose();
_request = null;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}

View File

@@ -69,7 +69,8 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
string fileHash = HashUtility.BytesCRC32(_webDataRequestOp.Result);
if (fileHash == _packageHash)
{
_steps = ESteps.LoadManifest;
}

View File

@@ -4,7 +4,6 @@ namespace YooAsset
public class FileSystemParametersDefine
{
public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL";
public const string INSTALL_CLEAR_MODE = "INSTALL_CLEAR_MODE";
public const string REMOTE_SERVICES = "REMOTE_SERVICES";
public const string DECRYPTION_SERVICES = "DECRYPTION_SERVICES";
public const string APPEND_FILE_EXTENSION = "APPEND_FILE_EXTENSION";

View File

@@ -37,13 +37,13 @@ namespace YooAsset
/// <summary>
/// 清理缓存文件
/// </summary>
FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options);
FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam);
/// <summary>
/// 下载Bundle文件
/// </summary>
FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options);
FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param);
/// <summary>
/// 加载Bundle文件
/// </summary>

View File

@@ -1,19 +1,6 @@

namespace YooAsset
{
internal class ClearCacheFilesOptions
{
/// <summary>
/// 清理模式
/// </summary>
public string ClearMode;
/// <summary>
/// 附加参数
/// </summary>
public object ClearParam;
}
internal abstract class FSClearCacheFilesOperation : AsyncOperationBase
{
}

View File

@@ -1,40 +1,6 @@

namespace YooAsset
{
internal class DownloadFileOptions
{
/// <summary>
/// 失败后重试次数
/// </summary>
public readonly int FailedTryAgain;
/// <summary>
/// 超时时间
/// </summary>
public readonly int Timeout;
/// <summary>
/// 主资源地址
/// </summary>
public string MainURL { set; get; }
/// <summary>
/// 备用资源地址
/// </summary>
public string FallbackURL { set; get; }
/// <summary>
/// 导入的本地文件路径
/// </summary>
public string ImportFilePath { set; get; }
public DownloadFileOptions(int failedTryAgain, int timeout)
{
FailedTryAgain = failedTryAgain;
Timeout = timeout;
}
}
internal abstract class FSDownloadFileOperation : AsyncOperationBase
{
public PackageBundle Bundle { private set; get; }

View File

@@ -18,7 +18,7 @@ namespace YooAsset
}
// 下载参数
protected readonly DownloadFileOptions Options;
protected readonly DownloadParam Param;
// 请求相关
protected UnityWebRequest _webRequest;
@@ -35,10 +35,10 @@ namespace YooAsset
protected int FailedTryAgain;
internal DefaultDownloadFileOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle)
internal DefaultDownloadFileOperation(PackageBundle bundle, DownloadParam param) : base(bundle)
{
Options = options;
FailedTryAgain = options.FailedTryAgain;
Param = param;
FailedTryAgain = param.FailedTryAgain;
}
/// <summary>
@@ -49,9 +49,9 @@ namespace YooAsset
// 轮流返回请求地址
_requestCount++;
if (_requestCount % 2 == 0)
return Options.FallbackURL;
return Param.FallbackURL;
else
return Options.MainURL;
return Param.MainURL;
}
/// <summary>
@@ -87,7 +87,7 @@ namespace YooAsset
}
float offset = UnityEngine.Time.realtimeSinceStartup - _latestDownloadRealtime;
if (offset > Options.Timeout)
if (offset > Param.Timeout)
{
YooLogger.Warning($"Download request timeout : {_requestURL}");
if (_webRequest != null)

View File

@@ -4,7 +4,7 @@ namespace YooAsset
{
internal abstract class DownloadAssetBundleOperation : DefaultDownloadFileOperation
{
internal DownloadAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
internal DownloadAssetBundleOperation(PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
}

View File

@@ -10,7 +10,7 @@ namespace YooAsset
private DownloadHandlerBuffer _downloadhandler;
private ESteps _steps = ESteps.None;
internal DownloadWebEncryptAssetBundleOperation(bool checkTimeout, IWebDecryptionServices decryptionServices, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
internal DownloadWebEncryptAssetBundleOperation(bool checkTimeout, IWebDecryptionServices decryptionServices, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
_checkTimeout = checkTimeout;
_decryptionServices = decryptionServices;

View File

@@ -9,7 +9,7 @@ namespace YooAsset
private DownloadHandlerAssetBundle _downloadhandler;
private ESteps _steps = ESteps.None;
internal DownloadWebNormalAssetBundleOperation(bool disableUnityWebCache, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
internal DownloadWebNormalAssetBundleOperation(bool disableUnityWebCache, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
_disableUnityWebCache = disableUnityWebCache;
}
@@ -122,7 +122,7 @@ namespace YooAsset
{
if (_disableUnityWebCache)
{
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, Bundle.UnityCRC);
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, 0);
#if UNITY_2020_3_OR_NEWER
downloadhandler.autoLoadAssetBundle = false;
#endif
@@ -132,8 +132,9 @@ namespace YooAsset
{
// 注意:优先从浏览器缓存里获取文件
// The file hash defining the version of the asset bundle.
uint unityCRC = Bundle.UnityCRC;
Hash128 fileHash = Hash128.Parse(Bundle.FileHash);
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, Bundle.UnityCRC);
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, unityCRC);
#if UNITY_2020_3_OR_NEWER
downloadhandler.autoLoadAssetBundle = false;
#endif

View File

@@ -38,10 +38,6 @@ namespace YooAsset
/// </summary>
public abstract class InitializeParameters
{
/// <summary>
/// 同时加载Bundle文件的最大并发数
/// </summary>
public int BundleLoadingMaxConcurrency = int.MaxValue;
}
/// <summary>

View File

@@ -9,8 +9,7 @@ namespace YooAsset
private enum ESteps
{
None,
CheckConcurrency,
LoadBundleFile,
LoadFile,
Done,
}
@@ -58,32 +57,17 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.CheckConcurrency;
_steps = ESteps.LoadFile;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckConcurrency)
{
if (IsWaitForAsyncComplete)
{
_steps = ESteps.LoadBundleFile;
}
else
{
if (_resourceManager.BundleLoadingIsBusy())
return;
_steps = ESteps.LoadBundleFile;
}
}
if (_steps == ESteps.LoadBundleFile)
if (_steps == ESteps.LoadFile)
{
if (_loadBundleOp == null)
{
_resourceManager.BundleLoadingCounter++;
_loadBundleOp = LoadBundleInfo.LoadBundleFile();
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
@@ -119,9 +103,6 @@ namespace YooAsset
Status = EOperationStatus.Failed;
Error = _loadBundleOp.Error;
}
// 统计计数减少
_resourceManager.BundleLoadingCounter--;
}
}
internal override void InternalWaitForAsyncComplete()

View File

@@ -15,7 +15,6 @@ namespace YooAsset
private readonly ResourceManager _resManager;
private readonly int _loopCount;
private int _loopCounter = 0;
private ESteps _steps = ESteps.None;
internal UnloadUnusedAssetsOperation(ResourceManager resourceManager, int loopCount)
@@ -26,7 +25,6 @@ namespace YooAsset
internal override void InternalStart()
{
_steps = ESteps.UnloadUnused;
_loopCounter = _loopCount;
}
internal override void InternalUpdate()
{
@@ -35,23 +33,13 @@ namespace YooAsset
if (_steps == ESteps.UnloadUnused)
{
while (_loopCounter > 0)
for (int i = 0; i < _loopCount; i++)
{
_loopCounter--;
LoopUnloadUnused();
if (IsWaitForAsyncComplete == false)
{
if (OperationSystem.IsBusy)
break;
}
}
if (_loopCounter <= 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
internal override void InternalWaitForAsyncComplete()

View File

@@ -14,7 +14,6 @@ namespace YooAsset
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
private long _sceneCreateIndex = 0;
private IBundleQuery _bundleQuery;
private int _bundleLoadingMaxConcurrency;
/// <summary>
/// 所属包裹
@@ -26,11 +25,6 @@ namespace YooAsset
/// </summary>
public bool LockLoadOperation = false;
/// <summary>
/// 统计正在加载的Bundle文件数量
/// </summary>
public int BundleLoadingCounter = 0;
public ResourceManager(string packageName)
{
@@ -40,9 +34,8 @@ namespace YooAsset
/// <summary>
/// 初始化
/// </summary>
public void Initialize(InitializeParameters parameters, IBundleQuery bundleServices)
public void Initialize(IBundleQuery bundleServices)
{
_bundleLoadingMaxConcurrency = parameters.BundleLoadingMaxConcurrency;
_bundleQuery = bundleServices;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
@@ -317,10 +310,6 @@ namespace YooAsset
{
return LoaderDic.Count > 0;
}
internal bool BundleLoadingIsBusy()
{
return BundleLoadingCounter >= _bundleLoadingMaxConcurrency;
}
private LoadBundleFileOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
{

View File

@@ -38,9 +38,9 @@ namespace YooAsset
/// </summary>
public FSDownloadFileOperation CreateDownloader(int failedTryAgain, int timeout)
{
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain, timeout);
options.ImportFilePath = _importFilePath;
return _fileSystem.DownloadFileAsync(Bundle, options);
DownloadParam downloadParam = new DownloadParam(failedTryAgain, timeout);
downloadParam.ImportFilePath = _importFilePath;
return _fileSystem.DownloadFileAsync(Bundle, downloadParam);
}
/// <summary>

View File

@@ -31,8 +31,8 @@ namespace YooAsset
/// <summary>
/// 清理缓存文件
/// </summary>
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam);
// 下载相关
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout);

View File

@@ -1,21 +0,0 @@

namespace YooAsset
{
public class ManifestDefine
{
/// <summary>
/// 文件极限大小100MB
/// </summary>
public const int FileMaxSize = 104857600;
/// <summary>
/// 文件头标记
/// </summary>
public const uint FileSign = 0x594F4F;
/// <summary>
/// 文件格式版本
/// </summary>
public const string FileVersion = "2.3.1";
}
}

View File

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

View File

@@ -8,30 +8,7 @@ namespace YooAsset
{
internal static class ManifestTools
{
/// <summary>
/// 验证清单文件的二进制数据
/// </summary>
public static bool VerifyManifestData(byte[] fileData, string hashValue)
{
if (fileData == null || fileData.Length == 0)
return false;
if (string.IsNullOrEmpty(hashValue))
return false;
// 注意:兼容俩种验证方式
// 注意计算MD5的哈希值通常为32个字符
string fileHash;
if (hashValue.Length == 32)
fileHash = HashUtility.BytesMD5(fileData);
else
fileHash = HashUtility.BytesCRC32(fileData);
if (fileHash == hashValue)
return true;
else
return false;
}
#if UNITY_EDITOR
/// <summary>
/// 序列化JSON文件
/// </summary>
@@ -49,10 +26,10 @@ namespace YooAsset
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
// 创建缓存器
BufferWriter buffer = new BufferWriter(ManifestDefine.FileMaxSize);
BufferWriter buffer = new BufferWriter(YooAssetSettings.ManifestFileMaxSize);
// 写入文件标记
buffer.WriteUInt32(ManifestDefine.FileSign);
buffer.WriteUInt32(YooAssetSettings.ManifestFileSign);
// 写入文件版本
buffer.WriteUTF8(manifest.FileVersion);
@@ -120,13 +97,13 @@ namespace YooAsset
// 读取文件标记
uint fileSign = buffer.ReadUInt32();
if (fileSign != ManifestDefine.FileSign)
if (fileSign != YooAssetSettings.ManifestFileSign)
throw new Exception("Invalid manifest file !");
// 读取文件版本
string fileVersion = buffer.ReadUTF8();
if (fileVersion != ManifestDefine.FileVersion)
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {ManifestDefine.FileVersion}");
if (fileVersion != YooAssetSettings.ManifestFileVersion)
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.ManifestFileVersion}");
PackageManifest manifest = new PackageManifest();
{
@@ -183,7 +160,7 @@ namespace YooAsset
InitManifest(manifest);
return manifest;
}
#endif
#region
public static void InitManifest(PackageManifest manifest)
@@ -221,16 +198,9 @@ namespace YooAsset
manifest.AssetDic = new Dictionary<string, PackageAsset>(assetCount);
if (manifest.EnableAddressable)
{
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 3);
}
else
{
if (manifest.LocationToLower)
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2, StringComparer.OrdinalIgnoreCase);
else
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
}
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
if (manifest.IncludeAssetGUID)
manifest.AssetPathMapping2 = new Dictionary<string, string>(assetCount);
@@ -252,6 +222,8 @@ namespace YooAsset
// 填充AssetPathMapping1
{
string location = packageAsset.AssetPath;
if (manifest.LocationToLower)
location = location.ToLower();
// 添加原生路径的映射
if (manifest.AssetPathMapping1.ContainsKey(location))
@@ -314,6 +286,27 @@ namespace YooAsset
}
#endregion
/// <summary>
/// 注意:该类拷贝自编辑器
/// </summary>
private enum EFileNameStyle
{
/// <summary>
/// 哈希值名称
/// </summary>
HashName = 0,
/// <summary>
/// 资源包名称(不推荐)
/// </summary>
BundleName = 1,
/// <summary>
/// 资源包名称 + 哈希值名称
/// </summary>
BundleName_HashName = 2,
}
/// <summary>
/// 获取资源文件的后缀名
/// </summary>

View File

@@ -15,15 +15,17 @@ namespace YooAsset
}
private readonly PlayModeImpl _impl;
private readonly ClearCacheFilesOptions _options;
private readonly string _clearMode;
private readonly object _clearParam;
private List<IFileSystem> _cloneList;
private FSClearCacheFilesOperation _clearCacheFilesOp;
private ESteps _steps = ESteps.None;
internal ClearCacheFilesOperation(PlayModeImpl impl, ClearCacheFilesOptions options)
internal ClearCacheFilesOperation(PlayModeImpl impl, string clearMode, object clearParam)
{
_impl = impl;
_options = options;
_clearMode = clearMode;
_clearParam = clearParam;
}
internal override void InternalStart()
{
@@ -72,7 +74,7 @@ namespace YooAsset
var fileSystem = _cloneList[0];
_cloneList.RemoveAt(0);
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _options);
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
_clearCacheFilesOp.StartOperation();
AddChildOperation(_clearCacheFilesOp);
_steps = ESteps.CheckClearResult;
@@ -100,7 +102,7 @@ namespace YooAsset
}
internal override string InternalGetDesc()
{
return $"ClearMode : {_options.ClearMode}";
return $"ClearMode : {_clearMode}";
}
}
}

View File

@@ -57,7 +57,7 @@ namespace YooAsset
// 读取文件标记
uint fileSign = _buffer.ReadUInt32();
if (fileSign != ManifestDefine.FileSign)
if (fileSign != YooAssetSettings.ManifestFileSign)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
@@ -67,11 +67,11 @@ namespace YooAsset
// 读取文件版本
string fileVersion = _buffer.ReadUTF8();
if (fileVersion != ManifestDefine.FileVersion)
if (fileVersion != YooAssetSettings.ManifestFileVersion)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"The manifest file version are not compatible : {fileVersion} != {ManifestDefine.FileVersion}";
Error = $"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.ManifestFileVersion}";
return;
}

View File

@@ -138,6 +138,9 @@ namespace YooAsset
if (string.IsNullOrEmpty(location))
return string.Empty;
if (LocationToLower)
location = location.ToLower();
if (AssetPathMapping1.TryGetValue(location, out string assetPath))
return assetPath;
else
@@ -304,6 +307,9 @@ namespace YooAsset
return string.Empty;
}
if (LocationToLower)
location = location.ToLower();
if (AssetPathMapping1.TryGetValue(location, out string assetPath))
{
return assetPath;

View File

@@ -97,9 +97,9 @@ namespace YooAsset
/// <summary>
/// 清理缓存文件
/// </summary>
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(ClearCacheFilesOptions options)
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{
var operation = new ClearCacheFilesOperation(this, options);
var operation = new ClearCacheFilesOperation(this, clearMode, clearParam);
return operation;
}

View File

@@ -100,7 +100,7 @@ namespace YooAsset
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
_bundleQuery = playModeImpl;
_playModeImpl = playModeImpl;
_resourceManager.Initialize(parameters, _bundleQuery);
_resourceManager.Initialize(_bundleQuery);
// 初始化资源系统
InitializationOperation initializeOperation;
@@ -162,10 +162,6 @@ namespace YooAsset
throw new Exception($"Editor simulate mode only support unity editor.");
#endif
// 检测初始化参数
if (parameters.BundleLoadingMaxConcurrency <= 0)
throw new Exception($"{nameof(parameters.BundleLoadingMaxConcurrency)} value must be greater than zero.");
// 鉴定运行模式
if (parameters is EditorSimulateModeParameters)
_playMode = EPlayMode.EditorSimulateMode;
@@ -267,11 +263,8 @@ namespace YooAsset
/// <param name="clearParam">执行参数</param>
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
{
DebugCheckInitialize(false);
ClearCacheFilesOptions options = new ClearCacheFilesOptions();
options.ClearMode = clearMode.ToString();
options.ClearParam = clearParam;
var operation = _playModeImpl.ClearCacheFilesAsync(options);
DebugCheckInitialize();
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -283,11 +276,8 @@ namespace YooAsset
/// <param name="clearParam">执行参数</param>
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
{
DebugCheckInitialize(false);
ClearCacheFilesOptions options = new ClearCacheFilesOptions();
options.ClearMode = clearMode;
options.ClearParam = clearParam;
var operation = _playModeImpl.ClearCacheFilesAsync(options);
DebugCheckInitialize();
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}

View File

@@ -16,6 +16,22 @@ namespace YooAsset
public string PackageManifestPrefix = string.Empty;
/// <summary>
/// 清单文件头标记
/// </summary>
public const uint ManifestFileSign = 0x594F4F;
/// <summary>
/// 清单文件极限大小100MB
/// </summary>
public const int ManifestFileMaxSize = 104857600;
/// <summary>
/// 清单文件格式版本
/// </summary>
public const string ManifestFileVersion = "2.3.1";
/// <summary>
/// 构建输出文件夹名称
/// </summary>

View File

@@ -106,6 +106,28 @@ namespace YooAsset
}
#region
/// <summary>
/// 获取YOO的Resources目录的加载路径
/// </summary>
internal static string GetYooResourcesLoadPath(string packageName, string fileName)
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return PathUtility.Combine(packageName, fileName);
else
return PathUtility.Combine(Setting.DefaultYooFolderName, packageName, fileName);
}
/// <summary>
/// 获取YOO的Resources目录的全路径
/// </summary>
internal static string GetYooResourcesFullPath()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return $"Assets/Resources";
else
return $"Assets/Resources/{Setting.DefaultYooFolderName}";
}
/// <summary>
/// 获取YOO的编辑器下缓存文件根目录
/// </summary>
@@ -198,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

@@ -63,22 +63,6 @@ namespace YooAsset
}
}
/// <summary>
/// 销毁资源系统
/// </summary>
public static void Destroy()
{
if (_isInitialize)
{
_isInitialize = false;
if (_driver != null)
GameObject.Destroy(_driver);
OnApplicationQuit(true);
}
}
/// <summary>
/// 更新资源系统
/// </summary>
@@ -93,7 +77,7 @@ namespace YooAsset
/// <summary>
/// 应用程序退出处理
/// </summary>
internal static void OnApplicationQuit(bool unloadAllAssetBundles)
internal static void OnApplicationQuit()
{
// 说明在编辑器下确保播放被停止时IO类操作被终止。
foreach (var package in _packages)
@@ -101,15 +85,6 @@ namespace YooAsset
OperationSystem.ClearPackageOperation(package.PackageName);
}
OperationSystem.DestroyAll();
// 清空资源包裹列表
_packages.Clear();
// 卸载所有AssetBundle
if (unloadAllAssetBundles)
{
AssetBundle.UnloadAllAssetBundles(true);
}
}
/// <summary>

View File

@@ -24,7 +24,7 @@ namespace YooAsset
#if UNITY_EDITOR
void OnApplicationQuit()
{
YooAssets.OnApplicationQuit(false);
YooAssets.OnApplicationQuit();
}
#endif

View File

@@ -51,6 +51,10 @@ namespace YooAsset.Editor
string manifestFileName = Path.GetFileNameWithoutExtension(manifestFilePath);
string outputDirectory = Path.GetDirectoryName(manifestFilePath);
// 加载补丁清单
byte[] bytesData = FileUtility.ReadAllBytes(manifestFilePath);
PackageManifest manifest = ManifestTools.DeserializeFromBinary(bytesData);
// 拷贝核心文件
{
string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes";
@@ -63,16 +67,12 @@ namespace YooAsset.Editor
EditorTools.CopyFile(sourcePath, destPath, true);
}
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName);
string sourcePath = $"{outputDirectory}/{fileName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{fileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 加载补丁清单
byte[] bytesData = FileUtility.ReadAllBytes(manifestFilePath);
PackageManifest manifest = ManifestTools.DeserializeFromBinary(bytesData);
// 拷贝文件列表
int fileCount = 0;
foreach (var packageBundle in manifest.BundleList)

View File

@@ -8,7 +8,7 @@ internal class TTFSDownloadFileOperation : DefaultDownloadFileOperation
private TiktokFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
_fileSystem = fileSystem;
}

View File

@@ -35,19 +35,19 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
{
if (_downloadAssetBundleOp == null)
{
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
downloadParam.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
downloadParam.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
if (_bundle.Encrypted)
{
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(false, _fileSystem.DecryptionServices, _bundle, options);
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(false, _fileSystem.DecryptionServices, _bundle, downloadParam);
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}
else
{
_downloadAssetBundleOp = new DownloadTiktokAssetBundleOperation(_bundle, options);
_downloadAssetBundleOp = new DownloadTiktokAssetBundleOperation(_bundle, downloadParam);
_downloadAssetBundleOp.StartOperation();
AddChildOperation(_downloadAssetBundleOp);
}

View File

@@ -8,7 +8,7 @@ namespace YooAsset
{
private ESteps _steps = ESteps.None;
internal DownloadTiktokAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
internal DownloadTiktokAssetBundleOperation(PackageBundle bundle, DownloadParam param) : base(bundle, param)
{
}
internal override void InternalStart()

View File

@@ -124,16 +124,16 @@ internal class TiktokFileSystem : IFileSystem
var operation = new TTFSRequestPackageVersionOperation(this, timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{
var operation = new FSClearCacheFilesCompleteOperation();
return operation;
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{
options.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
options.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
var operation = new TTFSDownloadFileOperation(this, bundle, options);
param.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
param.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
var operation = new TTFSDownloadFileOperation(this, bundle, param);
return operation;
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)

Some files were not shown because too many files have changed in this diff Show More