mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
TE6 打飞机Demo
TE6 打飞机Demo
This commit is contained in:
@@ -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:
|
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置资源清单目录
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class DefaultBuildinFileCatalog
|
||||
{
|
||||
[Serializable]
|
||||
public class FileWrapper
|
||||
{
|
||||
public string BundleGUID;
|
||||
public string FileName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件版本
|
||||
/// </summary>
|
||||
public string FileVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 文件列表
|
||||
/// </summary>
|
||||
public List<FileWrapper> Wrappers = new List<FileWrapper>();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b05c83971e3dca94f9fa460d396385e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,429 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置文件系统
|
||||
/// </summary>
|
||||
internal class DefaultBuildinFileSystem : IFileSystem
|
||||
{
|
||||
public class FileWrapper
|
||||
{
|
||||
public string FileName { private set; get; }
|
||||
|
||||
public FileWrapper(string fileName)
|
||||
{
|
||||
FileName = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
protected readonly Dictionary<string, FileWrapper> _wrappers = new Dictionary<string, FileWrapper>(10000);
|
||||
protected readonly Dictionary<string, string> _buildinFilePathMapping = new Dictionary<string, string>(10000);
|
||||
protected IFileSystem _unpackFileSystem;
|
||||
protected string _packageRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件根目录
|
||||
/// </summary>
|
||||
public string FileRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
return _packageRoot;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件数量
|
||||
/// </summary>
|
||||
public int FileCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _wrappers.Count;
|
||||
}
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:初始化的时候缓存文件校验级别
|
||||
/// </summary>
|
||||
public EFileVerifyLevel FileVerifyLevel { private set; get; } = EFileVerifyLevel.Middle;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:覆盖安装缓存清理模式
|
||||
/// </summary>
|
||||
public EOverwriteInstallClearMode InstallClearMode { private set; get; } = EOverwriteInstallClearMode.ClearAllManifestFiles;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:数据文件追加文件格式
|
||||
/// </summary>
|
||||
public bool AppendFileExtension { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:禁用Catalog目录查询文件
|
||||
/// </summary>
|
||||
public bool DisableCatalogFile { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置清单
|
||||
/// </summary>
|
||||
public bool CopyBuildinPackageManifest { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置清单的目标目录
|
||||
/// 注意:该参数为空的时候,会获取默认的沙盒目录!
|
||||
/// </summary>
|
||||
public string CopyBuildinPackageManifestDestRoot { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
|
||||
public DefaultBuildinFileSystem()
|
||||
{
|
||||
}
|
||||
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
|
||||
{
|
||||
var operation = new DBFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DBFSLoadPackageManifestOperation(this, packageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new DBFSRequestPackageVersionOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
{
|
||||
return _unpackFileSystem.ClearCacheFilesAsync(manifest, options);
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
{
|
||||
// 注意:业务层的解压下载器会依赖内置文件系统的下载方法
|
||||
options.ImportFilePath = GetBuildinFileLoadPath(bundle);
|
||||
return _unpackFileSystem.DownloadFileAsync(bundle, options);
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
{
|
||||
if (IsUnpackBundleFile(bundle))
|
||||
{
|
||||
return _unpackFileSystem.LoadBundleFile(bundle);
|
||||
}
|
||||
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new DBFSLoadAssetBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
else if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
|
||||
{
|
||||
var operation = new DBFSLoadRawBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(DefaultBuildinFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||
var operation = new FSLoadBundleCompleteOperation(error);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
|
||||
{
|
||||
FileVerifyLevel = (EFileVerifyLevel)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
|
||||
{
|
||||
InstallClearMode = (EOverwriteInstallClearMode)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
|
||||
{
|
||||
AppendFileExtension = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DISABLE_CATALOG_FILE)
|
||||
{
|
||||
DisableCatalogFile = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST)
|
||||
{
|
||||
CopyBuildinPackageManifest = Convert.ToBoolean(value);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT)
|
||||
{
|
||||
CopyBuildinPackageManifestDestRoot = (string)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IDecryptionServices)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
}
|
||||
}
|
||||
public virtual void OnCreate(string packageName, string packageRoot)
|
||||
{
|
||||
PackageName = packageName;
|
||||
|
||||
if (string.IsNullOrEmpty(packageRoot))
|
||||
_packageRoot = GetDefaultBuildinPackageRoot(packageName);
|
||||
else
|
||||
_packageRoot = packageRoot;
|
||||
|
||||
// 创建解压文件系统
|
||||
var remoteServices = new DefaultUnpackRemoteServices(_packageRoot);
|
||||
_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);
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
{
|
||||
if (DisableCatalogFile)
|
||||
return true;
|
||||
return _wrappers.ContainsKey(bundle.BundleGUID);
|
||||
}
|
||||
public virtual bool Exists(PackageBundle bundle)
|
||||
{
|
||||
if (DisableCatalogFile)
|
||||
return true;
|
||||
return _wrappers.ContainsKey(bundle.BundleGUID);
|
||||
}
|
||||
public virtual bool NeedDownload(PackageBundle bundle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual bool NeedUnpack(PackageBundle bundle)
|
||||
{
|
||||
if (IsUnpackBundleFile(bundle))
|
||||
{
|
||||
return _unpackFileSystem.Exists(bundle) == false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public virtual bool NeedImport(PackageBundle bundle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual string GetBundleFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (IsUnpackBundleFile(bundle))
|
||||
return _unpackFileSystem.GetBundleFilePath(bundle);
|
||||
|
||||
return GetBuildinFileLoadPath(bundle);
|
||||
}
|
||||
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
||||
{
|
||||
if (IsUnpackBundleFile(bundle))
|
||||
return _unpackFileSystem.ReadBundleFileData(bundle);
|
||||
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file data !");
|
||||
return null;
|
||||
#else
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileData(fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||||
{
|
||||
if (IsUnpackBundleFile(bundle))
|
||||
return _unpackFileSystem.ReadBundleFileText(bundle);
|
||||
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
YooLogger.Error($"Android platform not support read buildin bundle file text !");
|
||||
return null;
|
||||
#else
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.ReadFileText(fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
protected string GetDefaultBuildinPackageRoot(string packageName)
|
||||
{
|
||||
string rootDirectory = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
return PathUtility.Combine(rootDirectory, packageName);
|
||||
}
|
||||
public string GetBuildinFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
if (_buildinFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
{
|
||||
filePath = PathUtility.Combine(_packageRoot, bundle.FileName);
|
||||
_buildinFilePathMapping.Add(bundle.BundleGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetBuildinPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
|
||||
return PathUtility.Combine(_packageRoot, fileName);
|
||||
}
|
||||
public string GetBuildinPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(_packageRoot, fileName);
|
||||
}
|
||||
public string GetBuildinPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(_packageRoot, fileName);
|
||||
}
|
||||
public string GetCatalogBinaryFileLoadPath()
|
||||
{
|
||||
return PathUtility.Combine(_packageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否属于解压资源包文件
|
||||
/// </summary>
|
||||
protected bool IsUnpackBundleFile(PackageBundle bundle)
|
||||
{
|
||||
if (Belong(bundle) == false)
|
||||
return false;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
if (bundle.Encrypted)
|
||||
return true;
|
||||
|
||||
if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
/// </summary>
|
||||
public bool RecordCatalogFile(string bundleGUID, FileWrapper wrapper)
|
||||
{
|
||||
if (_wrappers.ContainsKey(bundleGUID))
|
||||
{
|
||||
YooLogger.Error($"{nameof(DefaultBuildinFileSystem)} has element : {bundleGUID}");
|
||||
return false;
|
||||
}
|
||||
|
||||
_wrappers.Add(bundleGUID, wrapper);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化解压文件系统
|
||||
/// </summary>
|
||||
public FSInitializeFileSystemOperation InitializeUpackFileSystem()
|
||||
{
|
||||
return _unpackFileSystem.InitializeFileSystemAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密的资源文件
|
||||
/// </summary>
|
||||
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.LoadAssetBundle(fileInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载加密的资源文件
|
||||
/// </summary>
|
||||
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle)
|
||||
{
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
var fileInfo = new DecryptFileInfo()
|
||||
{
|
||||
BundleName = bundle.BundleName,
|
||||
FileLoadCRC = bundle.UnityCRC,
|
||||
FileLoadPath = filePath,
|
||||
};
|
||||
return DecryptionServices.LoadAssetBundleAsync(fileInfo);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98465b987635afc479022ec358477491
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,148 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder { get { return 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// 在构建应用程序前自动生成内置资源目录文件。
|
||||
/// 原理:搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入文件,并存储在Resources目录下。
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
{
|
||||
YooLogger.Log("Begin to create catalog file !");
|
||||
|
||||
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists == false)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Can not found StreamingAssets root directory : {rootPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 搜索所有Package目录
|
||||
DirectoryInfo[] subDirectories = rootDirectory.GetDirectories();
|
||||
foreach (var subDirectory in subDirectories)
|
||||
{
|
||||
string packageName = subDirectory.Name;
|
||||
string pacakgeDirectory = subDirectory.FullName;
|
||||
bool result = CreateBuildinCatalogFile(packageName, pacakgeDirectory);
|
||||
if (result == false)
|
||||
{
|
||||
throw new System.Exception($"Create package {packageName} catalog file failed ! See the detail error in console !");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成包裹的内置资源目录文件
|
||||
/// </summary>
|
||||
public static bool CreateBuildinCatalogFile(string packageName, string pacakgeDirectory)
|
||||
{
|
||||
// 获取资源清单版本
|
||||
string packageVersion;
|
||||
{
|
||||
string versionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||
string versionFilePath = $"{pacakgeDirectory}/{versionFileName}";
|
||||
if (File.Exists(versionFilePath) == false)
|
||||
{
|
||||
Debug.LogError($"Can not found package version file : {versionFilePath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
packageVersion = FileUtility.ReadAllText(versionFilePath);
|
||||
}
|
||||
|
||||
// 加载资源清单文件
|
||||
PackageManifest packageManifest;
|
||||
{
|
||||
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||
string manifestFilePath = $"{pacakgeDirectory}/{manifestFileName}";
|
||||
if (File.Exists(manifestFilePath) == false)
|
||||
{
|
||||
Debug.LogError($"Can not found package manifest file : {manifestFilePath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var binaryData = FileUtility.ReadAllBytes(manifestFilePath);
|
||||
packageManifest = ManifestTools.DeserializeFromBinary(binaryData);
|
||||
}
|
||||
|
||||
// 获取文件名映射关系
|
||||
Dictionary<string, string> fileMapping = new Dictionary<string, string>();
|
||||
{
|
||||
foreach (var packageBundle in packageManifest.BundleList)
|
||||
{
|
||||
fileMapping.Add(packageBundle.FileName, packageBundle.BundleGUID);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建内置清单实例
|
||||
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();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta")
|
||||
continue;
|
||||
|
||||
if (whiteFileList.Contains(fileInfo.Name))
|
||||
continue;
|
||||
|
||||
string fileName = fileInfo.Name;
|
||||
if (fileMapping.TryGetValue(fileName, out string bundleGUID))
|
||||
{
|
||||
var wrapper = new DefaultBuildinFileCatalog.FileWrapper();
|
||||
wrapper.BundleGUID = bundleGUID;
|
||||
wrapper.FileName = fileName;
|
||||
buildinFileCatalog.Wrappers.Add(wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed mapping file : {fileName}");
|
||||
}
|
||||
}
|
||||
|
||||
// 创建输出文件
|
||||
string jsonFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}";
|
||||
if (File.Exists(jsonFilePath))
|
||||
File.Delete(jsonFilePath);
|
||||
CatalogTools.SerializeToJson(jsonFilePath, buildinFileCatalog);
|
||||
|
||||
// 创建输出文件
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b5abe115ebfe1344b674db78b2edf6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,16 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DefaultBuildinFileSystemDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置清单JSON文件名称
|
||||
/// </summary>
|
||||
public const string BuildinCatalogJsonFileName = "BuildinCatalog.json";
|
||||
|
||||
/// <summary>
|
||||
/// 内置清单二进制文件名称
|
||||
/// </summary>
|
||||
public const string BuildinCatalogBinaryFileName = "BuildinCatalog.bytes";
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4aa038f71ffd2394abc5daee917fbc66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06f6a75331ed07a4a9e5e8f46dcf157e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DBFSInitializeOperation : FSInitializeFileSystemOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CopyBuildinManifest,
|
||||
InitUnpackFileSystem,
|
||||
LoadCatalogFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private CopyBuildinPackageManifestOperation _copyBuildinPackageManifestOp;
|
||||
private FSInitializeFileSystemOperation _initUnpackFIleSystemOp;
|
||||
private LoadBuildinCatalogFileOperation _loadCatalogFileOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal DBFSInitializeOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(DefaultBuildinFileSystem)} is not support WEBGL platform !";
|
||||
#else
|
||||
if (_fileSystem.CopyBuildinPackageManifest)
|
||||
_steps = ESteps.CopyBuildinManifest;
|
||||
else
|
||||
_steps = ESteps.InitUnpackFileSystem;
|
||||
#endif
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CopyBuildinManifest)
|
||||
{
|
||||
if (_copyBuildinPackageManifestOp == null)
|
||||
{
|
||||
_copyBuildinPackageManifestOp = new CopyBuildinPackageManifestOperation(_fileSystem);
|
||||
_copyBuildinPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_copyBuildinPackageManifestOp);
|
||||
}
|
||||
|
||||
_copyBuildinPackageManifestOp.UpdateOperation();
|
||||
if (_copyBuildinPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_copyBuildinPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.InitUnpackFileSystem;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _copyBuildinPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.InitUnpackFileSystem)
|
||||
{
|
||||
if (_initUnpackFIleSystemOp == null)
|
||||
{
|
||||
_initUnpackFIleSystemOp = _fileSystem.InitializeUpackFileSystem();
|
||||
_initUnpackFIleSystemOp.StartOperation();
|
||||
AddChildOperation(_initUnpackFIleSystemOp);
|
||||
}
|
||||
|
||||
_initUnpackFIleSystemOp.UpdateOperation();
|
||||
Progress = _initUnpackFIleSystemOp.Progress;
|
||||
if (_initUnpackFIleSystemOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_initUnpackFIleSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
if (_fileSystem.DisableCatalogFile)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadCatalogFile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _initUnpackFIleSystemOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCatalogFile)
|
||||
{
|
||||
if (_loadCatalogFileOp == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 兼容性初始化
|
||||
// 说明:内置文件系统在编辑器下运行时需要动态生成
|
||||
string packageRoot = _fileSystem.FileRoot;
|
||||
bool result = DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
|
||||
if (result == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Create package catalog file failed ! See the detail error in console !";
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
_loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
|
||||
_loadCatalogFileOp.StartOperation();
|
||||
AddChildOperation(_loadCatalogFileOp);
|
||||
}
|
||||
|
||||
_loadCatalogFileOp.UpdateOperation();
|
||||
if (_loadCatalogFileOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadCatalogFileOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadCatalogFileOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a15804d2ba6172a4b91f6c17245495a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,214 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载AssetBundle文件
|
||||
/// </summary>
|
||||
internal class DBFSLoadAssetBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private AssetBundleCreateRequest _createRequest;
|
||||
private AssetBundle _assetBundle;
|
||||
private Stream _managedStream;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DBFSLoadAssetBundleOperation(DefaultBuildinFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
if (_fileSystem.DecryptionServices == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(IDecryptionServices)} is null !";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
var decryptResult = _fileSystem.LoadEncryptedAssetBundle(_bundle);
|
||||
_assetBundle = decryptResult.Result;
|
||||
_managedStream = decryptResult.ManagedStream;
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
_assetBundle = AssetBundle.LoadFromFile(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
var decryptResult = _fileSystem.LoadEncryptedAssetBundleAsync(_bundle);
|
||||
_createRequest = decryptResult.CreateRequest;
|
||||
_managedStream = decryptResult.ManagedStream;
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_createRequest != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity bundle.");
|
||||
_assetBundle = _createRequest.assetBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_createRequest.isDone == false)
|
||||
return;
|
||||
_assetBundle = _createRequest.assetBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new AssetBundleResult(_fileSystem, _bundle, _assetBundle, _managedStream);
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load encrypted buildin asset bundle file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load buildin asset bundle file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载原生文件
|
||||
/// </summary>
|
||||
internal class DBFSLoadRawBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadBuildinRawBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DBFSLoadRawBundleOperation(DefaultBuildinFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadBuildinRawBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadBuildinRawBundle)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||
_steps = ESteps.Done;
|
||||
Result = new RawBundleResult(_fileSystem, _bundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
#else
|
||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = new RawBundleResult(_fileSystem, _bundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found buildin raw bundle file : {filePath}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99fc95c784d960c45ba9373f31fbc7fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,89 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DBFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestBuildinPackageHash,
|
||||
LoadBuildinPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private RequestBuildinPackageHashOperation _requestBuildinPackageHashOp;
|
||||
private LoadBuildinPackageManifestOperation _loadBuildinPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public DBFSLoadPackageManifestOperation(DefaultBuildinFileSystem fileSystem, string packageVersion)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestBuildinPackageHash;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestBuildinPackageHash)
|
||||
{
|
||||
if (_requestBuildinPackageHashOp == null)
|
||||
{
|
||||
_requestBuildinPackageHashOp = new RequestBuildinPackageHashOperation(_fileSystem, _packageVersion);
|
||||
_requestBuildinPackageHashOp.StartOperation();
|
||||
AddChildOperation(_requestBuildinPackageHashOp);
|
||||
}
|
||||
|
||||
_requestBuildinPackageHashOp.UpdateOperation();
|
||||
if (_requestBuildinPackageHashOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestBuildinPackageHashOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadBuildinPackageManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestBuildinPackageHashOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBuildinPackageManifest)
|
||||
{
|
||||
if (_loadBuildinPackageManifestOp == null)
|
||||
{
|
||||
string packageHash = _requestBuildinPackageHashOp.PackageHash;
|
||||
_loadBuildinPackageManifestOp = new LoadBuildinPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
||||
_loadBuildinPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_loadBuildinPackageManifestOp);
|
||||
}
|
||||
|
||||
_loadBuildinPackageManifestOp.UpdateOperation();
|
||||
if (_loadBuildinPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadBuildinPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Manifest = _loadBuildinPackageManifestOp.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadBuildinPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b55b3624add2db6489954d999b13a9ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,59 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DBFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DBFSRequestPackageVersionOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_requestBuildinPackageVersionOp == null)
|
||||
{
|
||||
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
|
||||
_requestBuildinPackageVersionOp.StartOperation();
|
||||
AddChildOperation(_requestBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
_requestBuildinPackageVersionOp.UpdateOperation();
|
||||
if (_requestBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
PackageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestBuildinPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0b6ec24639af3741847a6a7ef09986a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be1c19353672bb34ca3e4ddcb462402f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class CopyBuildinPackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageVersion,
|
||||
CheckHashFile,
|
||||
UnpackHashFile,
|
||||
CheckManifestFile,
|
||||
UnpackManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
||||
private UnityWebFileRequestOperation _hashFileRequestOp;
|
||||
private UnityWebFileRequestOperation _manifestFileRequestOp;
|
||||
private string _buildinPackageVersion;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public CopyBuildinPackageManifestOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_requestBuildinPackageVersionOp == null)
|
||||
{
|
||||
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
|
||||
_requestBuildinPackageVersionOp.StartOperation();
|
||||
AddChildOperation(_requestBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
_requestBuildinPackageVersionOp.UpdateOperation();
|
||||
if (_requestBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CheckHashFile;
|
||||
_buildinPackageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestBuildinPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckHashFile)
|
||||
{
|
||||
string hashFilePath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
||||
if (File.Exists(hashFilePath))
|
||||
{
|
||||
_steps = ESteps.CheckManifestFile;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.UnpackHashFile;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackHashFile)
|
||||
{
|
||||
if (_hashFileRequestOp == null)
|
||||
{
|
||||
string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
||||
string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
||||
_hashFileRequestOp.StartOperation();
|
||||
AddChildOperation(_hashFileRequestOp);
|
||||
}
|
||||
|
||||
_hashFileRequestOp.UpdateOperation();
|
||||
if (_hashFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_hashFileRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CheckManifestFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _hashFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckManifestFile)
|
||||
{
|
||||
string manifestFilePath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
||||
if (File.Exists(manifestFilePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.UnpackManifestFile;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackManifestFile)
|
||||
{
|
||||
if (_manifestFileRequestOp == null)
|
||||
{
|
||||
string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||
string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
||||
_manifestFileRequestOp.StartOperation();
|
||||
AddChildOperation(_manifestFileRequestOp);
|
||||
}
|
||||
|
||||
_manifestFileRequestOp.UpdateOperation();
|
||||
if (_manifestFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_manifestFileRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _manifestFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetCopyManifestFileRoot()
|
||||
{
|
||||
string destRoot = _fileSystem.CopyBuildinPackageManifestDestRoot;
|
||||
if (string.IsNullOrEmpty(destRoot))
|
||||
{
|
||||
string defaultCacheRoot = YooAssetSettingsData.GetYooDefaultCacheRoot();
|
||||
destRoot = PathUtility.Combine(defaultCacheRoot, _fileSystem.PackageName, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
|
||||
}
|
||||
return destRoot;
|
||||
}
|
||||
private string GetCopyPackageHashDestPath(string packageVersion)
|
||||
{
|
||||
string fileRoot = GetCopyManifestFileRoot();
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_fileSystem.PackageName, packageVersion);
|
||||
return PathUtility.Combine(fileRoot, fileName);
|
||||
}
|
||||
private string GetCopyPackageManifestDestPath(string packageVersion)
|
||||
{
|
||||
string fileRoot = GetCopyManifestFileRoot();
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, packageVersion);
|
||||
return PathUtility.Combine(fileRoot, fileName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69f62f6b4185d06498f96aa272e9b926
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class LoadBuildinCatalogFileOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestData,
|
||||
LoadCatalog,
|
||||
Done,
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load catalog file : {e.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4113df346bbd1b4ead918b52ac46f55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,117 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadBuildinPackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestFileData,
|
||||
VerifyFileData,
|
||||
LoadManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private readonly string _packageHash;
|
||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹清单
|
||||
/// </summary>
|
||||
public PackageManifest Manifest { private set; get; }
|
||||
|
||||
|
||||
internal LoadBuildinPackageManifestOperation(DefaultBuildinFileSystem fileSystem, string packageVersion, string packageHash)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
_packageHash = packageHash;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestFileData;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestFileData)
|
||||
{
|
||||
if (_webDataRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageManifestFilePath(_packageVersion);
|
||||
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.VerifyFileData;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webDataRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify buildin package manifest file !";
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadManifest)
|
||||
{
|
||||
if (_deserializer == null)
|
||||
{
|
||||
_deserializer = new DeserializeManifestOperation(_webDataRequestOp.Result);
|
||||
_deserializer.StartOperation();
|
||||
AddChildOperation(_deserializer);
|
||||
}
|
||||
|
||||
_deserializer.UpdateOperation();
|
||||
Progress = _deserializer.Progress;
|
||||
if (_deserializer.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Manifest = _deserializer.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _deserializer.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8af9b72837c6a01428ee627011f4341b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,77 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RequestBuildinPackageHashOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageHash,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹哈希值
|
||||
/// </summary>
|
||||
public string PackageHash { private set; get; }
|
||||
|
||||
|
||||
internal RequestBuildinPackageHashOperation(DefaultBuildinFileSystem fileSystem, string packageVersion)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageHash;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageHash)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageHashFilePath(_packageVersion);
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageHash = _webTextRequestOp.Result;
|
||||
if (string.IsNullOrEmpty(PackageHash))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package hash file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webTextRequestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2084625d8253164aa71ef934e0690fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,75 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RequestBuildinPackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
|
||||
|
||||
internal RequestBuildinPackageVersionOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageVersionFilePath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _webTextRequestOp.Result;
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package version file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webTextRequestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bddb076e377b66488ec28c9dbdd18cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user