Compare commits

...

4 Commits

Author SHA1 Message Date
何冠峰 e925d9892f fix #448 2025-02-06 17:43:40 +08:00
何冠峰 e7907eeaa7 fix #454
内置文件系统新增COPY_BUILDIN_PACKAGE_MANIFEST参数
2025-02-06 17:35:10 +08:00
何冠峰 644e6655ff update extension sample 2025-02-06 16:44:25 +08:00
何冠峰 20c07af504 update YooAssetSettings 2025-02-06 16:43:55 +08:00
15 changed files with 266 additions and 68 deletions

View File

@ -36,7 +36,7 @@ namespace YooAsset.Editor
BuildLogger.InitLogger(enableLog);
// 执行构建流程
Debug.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}");
BuildLogger.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}");
var buildResult = BuildRunner.Run(buildPipeline, _buildContext);
if (buildResult.Success)
{

View File

@ -22,7 +22,7 @@ namespace YooAsset.Editor
/// </summary>
public static string GetStreamingAssetsRoot()
{
return YooAssetSettingsData.GetYooEditorBuildinRoot();
return YooAssetSettingsData.GetYooDefaultBuildinRoot();
}
}
}

View File

@ -68,6 +68,17 @@ namespace YooAsset
/// </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>
@ -147,6 +158,14 @@ namespace YooAsset
{
DisableCatalogFile = (bool)value;
}
else if (name == FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST)
{
CopyBuildinPackageManifest = (bool)value;
}
else if (name == FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT)
{
CopyBuildinPackageManifestDestRoot = (string)value;
}
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
{
DecryptionServices = (IDecryptionServices)value;
@ -291,7 +310,7 @@ namespace YooAsset
#region 内部方法
protected string GetDefaultBuildinPackageRoot(string packageName)
{
string rootDirectory = YooAssetSettingsData.GetYooMobileBuildinRoot();
string rootDirectory = YooAssetSettingsData.GetYooDefaultBuildinRoot();
return PathUtility.Combine(rootDirectory, packageName);
}
public string GetBuildinFileLoadPath(PackageBundle bundle)

View File

@ -22,7 +22,7 @@ namespace YooAsset
if (saveDirectory.Exists)
saveDirectory.Delete(true);
string rootPath = YooAssetSettingsData.GetYooEditorBuildinRoot();
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists == false)
{

View File

@ -8,12 +8,14 @@ namespace YooAsset
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;
@ -29,7 +31,10 @@ namespace YooAsset
Status = EOperationStatus.Failed;
Error = $"{nameof(DefaultBuildinFileSystem)} is not support WEBGL platform !";
#else
_steps = ESteps.InitUnpackFileSystem;
if (_fileSystem.CopyBuildinPackageManifest)
_steps = ESteps.CopyBuildinManifest;
else
_steps = ESteps.InitUnpackFileSystem;
#endif
}
internal override void InternalOnUpdate()
@ -37,6 +42,29 @@ namespace YooAsset
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CopyBuildinManifest)
{
if (_copyBuildinPackageManifestOp == null)
{
_copyBuildinPackageManifestOp = new CopyBuildinPackageManifestOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _copyBuildinPackageManifestOp);
}
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)

View File

@ -0,0 +1,167 @@
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 InternalOnStart()
{
_steps = ESteps.RequestPackageVersion;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageVersion)
{
if (_requestBuildinPackageVersionOp == null)
{
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageVersionOp);
}
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);
OperationSystem.StartOperation(_fileSystem.PackageName, _hashFileRequestOp);
}
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);
OperationSystem.StartOperation(_fileSystem.PackageName, _manifestFileRequestOp);
}
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);
}
}
}

View File

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

View File

@ -473,16 +473,7 @@ namespace YooAsset
#region 内部方法
public string GetDefaultCachePackageRoot(string packageName)
{
string rootDirectory;
#if UNITY_EDITOR
rootDirectory = YooAssetSettingsData.GetYooEditorCacheRoot();
#elif UNITY_STANDALONE
rootDirectory = YooAssetSettingsData.GetYooStandaloneCacheRoot();
#else
rootDirectory = YooAssetSettingsData.GetYooMobileCacheRoot();
#endif
string rootDirectory = YooAssetSettingsData.GetYooDefaultCacheRoot();
return PathUtility.Combine(rootDirectory, packageName);
}
public string GetCacheBundleFileLoadPath(PackageBundle bundle)

View File

@ -174,17 +174,17 @@ namespace YooAsset
public string GetEditorPackageVersionFilePath()
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
return PathUtility.Combine(FileRoot, fileName);
return PathUtility.Combine(_packageRoot, fileName);
}
public string GetEditorPackageHashFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName);
return PathUtility.Combine(_packageRoot, fileName);
}
public string GetEditorPackageManifestFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(FileRoot, fileName);
return PathUtility.Combine(_packageRoot, fileName);
}
public int GetAsyncSimulateFrame()
{

View File

@ -168,7 +168,7 @@ namespace YooAsset
#region 内部方法
protected string GetDefaultWebPackageRoot(string packageName)
{
string rootDirectory = YooAssetSettingsData.GetYooWebBuildinRoot();
string rootDirectory = YooAssetSettingsData.GetYooDefaultBuildinRoot();
return PathUtility.Combine(rootDirectory, packageName);
}
public string GetWebFileLoadPath(PackageBundle bundle)

View File

@ -37,8 +37,7 @@ namespace YooAsset
#if UNITY_EDITOR
// 兼容性初始化
// 说明:内置文件系统在编辑器下运行时需要动态生成
string buildinRoot = YooAssetSettingsData.GetYooEditorBuildinRoot();
string packageRoot = PathUtility.Combine(buildinRoot, _fileSystem.PackageName);
string packageRoot = _fileSystem.FileRoot;
bool result = DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
if (result == false)
{

View File

@ -15,5 +15,7 @@ namespace YooAsset
public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES";
public const string ASYNC_SIMULATE_MIN_FRAME = "ASYNC_SIMULATE_MIN_FRAME";
public const string ASYNC_SIMULATE_MAX_FRAME = "ASYNC_SIMULATE_MAX_FRAME";
public const string COPY_BUILDIN_PACKAGE_MANIFEST = "COPY_BUILDIN_PACKAGE_MANIFEST";
public const string COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT = "COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT";
}
}

View File

@ -111,50 +111,6 @@ namespace YooAsset
return $"Assets/Resources/{Setting.DefaultYooFolderName}";
}
/// <summary>
/// 获取YOO的编辑器下内置文件根目录
/// </summary>
public static string GetYooEditorBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return PathUtility.Combine(Application.dataPath, "StreamingAssets");
else
return PathUtility.Combine(Application.dataPath, "StreamingAssets", Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的PC端内置文件根目录
/// </summary>
public static string GetYooStandaloneBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.streamingAssetsPath;
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的移动端内置文件根目录
/// </summary>
public static string GetYooMobileBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.streamingAssetsPath;
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的Web端内置文件根目录
/// </summary>
public static string GetYooWebBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.streamingAssetsPath;
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO的编辑器下缓存文件根目录
/// </summary>
@ -196,6 +152,31 @@ namespace YooAsset
else
return PathUtility.Combine(Application.persistentDataPath, Setting.DefaultYooFolderName);
}
/// <summary>
/// 获取YOO默认的缓存文件根目录
/// </summary>
public static string GetYooDefaultCacheRoot()
{
#if UNITY_EDITOR
return GetYooEditorCacheRoot();
#elif UNITY_STANDALONE
return GetYooStandaloneCacheRoot();
#else
return GetYooMobileCacheRoot();
#endif
}
/// <summary>
/// 获取YOO默认的内置文件根目录
/// </summary>
public static string GetYooDefaultBuildinRoot()
{
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
return Application.streamingAssetsPath;
else
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
}
#endregion
}
}

View File

@ -123,7 +123,7 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
private string GetBuildinYooRoot()
{
return YooAssetSettingsData.GetYooMobileBuildinRoot();
return YooAssetSettingsData.GetYooDefaultBuildinRoot();
}
private string GetBuildinHashFilePath()
{
@ -140,7 +140,7 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
private string GetCacheYooRoot()
{
return YooAssetSettingsData.GetYooMobileCacheRoot();
return YooAssetSettingsData.GetYooDefaultCacheRoot();
}
private string GetCacheHashFilePath()
{

View File

@ -63,7 +63,7 @@ public class GetCacheBundleSizeOperation : GameAsyncOperation
private string GetCacheDirectoryRoot()
{
string rootDirectory = YooAssetSettingsData.GetYooMobileCacheRoot();
string rootDirectory = YooAssetSettingsData.GetYooDefaultCacheRoot();
string packageRoot = PathUtility.Combine(rootDirectory, _packageName);
return PathUtility.Combine(packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName);
}