pull/464/head
何冠峰 2025-02-06 11:15:09 +08:00
parent 203b9994df
commit 0b5d16bd0e
5 changed files with 79 additions and 8 deletions

View File

@ -34,14 +34,20 @@ namespace YooAsset
DirectoryInfo[] subDirectories = rootDirectory.GetDirectories(); DirectoryInfo[] subDirectories = rootDirectory.GetDirectories();
foreach (var subDirectory in subDirectories) foreach (var subDirectory in subDirectories)
{ {
CreateBuildinCatalogFile(subDirectory.Name, subDirectory.FullName); 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>
/// 生成包裹的内置资源目录文件 /// 生成包裹的内置资源目录文件
/// </summary> /// </summary>
public static void CreateBuildinCatalogFile(string packageName, string pacakgeDirectory) public static bool CreateBuildinCatalogFile(string packageName, string pacakgeDirectory)
{ {
// 获取资源清单版本 // 获取资源清单版本
string packageVersion; string packageVersion;
@ -50,7 +56,8 @@ namespace YooAsset
string versionFilePath = $"{pacakgeDirectory}/{versionFileName}"; string versionFilePath = $"{pacakgeDirectory}/{versionFileName}";
if (File.Exists(versionFilePath) == false) if (File.Exists(versionFilePath) == false)
{ {
throw new System.Exception($"Can not found package version file : {versionFilePath}"); Debug.LogError($"Can not found package version file : {versionFilePath}");
return false;
} }
packageVersion = FileUtility.ReadAllText(versionFilePath); packageVersion = FileUtility.ReadAllText(versionFilePath);
@ -63,7 +70,8 @@ namespace YooAsset
string manifestFilePath = $"{pacakgeDirectory}/{manifestFileName}"; string manifestFilePath = $"{pacakgeDirectory}/{manifestFileName}";
if (File.Exists(manifestFilePath) == false) if (File.Exists(manifestFilePath) == false)
{ {
throw new System.Exception($"Can not found package manifest file : {manifestFilePath}"); Debug.LogError($"Can not found package manifest file : {manifestFilePath}");
return false;
} }
var binaryData = FileUtility.ReadAllBytes(manifestFilePath); var binaryData = FileUtility.ReadAllBytes(manifestFilePath);
@ -117,10 +125,12 @@ namespace YooAsset
} }
} }
// 创建输出目录
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath(); string fullPath = YooAssetSettingsData.GetYooResourcesFullPath();
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}"; string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
FileUtility.CreateFileDirectory(saveFilePath); FileUtility.CreateFileDirectory(saveFilePath);
// 创建输出文件
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath); UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog); UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
#if UNITY_2019 #if UNITY_2019
@ -128,7 +138,9 @@ namespace YooAsset
#else #else
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog); UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
#endif #endif
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}"); Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
return true;
} }
} }
} }

View File

@ -74,7 +74,14 @@ namespace YooAsset
// 兼容性初始化 // 兼容性初始化
// 说明:内置文件系统在编辑器下运行时需要动态生成 // 说明:内置文件系统在编辑器下运行时需要动态生成
string packageRoot = _fileSystem.FileRoot; string packageRoot = _fileSystem.FileRoot;
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot); 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 #endif
_loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem); _loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);

View File

@ -1,4 +1,6 @@
 
using static UnityEngine.Networking.UnityWebRequest;
namespace YooAsset namespace YooAsset
{ {
internal class DWSFSInitializeOperation : FSInitializeFileSystemOperation internal class DWSFSInitializeOperation : FSInitializeFileSystemOperation
@ -37,7 +39,14 @@ namespace YooAsset
// 说明:内置文件系统在编辑器下运行时需要动态生成 // 说明:内置文件系统在编辑器下运行时需要动态生成
string buildinRoot = YooAssetSettingsData.GetYooEditorBuildinRoot(); string buildinRoot = YooAssetSettingsData.GetYooEditorBuildinRoot();
string packageRoot = PathUtility.Combine(buildinRoot, _fileSystem.PackageName); string packageRoot = PathUtility.Combine(buildinRoot, _fileSystem.PackageName);
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot); 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 #endif
_loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem); _loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem);

View File

@ -6,6 +6,7 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
CheckInitStatus,
UnloadAllAssets, UnloadAllAssets,
DestroyPackage, DestroyPackage,
Done, Done,
@ -23,13 +24,42 @@ namespace YooAsset
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_steps = ESteps.UnloadAllAssets; _steps = ESteps.CheckInitStatus;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.CheckInitStatus)
{
if (_resourcePackage.InitializeStatus == EOperationStatus.None)
{
_steps = ESteps.DestroyPackage;
}
else if (_resourcePackage.InitializeStatus == EOperationStatus.Processing)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "The Package is initializing ! Please try to destroy the package again later.";
}
else if (_resourcePackage.InitializeStatus == EOperationStatus.Failed)
{
_steps = ESteps.DestroyPackage;
}
else if (_resourcePackage.InitializeStatus == EOperationStatus.Succeed)
{
if (_resourcePackage.PackageValid)
_steps = ESteps.UnloadAllAssets;
else
_steps = ESteps.DestroyPackage;
}
else
{
throw new System.NotImplementedException(_resourcePackage.InitializeStatus.ToString());
}
}
if (_steps == ESteps.UnloadAllAssets) if (_steps == ESteps.UnloadAllAssets)
{ {
if (_unloadAllAssetsOp == null) if (_unloadAllAssetsOp == null)

View File

@ -31,6 +31,19 @@ namespace YooAsset
get { return _initializeStatus; } get { return _initializeStatus; }
} }
/// <summary>
/// 包裹是否有效
/// </summary>
public bool PackageValid
{
get
{
if (_playModeImpl == null)
return false;
return _playModeImpl.ActiveManifest != null;
}
}
internal ResourcePackage(string packageName) internal ResourcePackage(string packageName)
{ {
@ -258,7 +271,7 @@ namespace YooAsset
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam); return _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
} }
/// <summary> /// <summary>
/// 清理缓存文件 /// 清理缓存文件
/// </summary> /// </summary>