mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-22 16:50:18 +00:00
Compare commits
6 Commits
e984d69c48
...
278fca667e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
278fca667e | ||
|
|
6155256fb6 | ||
|
|
0d4f2bc893 | ||
|
|
600e928ab4 | ||
|
|
4599ff098c | ||
|
|
0b4f6d6639 |
@@ -2,6 +2,15 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.3.5-preview] - 2025-03-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#502) 修复了原生缓存文件由于文件格式变动导致的加载本地缓存文件失败的问题。
|
||||
- (#504) 修复了MacOS平台Offline Play Mode模式请求本地资源清单失败的问题。
|
||||
- (#506) 修复了v2.3x版本LoadAllAssets方法计算依赖Bundle不完整的问题。
|
||||
- (#506) 修复了微信小游戏文件系统,在启用加密算法后卸载bundle报错的问题。
|
||||
|
||||
## [2.3.4-preview] - 2025-03-08
|
||||
|
||||
### Improvements
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace YooAsset.Editor
|
||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace YooAsset.Editor
|
||||
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace YooAsset.Editor
|
||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
DefaultBuildinFileSystemBuild.ExportBuildinCatalogFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置资源清单目录
|
||||
/// </summary>
|
||||
internal class DefaultBuildinFileCatalog : ScriptableObject
|
||||
[Serializable]
|
||||
internal class DefaultBuildinFileCatalog
|
||||
{
|
||||
[Serializable]
|
||||
public class FileWrapper
|
||||
|
||||
@@ -338,8 +338,8 @@ namespace YooAsset
|
||||
}
|
||||
public string GetCatalogFileLoadPath()
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(DefaultBuildinFileSystemDefine.BuildinCatalogFileName);
|
||||
return YooAssetSettingsData.GetYooResourcesLoadPath(PackageName, fileName);
|
||||
string fileName = DefaultBuildinFileSystemDefine.BuildinCatalogFileName;
|
||||
return PathUtility.Combine(YooAssetSettingsData.GetRequestYooDefaultBuildinRoot(), PackageName, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,22 +5,16 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class DefaultBuildinFileSystemBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
public class DefaultBuildinFileSystemBuild
|
||||
{
|
||||
public int callbackOrder { get { return 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// 在构建应用程序前自动生成内置资源目录文件。
|
||||
/// 原理:搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入文件,并存储在Resources目录下。
|
||||
/// 输出包裹的内置资源目录文件
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
/// <exception cref="System.Exception"></exception>
|
||||
public static void ExportBuildinCatalogFile()
|
||||
{
|
||||
YooLogger.Log("Begin to create catalog file !");
|
||||
|
||||
string savePath = YooAssetSettingsData.GetYooResourcesFullPath();
|
||||
if (UnityEditor.AssetDatabase.DeleteAsset(savePath))
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
|
||||
string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists == false)
|
||||
@@ -87,7 +81,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 创建内置清单实例
|
||||
var buildinFileCatalog = ScriptableObject.CreateInstance<DefaultBuildinFileCatalog>();
|
||||
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||
buildinFileCatalog.PackageName = packageName;
|
||||
buildinFileCatalog.PackageVersion = packageVersion;
|
||||
|
||||
@@ -111,6 +105,8 @@ namespace YooAsset
|
||||
continue;
|
||||
if (fileInfo.Name == $"{packageName}_{packageVersion}.report")
|
||||
continue;
|
||||
if (fileInfo.Name == DefaultBuildinFileSystemDefine.BuildinCatalogFileName)
|
||||
continue;
|
||||
|
||||
string fileName = fileInfo.Name;
|
||||
if (fileMapping.TryGetValue(fileName, out string bundleGUID))
|
||||
@@ -125,18 +121,13 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 创建输出目录
|
||||
string fullPath = YooAssetSettingsData.GetYooResourcesFullPath();
|
||||
string fullPath = YooAssetSettingsData.GetYooDefaultBuildinRoot();
|
||||
string saveFilePath = $"{fullPath}/{packageName}/{DefaultBuildinFileSystemDefine.BuildinCatalogFileName}";
|
||||
FileUtility.CreateFileDirectory(saveFilePath);
|
||||
|
||||
// 创建输出文件
|
||||
UnityEditor.AssetDatabase.CreateAsset(buildinFileCatalog, saveFilePath);
|
||||
UnityEditor.EditorUtility.SetDirty(buildinFileCatalog);
|
||||
#if UNITY_2019
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#else
|
||||
UnityEditor.AssetDatabase.SaveAssetIfDirty(buildinFileCatalog);
|
||||
#endif
|
||||
File.WriteAllText(saveFilePath, JsonUtility.ToJson(buildinFileCatalog, false));
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"Succeed to save buildin file catalog : {saveFilePath}");
|
||||
return true;
|
||||
|
||||
@@ -6,6 +6,6 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 内置清单文件名称
|
||||
/// </summary>
|
||||
public const string BuildinCatalogFileName = "BuildinCatalog.asset";
|
||||
public const string BuildinCatalogFileName = "BuildinCatalog.json";
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -8,9 +9,11 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
LoadCatalog,
|
||||
WaitForRequest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private UnityWebRequest _request;
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@@ -28,12 +31,39 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
||||
_request = UnityWebRequest.Get(catalogFilePath);
|
||||
_request.SendWebRequest();
|
||||
_steps = ESteps.WaitForRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.WaitForRequest)
|
||||
{
|
||||
// 等待请求完成
|
||||
if (!_request.isDone)
|
||||
return;
|
||||
|
||||
if (_request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load catalog file: {_request.error}";
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析 JSON
|
||||
string jsonText = _request.downloadHandler.text;
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
|
||||
if (catalog == null)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load catalog file : {catalogFilePath}";
|
||||
@@ -42,6 +72,8 @@ namespace YooAsset
|
||||
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
@@ -55,6 +87,8 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
@@ -333,6 +333,13 @@ namespace YooAsset
|
||||
{
|
||||
return _records.Keys.ToList();
|
||||
}
|
||||
public RecordFileElement GetRecordFileElement(PackageBundle bundle)
|
||||
{
|
||||
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element))
|
||||
return element;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetTempFilePath(PackageBundle bundle)
|
||||
{
|
||||
@@ -384,10 +391,10 @@ namespace YooAsset
|
||||
|
||||
public EFileVerifyResult VerifyCacheFile(PackageBundle bundle)
|
||||
{
|
||||
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement wrapper) == false)
|
||||
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element) == false)
|
||||
return EFileVerifyResult.CacheNotFound;
|
||||
|
||||
EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
|
||||
EFileVerifyResult result = FileVerifyHelper.FileVerify(element.DataFilePath, element.DataFileSize, element.DataFileCRC, EFileVerifyLevel.High);
|
||||
return result;
|
||||
}
|
||||
public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)
|
||||
@@ -427,22 +434,10 @@ namespace YooAsset
|
||||
}
|
||||
public bool DeleteCacheBundleFile(string bundleGUID)
|
||||
{
|
||||
if (_records.TryGetValue(bundleGUID, out RecordFileElement wrapper))
|
||||
if (_records.TryGetValue(bundleGUID, out RecordFileElement element))
|
||||
{
|
||||
try
|
||||
{
|
||||
string dataFilePath = wrapper.DataFilePath;
|
||||
FileInfo fileInfo = new FileInfo(dataFilePath);
|
||||
if (fileInfo.Exists)
|
||||
fileInfo.Directory.Delete(true);
|
||||
_records.Remove(bundleGUID);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
|
||||
return false;
|
||||
}
|
||||
_records.Remove(bundleGUID);
|
||||
return element.DeleteFolder();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RecordFileElement
|
||||
@@ -7,7 +9,7 @@ namespace YooAsset
|
||||
public string DataFilePath { private set; get; }
|
||||
public string DataFileCRC { private set; get; }
|
||||
public long DataFileSize { private set; get; }
|
||||
|
||||
|
||||
public RecordFileElement(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
|
||||
{
|
||||
InfoFilePath = infoFilePath;
|
||||
@@ -15,5 +17,31 @@ namespace YooAsset
|
||||
DataFileCRC = dataFileCRC;
|
||||
DataFileSize = dataFileSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除记录文件
|
||||
/// </summary>
|
||||
public bool DeleteFolder()
|
||||
{
|
||||
try
|
||||
{
|
||||
string directory = Path.GetDirectoryName(InfoFilePath);
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
|
||||
if (directoryInfo.Exists)
|
||||
{
|
||||
directoryInfo.Delete(true);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
@@ -260,9 +261,30 @@ namespace YooAsset
|
||||
{
|
||||
if (_fileSystem.Exists(_bundle))
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadCacheRawBundle;
|
||||
// 注意:缓存的原生文件的格式,可能会在业务端根据需求发生变动!
|
||||
// 注意:这里需要校验文件格式,如果不一致对本地文件进行修正!
|
||||
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var recordFileElement = _fileSystem.GetRecordFileElement(_bundle);
|
||||
File.Move(recordFileElement.DataFilePath, filePath);
|
||||
_steps = ESteps.LoadCacheRawBundle;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Faild rename raw data file : {e.Message}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadCacheRawBundle;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -7,9 +7,10 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckManifest,
|
||||
CheckArgs,
|
||||
GetTagsCacheFiles,
|
||||
ClearTagsCacheFiles,
|
||||
GetClearCacheFiles,
|
||||
ClearFilterCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -29,13 +30,27 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckArgs;
|
||||
_steps = ESteps.CheckManifest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckManifest)
|
||||
{
|
||||
if (_manifest == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckArgs;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckArgs)
|
||||
{
|
||||
if (_clearParam == null)
|
||||
@@ -67,17 +82,17 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.GetTagsCacheFiles;
|
||||
_steps = ESteps.GetClearCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.GetTagsCacheFiles)
|
||||
if (_steps == ESteps.GetClearCacheFiles)
|
||||
{
|
||||
_clearBundleGUIDs = GetTagsBundleGUIDs();
|
||||
_clearBundleGUIDs = GetBundleGUIDsByTag();
|
||||
_clearFileTotalCount = _clearBundleGUIDs.Count;
|
||||
_steps = ESteps.ClearTagsCacheFiles;
|
||||
_steps = ESteps.ClearFilterCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearTagsCacheFiles)
|
||||
if (_steps == ESteps.ClearFilterCacheFiles)
|
||||
{
|
||||
for (int i = _clearBundleGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -100,7 +115,7 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
private List<string> GetTagsBundleGUIDs()
|
||||
private List<string> GetBundleGUIDsByTag()
|
||||
{
|
||||
var allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
|
||||
List<string> result = new List<string>(allBundleGUIDs.Count);
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckManifest,
|
||||
GetUnusedCacheFiles,
|
||||
ClearUnusedCacheFiles,
|
||||
Done,
|
||||
@@ -19,7 +20,7 @@ namespace YooAsset
|
||||
private int _unusedFileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
|
||||
internal ClearUnusedCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
@@ -27,15 +28,29 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.GetUnusedCacheFiles;
|
||||
_steps = ESteps.CheckManifest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckManifest)
|
||||
{
|
||||
if (_manifest == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.GetUnusedCacheFiles;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.GetUnusedCacheFiles)
|
||||
{
|
||||
{
|
||||
_unusedBundleGUIDs = GetUnusedBundleGUIDs();
|
||||
_unusedFileTotalCount = _unusedBundleGUIDs.Count;
|
||||
_steps = ESteps.ClearUnusedCacheFiles;
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckManifest,
|
||||
ClearUnusedCacheFiles,
|
||||
Done,
|
||||
}
|
||||
@@ -24,13 +25,27 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.ClearUnusedCacheFiles;
|
||||
_steps = ESteps.CheckManifest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckManifest)
|
||||
{
|
||||
if (_manifest == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.ClearUnusedCacheFiles;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearUnusedCacheFiles)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -92,12 +92,7 @@ namespace YooAsset
|
||||
if (_fileSystem.AppendFileExtension)
|
||||
{
|
||||
string dataFileExtension = FindDataFileExtension(chidDirectory);
|
||||
if (string.IsNullOrEmpty(dataFileExtension))
|
||||
{
|
||||
//注意:覆盖安装的情况下,缓存文件可能会没有后缀格式,需要删除重新下载!
|
||||
dataFilePath = string.Empty;
|
||||
}
|
||||
else
|
||||
if (string.IsNullOrEmpty(dataFileExtension) == false)
|
||||
{
|
||||
dataFilePath += dataFileExtension;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -12,9 +13,11 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
LoadCatalog,
|
||||
WaitForRequest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private UnityWebRequest _request;
|
||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@@ -36,12 +39,39 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
|
||||
if (_steps == ESteps.LoadCatalog)
|
||||
{
|
||||
string catalogFilePath = _fileSystem.GetCatalogFileLoadPath();
|
||||
var catalog = Resources.Load<DefaultBuildinFileCatalog>(catalogFilePath);
|
||||
_request = UnityWebRequest.Get(catalogFilePath);
|
||||
_request.SendWebRequest();
|
||||
_steps = ESteps.WaitForRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.WaitForRequest)
|
||||
{
|
||||
// 等待请求完成
|
||||
if (!_request.isDone)
|
||||
return;
|
||||
|
||||
if (_request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load web server catalog file: {_request.error}";
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析 JSON
|
||||
string jsonText = _request.downloadHandler.text;
|
||||
var catalog = JsonUtility.FromJson<DefaultBuildinFileCatalog>(jsonText);
|
||||
if (catalog == null)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load web server catalog file : {catalogFilePath}";
|
||||
@@ -50,6 +80,8 @@ namespace YooAsset
|
||||
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Web server catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
@@ -64,6 +96,8 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
|
||||
_request.Dispose();
|
||||
_request = null;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace YooAsset
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
DebugCheckInitialize(false);
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
@@ -276,7 +276,7 @@ namespace YooAsset
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
DebugCheckInitialize(false);
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
|
||||
@@ -220,6 +220,26 @@ namespace YooAsset
|
||||
else
|
||||
return PathUtility.Combine(Application.streamingAssetsPath, Setting.DefaultYooFolderName);
|
||||
}
|
||||
|
||||
internal static string GetRequestYooDefaultBuildinRoot()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Setting.DefaultYooFolderName))
|
||||
return GetRequestStreamingAssetsPath();
|
||||
else
|
||||
return PathUtility.Combine(GetRequestStreamingAssetsPath(), Setting.DefaultYooFolderName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取UnityWebRequest StreamingAssets的路径 (OSX and iOS 需要加 file://)
|
||||
/// </summary>
|
||||
internal static string GetRequestStreamingAssetsPath()
|
||||
{
|
||||
#if UNITY_STANDALONE_OSX || UNITY_IOS
|
||||
return $"file://{Application.streamingAssetsPath}";
|
||||
#else
|
||||
return Application.streamingAssetsPath;
|
||||
#endif
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "2.3.4-preview",
|
||||
"version": "2.3.5-preview",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user