mirror of https://github.com/tuyoogame/YooAsset
update file system
parent
eb2f783417
commit
38aa1c3509
|
@ -30,7 +30,7 @@ namespace YooAsset.Editor
|
|||
|
||||
// 创建新补丁清单
|
||||
PackageManifest manifest = new PackageManifest();
|
||||
manifest.FileVersion = YooAssetSettings.ManifestFileVersion;
|
||||
manifest.FileVersion = ManifestDefine.FileVersion;
|
||||
manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
|
||||
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c6be7b8be0b51784997c959b370193e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cf87ffe3b3de69942ac16640a330dd37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -15,14 +15,13 @@ namespace YooAsset
|
|||
{
|
||||
public string BundleGUID;
|
||||
public string FileName;
|
||||
|
||||
public FileWrapper(string bundleGUID, string fileName)
|
||||
{
|
||||
BundleGUID = bundleGUID;
|
||||
FileName = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件版本
|
||||
/// </summary>
|
||||
public string FileVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
|
|
|
@ -336,9 +336,9 @@ namespace YooAsset
|
|||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(_packageRoot, fileName);
|
||||
}
|
||||
public string GetCatalogFileLoadPath()
|
||||
public string GetCatalogBinaryFileLoadPath()
|
||||
{
|
||||
return PathUtility.Combine(_packageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
return PathUtility.Combine(_packageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -84,6 +84,7 @@ namespace YooAsset
|
|||
|
||||
// 创建内置清单实例
|
||||
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion;
|
||||
buildinFileCatalog.PackageName = packageName;
|
||||
buildinFileCatalog.PackageVersion = packageVersion;
|
||||
|
||||
|
@ -97,7 +98,8 @@ namespace YooAsset
|
|||
$"{packageName}_{packageVersion}.hash",
|
||||
$"{packageName}_{packageVersion}.json",
|
||||
$"{packageName}_{packageVersion}.report",
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogFileName
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName,
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName
|
||||
};
|
||||
|
||||
// 记录所有内置资源文件
|
||||
|
@ -114,7 +116,9 @@ namespace YooAsset
|
|||
string fileName = fileInfo.Name;
|
||||
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);
|
||||
}
|
||||
else
|
||||
|
@ -123,16 +127,20 @@ namespace YooAsset
|
|||
}
|
||||
}
|
||||
|
||||
// 创建输出目录
|
||||
string saveFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
|
||||
if (File.Exists(saveFilePath))
|
||||
File.Delete(saveFilePath);
|
||||
|
||||
// 创建输出文件
|
||||
File.WriteAllText(saveFilePath, JsonUtility.ToJson(buildinFileCatalog, false));
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
string jsonFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}";
|
||||
if (File.Exists(jsonFilePath))
|
||||
File.Delete(jsonFilePath);
|
||||
CatalogTools.SerializeToJson(jsonFilePath, buildinFileCatalog);
|
||||
|
||||
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
|
||||
// 创建输出文件
|
||||
string binaryFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName}";
|
||||
if (File.Exists(binaryFilePath))
|
||||
File.Delete(binaryFilePath);
|
||||
CatalogTools.SerializeToBinary(binaryFilePath, buildinFileCatalog);
|
||||
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
Debug.Log($"Succeed to save buildin file catalog : {binaryFilePath}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,13 @@ namespace YooAsset
|
|||
internal class DefaultBuildinFileSystemDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置清单文件名称
|
||||
/// 内置清单JSON文件名称
|
||||
/// </summary>
|
||||
public const string BuildinCatalogFileName = "BuildinCatalog.json";
|
||||
public const string BuildinCatalogJsonFileName = "BuildinCatalog.json";
|
||||
|
||||
/// <summary>
|
||||
/// 内置清单二进制文件名称
|
||||
/// </summary>
|
||||
public const string BuildinCatalogBinaryFileName = "BuildinCatalog.bytes";
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
|
@ -14,10 +13,8 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private string _textData = null;
|
||||
|
||||
|
||||
internal LoadBuildinCatalogFileOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
|
@ -34,45 +31,36 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.RequestData)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
if (_webDataRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
||||
_webDataRequestOp.StartOperation();
|
||||
AddChildOperation(_webDataRequestOp);
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
_webDataRequestOp.UpdateOperation();
|
||||
if (_webDataRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
if (_webDataRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCatalog;
|
||||
_textData = _webTextRequestOp.Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webTextRequestOp.Error;
|
||||
Error = _webDataRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_textData))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin catalog file content is empty !";
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(_textData);
|
||||
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result);
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
|
|
@ -198,9 +198,9 @@ namespace YooAsset
|
|||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
public string GetCatalogFileLoadPath()
|
||||
public string GetCatalogBinaryFileLoadPath()
|
||||
{
|
||||
return PathUtility.Combine(_webPackageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
return PathUtility.Combine(_webPackageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
|
@ -17,9 +16,8 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private string _textData = null;
|
||||
|
||||
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem)
|
||||
{
|
||||
|
@ -36,45 +34,36 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.RequestData)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
if (_webDataRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
||||
_webDataRequestOp.StartOperation();
|
||||
AddChildOperation(_webDataRequestOp);
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
_webDataRequestOp.UpdateOperation();
|
||||
if (_webDataRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
if (_webDataRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCatalog;
|
||||
_textData = _webTextRequestOp.Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webTextRequestOp.Error;
|
||||
Error = _webDataRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_textData))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin catalog file content is empty !";
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(_textData);
|
||||
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result);
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace YooAsset
|
|||
{
|
||||
internal static class ManifestTools
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 序列化(JSON文件)
|
||||
/// </summary>
|
||||
|
@ -160,7 +159,7 @@ namespace YooAsset
|
|||
InitManifest(manifest);
|
||||
return manifest;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#region 解析资源清单辅助方法
|
||||
public static void InitManifest(PackageManifest manifest)
|
||||
|
|
Loading…
Reference in New Issue