Compare commits

...

7 Commits

Author SHA1 Message Date
何冠峰
974493f88d Update CHANGELOG.md 2025-03-25 11:15:56 +08:00
何冠峰
69a69988a1 Update package.json 2025-03-25 11:15:24 +08:00
何冠峰
4e9c1955eb fix #486 2025-03-14 18:54:03 +08:00
何冠峰
b6c68a533e update asset bundle builder
增加TaskCreateCatalog任务节点
2025-03-14 18:49:56 +08:00
何冠峰
38aa1c3509 update file system 2025-03-14 18:26:04 +08:00
何冠峰
eb2f783417 update resource package 2025-03-14 17:23:55 +08:00
何冠峰
8556e071fa fix #507 2025-03-14 16:50:48 +08:00
32 changed files with 487 additions and 153 deletions

View File

@@ -2,6 +2,17 @@
All notable changes to this package will be documented in this file. All notable changes to this package will be documented in this file.
## [2.3.6] - 2025-03-25
### Improvements
- 构建管线新增了TaskCreateCatalog任务节点。
- 内置文件系统的catalog文件现在存储在streammingAssets目录下。
### Fixed
- (#486) 修复了微信小游戏文件系统调用ClearUnusedBundleFiles时候的异常。
## [2.3.5-preview] - 2025-03-14 ## [2.3.5-preview] - 2025-03-14
### Fixed ### Fixed

View File

@@ -0,0 +1,23 @@
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

@@ -0,0 +1,11 @@
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(); PackageManifest manifest = new PackageManifest();
manifest.FileVersion = YooAssetSettings.ManifestFileVersion; manifest.FileVersion = ManifestDefine.FileVersion;
manifest.EnableAddressable = buildMapContext.Command.EnableAddressable; manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
manifest.LocationToLower = buildMapContext.Command.LocationToLower; manifest.LocationToLower = buildMapContext.Command.LocationToLower;
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID; manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;

View File

@@ -0,0 +1,20 @@
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

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

View File

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

View File

@@ -0,0 +1,20 @@
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

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

View File

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

View File

@@ -0,0 +1,20 @@
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

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

View File

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

View File

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

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

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

View File

@@ -0,0 +1,102 @@
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

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

View File

@@ -1,27 +1,27 @@
using System; using System;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
/// <summary> /// <summary>
/// 内置资源清单目录 /// 内置资源清单目录
/// </summary> /// </summary>
internal class DefaultBuildinFileCatalog : ScriptableObject [Serializable]
internal class DefaultBuildinFileCatalog
{ {
[Serializable] [Serializable]
public class FileWrapper public class FileWrapper
{ {
public string BundleGUID; public string BundleGUID;
public string FileName; public string FileName;
public FileWrapper(string bundleGUID, string fileName)
{
BundleGUID = bundleGUID;
FileName = fileName;
}
} }
/// <summary>
/// 文件版本
/// </summary>
public string FileVersion;
/// <summary> /// <summary>
/// 包裹名称 /// 包裹名称
/// </summary> /// </summary>

View File

@@ -336,10 +336,9 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(_packageRoot, fileName); return PathUtility.Combine(_packageRoot, fileName);
} }
public string GetCatalogFileLoadPath() public string GetCatalogBinaryFileLoadPath()
{ {
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName); return PathUtility.Combine(_packageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
} }
/// <summary> /// <summary>

View File

@@ -17,10 +17,6 @@ namespace YooAsset
{ {
YooLogger.Log("Begin to create catalog file !"); YooLogger.Log("Begin to create catalog file !");
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
if (UnityEditor.AssetDatabase.DeleteAsset(savePath))
UnityEditor.AssetDatabase.Refresh();
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot(); string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists == false) if (rootDirectory.Exists == false)
@@ -87,10 +83,25 @@ namespace YooAsset
} }
// 创建内置清单实例 // 创建内置清单实例
var buildinFileCatalog = ScriptableObject.CreateInstance<DefaultBuildinFileCatalog>(); var buildinFileCatalog = new DefaultBuildinFileCatalog();
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion;
buildinFileCatalog.PackageName = packageName; buildinFileCatalog.PackageName = packageName;
buildinFileCatalog.PackageVersion = packageVersion; 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); DirectoryInfo rootDirectory = new DirectoryInfo(pacakgeDirectory);
FileInfo[] fileInfos = rootDirectory.GetFiles(); FileInfo[] fileInfos = rootDirectory.GetFiles();
@@ -99,23 +110,15 @@ namespace YooAsset
if (fileInfo.Extension == ".meta") if (fileInfo.Extension == ".meta")
continue; continue;
if (fileInfo.Name == "link.xml" || fileInfo.Name == "buildlogtep.json") if (whiteFileList.Contains(fileInfo.Name))
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; continue;
string fileName = fileInfo.Name; string fileName = fileInfo.Name;
if (fileMapping.TryGetValue(fileName, out string bundleGUID)) if (fileMapping.TryGetValue(fileName, out string bundleGUID))
{ {
var wrapper = new DefaultBuildinFileCatalog.FileWrapper(bundleGUID, fileName); var wrapper = new DefaultBuildinFileCatalog.FileWrapper();
wrapper.BundleGUID = bundleGUID;
wrapper.FileName = fileName;
buildinFileCatalog.Wrappers.Add(wrapper); buildinFileCatalog.Wrappers.Add(wrapper);
} }
else else
@@ -124,21 +127,20 @@ namespace YooAsset
} }
} }
// 创建输出目录 // 创建输出文件
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath(); string jsonFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}";
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}"; if (File.Exists(jsonFilePath))
FileUtility.CreateFileDirectory(saveFilePath); File.Delete(jsonFilePath);
CatalogTools.SerializeToJson(jsonFilePath, buildinFileCatalog);
// 创建输出文件 // 创建输出文件
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath); string binaryFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName}";
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog); if (File.Exists(binaryFilePath))
#if UNITY_2019 File.Delete(binaryFilePath);
UnityEditor.AssetDatabase.SaveAssets(); CatalogTools.SerializeToBinary(binaryFilePath, buildinFileCatalog);
#else
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
#endif
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}"); UnityEditor.AssetDatabase.Refresh();
Debug.Log($"Succeed to save buildin file catalog : {binaryFilePath}");
return true; return true;
} }
} }

View File

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

View File

@@ -1,4 +1,4 @@
using UnityEngine; using System;
namespace YooAsset namespace YooAsset
{ {
@@ -7,56 +7,84 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
RequestData,
LoadCatalog, LoadCatalog,
Done, Done,
} }
private readonly DefaultBuildinFileSystem _fileSystem; private readonly DefaultBuildinFileSystem _fileSystem;
private UnityWebDataRequestOperation _webDataRequestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal LoadBuildinCatalogFileOperation(DefaultBuildinFileSystem fileSystem) internal LoadBuildinCatalogFileOperation(DefaultBuildinFileSystem fileSystem)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.LoadCatalog; _steps = ESteps.RequestData;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; 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;
}
}
if (_steps == ESteps.LoadCatalog) if (_steps == ESteps.LoadCatalog)
{ {
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath(); try
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath); {
if (catalog == null) 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;
}
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}");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (Exception e)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Failed to load catalog file : {catalogFilePath}"; Error = $"Failed to load catalog file : {e.Message}";
return;
} }
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;
}
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}");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
} }
} }
} }

View File

@@ -198,10 +198,9 @@ namespace YooAsset
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName); return PathUtility.Combine(FileRoot, fileName);
} }
public string GetCatalogFileLoadPath() public string GetCatalogBinaryFileLoadPath()
{ {
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName); return PathUtility.Combine(_webPackageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
} }
/// <summary> /// <summary>

View File

@@ -2,7 +2,6 @@
using System.IO; using System.IO;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
@@ -11,61 +10,84 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
RequestData,
LoadCatalog, LoadCatalog,
Done, Done,
} }
private readonly DefaultWebServerFileSystem _fileSystem; private readonly DefaultWebServerFileSystem _fileSystem;
private UnityWebDataRequestOperation _webDataRequestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
/// <summary>
/// 内置清单版本
/// </summary>
public string PackageVersion { private set; get; }
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem) internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.LoadCatalog; _steps = ESteps.RequestData;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; 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;
}
}
if (_steps == ESteps.LoadCatalog) if (_steps == ESteps.LoadCatalog)
{ {
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath(); try
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath); {
if (catalog == null) 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;
}
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultWebServerFileSystem.FileWrapper(wrapper.FileName);
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (Exception e)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Failed to load web server catalog file : {catalogFilePath}"; Error = $"Failed to load catalog file : {e.Message}";
return;
} }
if (catalog.PackageName != _fileSystem.PackageName)
{
_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}");
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
} }
} }
} }

View File

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

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

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

View File

@@ -8,7 +8,6 @@ namespace YooAsset
{ {
internal static class ManifestTools internal static class ManifestTools
{ {
#if UNITY_EDITOR
/// <summary> /// <summary>
/// 序列化JSON文件 /// 序列化JSON文件
/// </summary> /// </summary>
@@ -26,10 +25,10 @@ namespace YooAsset
using (FileStream fs = new FileStream(savePath, FileMode.Create)) using (FileStream fs = new FileStream(savePath, FileMode.Create))
{ {
// 创建缓存器 // 创建缓存器
BufferWriter buffer = new BufferWriter(YooAssetSettings.ManifestFileMaxSize); BufferWriter buffer = new BufferWriter(ManifestDefine.FileMaxSize);
// 写入文件标记 // 写入文件标记
buffer.WriteUInt32(YooAssetSettings.ManifestFileSign); buffer.WriteUInt32(ManifestDefine.FileSign);
// 写入文件版本 // 写入文件版本
buffer.WriteUTF8(manifest.FileVersion); buffer.WriteUTF8(manifest.FileVersion);
@@ -97,13 +96,13 @@ namespace YooAsset
// 读取文件标记 // 读取文件标记
uint fileSign = buffer.ReadUInt32(); uint fileSign = buffer.ReadUInt32();
if (fileSign != YooAssetSettings.ManifestFileSign) if (fileSign != ManifestDefine.FileSign)
throw new Exception("Invalid manifest file !"); throw new Exception("Invalid manifest file !");
// 读取文件版本 // 读取文件版本
string fileVersion = buffer.ReadUTF8(); string fileVersion = buffer.ReadUTF8();
if (fileVersion != YooAssetSettings.ManifestFileVersion) if (fileVersion != ManifestDefine.FileVersion)
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.ManifestFileVersion}"); throw new Exception($"The manifest file version are not compatible : {fileVersion} != {ManifestDefine.FileVersion}");
PackageManifest manifest = new PackageManifest(); PackageManifest manifest = new PackageManifest();
{ {
@@ -160,7 +159,7 @@ namespace YooAsset
InitManifest(manifest); InitManifest(manifest);
return manifest; return manifest;
} }
#endif
#region #region
public static void InitManifest(PackageManifest manifest) public static void InitManifest(PackageManifest manifest)

View File

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

View File

@@ -16,22 +16,6 @@ namespace YooAsset
public string PackageManifestPrefix = string.Empty; 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>
/// 构建输出文件夹名称 /// 构建输出文件夹名称
/// </summary> /// </summary>

View File

@@ -106,28 +106,6 @@ namespace YooAsset
} }
#region #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> /// <summary>
/// 获取YOO的编辑器下缓存文件根目录 /// 获取YOO的编辑器下缓存文件根目录
/// </summary> /// </summary>

View File

@@ -17,7 +17,7 @@ internal class WXFSClearUnusedBundleFilesAsync : FSClearCacheFilesOperation
private readonly WechatFileSystem _fileSystem; private readonly WechatFileSystem _fileSystem;
private readonly PackageManifest _manifest; private readonly PackageManifest _manifest;
private List<string> _unusedCacheFiles; private List<string> _unusedCacheFiles = new List<string>(1000);
private int _unusedFileTotalCount = 0; private int _unusedFileTotalCount = 0;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;

View File

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