Compare commits

...

8 Commits

Author SHA1 Message Date
何冠峰 ce023cedb8 update extension sample 2025-02-11 15:13:45 +08:00
何冠峰 3d1a28a50e update file system 2025-02-11 15:09:23 +08:00
何冠峰 5d2d0b4168 fix #341 2025-02-11 10:20:33 +08:00
何冠峰 fa985a5a93 Merge branch 'dev' of https://github.com/tuyoogame/YooAsset into dev 2025-02-11 09:55:38 +08:00
何冠峰 40f9937b60 update space shooter 2025-02-11 09:55:37 +08:00
何冠峰 c543c629c3
Merge pull request #466 from suxf/dev
fix:微信小游戏缓存文件系统查询机制不生效
2025-02-11 09:43:16 +08:00
枫似锦 0a96e583d3 Merge branch 'dev' of https://github.com/suxf/YooAsset into dev 2025-02-10 16:39:31 +08:00
枫似锦 c9d263c60d fix:微信小游戏缓存文件系统查询机制不生效 2025-02-10 16:38:23 +08:00
9 changed files with 62 additions and 51 deletions

View File

@ -21,7 +21,7 @@ namespace YooAsset
}
protected readonly Dictionary<string, FileWrapper> _wrappers = new Dictionary<string, FileWrapper>(10000);
protected readonly Dictionary<string, string> _buildinFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _buildinFilePathMapping = new Dictionary<string, string>(10000);
protected IFileSystem _unpackFileSystem;
protected string _packageRoot;
@ -309,10 +309,10 @@ namespace YooAsset
}
public string GetBuildinFileLoadPath(PackageBundle bundle)
{
if (_buildinFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
if (_buildinFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_packageRoot, bundle.FileName);
_buildinFilePaths.Add(bundle.BundleGUID, filePath);
_buildinFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}

View File

@ -11,10 +11,10 @@ namespace YooAsset
/// </summary>
internal class DefaultCacheFileSystem : IFileSystem
{
protected readonly Dictionary<string, RecordFileElement> _wrappers = new Dictionary<string, RecordFileElement>(10000);
protected readonly Dictionary<string, string> _bundleDataFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _bundleInfoFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _tempFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, RecordFileElement> _records = new Dictionary<string, RecordFileElement>(10000);
protected readonly Dictionary<string, string> _bundleDataFilePathMapping = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _bundleInfoFilePathMapping = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _tempFilePathMapping = new Dictionary<string, string>(10000);
protected DefaultCacheDownloadCenter _downloadCenter;
protected string _packageRoot;
@ -45,7 +45,7 @@ namespace YooAsset
{
get
{
return _wrappers.Count;
return _records.Count;
}
}
@ -245,7 +245,7 @@ namespace YooAsset
}
public virtual bool Exists(PackageBundle bundle)
{
return _wrappers.ContainsKey(bundle.BundleGUID);
return _records.ContainsKey(bundle.BundleGUID);
}
public virtual bool NeedDownload(PackageBundle bundle)
{
@ -330,60 +330,60 @@ namespace YooAsset
#region 缓存相关
public List<string> GetAllCachedBundleGUIDs()
{
return _wrappers.Keys.ToList();
return _records.Keys.ToList();
}
public string GetTempFilePath(PackageBundle bundle)
{
if (_tempFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
if (_tempFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_tempFilesRoot, bundle.BundleGUID);
_tempFilePaths.Add(bundle.BundleGUID, filePath);
_tempFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetBundleDataFilePath(PackageBundle bundle)
{
if (_bundleDataFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
if (_bundleDataFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheBundleFilesRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.BundleDataFileName);
if (AppendFileExtension)
filePath += bundle.FileExtension;
_bundleDataFilePaths.Add(bundle.BundleGUID, filePath);
_bundleDataFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetBundleInfoFilePath(PackageBundle bundle)
{
if (_bundleInfoFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
if (_bundleInfoFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheBundleFilesRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.BundleInfoFileName);
_bundleInfoFilePaths.Add(bundle.BundleGUID, filePath);
_bundleInfoFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public bool IsRecordBundleFile(string bundleGUID)
{
return _wrappers.ContainsKey(bundleGUID);
return _records.ContainsKey(bundleGUID);
}
public bool RecordBundleFile(string bundleGUID, RecordFileElement element)
{
if (_wrappers.ContainsKey(bundleGUID))
if (_records.ContainsKey(bundleGUID))
{
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has element : {bundleGUID}");
return false;
}
_wrappers.Add(bundleGUID, element);
_records.Add(bundleGUID, element);
return true;
}
public EFileVerifyResult VerifyCacheFile(PackageBundle bundle)
{
if (_wrappers.TryGetValue(bundle.BundleGUID, out RecordFileElement wrapper) == false)
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement wrapper) == false)
return EFileVerifyResult.CacheNotFound;
EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
@ -391,7 +391,7 @@ namespace YooAsset
}
public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)
{
if (_wrappers.ContainsKey(bundle.BundleGUID))
if (_records.ContainsKey(bundle.BundleGUID))
{
throw new Exception("Should never get here !");
}
@ -426,7 +426,7 @@ namespace YooAsset
}
public bool DeleteCacheBundleFile(string bundleGUID)
{
if (_wrappers.TryGetValue(bundleGUID, out RecordFileElement wrapper))
if (_records.TryGetValue(bundleGUID, out RecordFileElement wrapper))
{
try
{
@ -434,7 +434,7 @@ namespace YooAsset
FileInfo fileInfo = new FileInfo(dataFilePath);
if (fileInfo.Exists)
fileInfo.Directory.Delete(true);
_wrappers.Remove(bundleGUID);
_records.Remove(bundleGUID);
return true;
}
catch (Exception e)

View File

@ -21,7 +21,7 @@ namespace YooAsset
}
protected readonly Dictionary<string, FileWrapper> _wrappers = new Dictionary<string, FileWrapper>(10000);
protected readonly Dictionary<string, string> _webFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _webFilePathMapping = new Dictionary<string, string>(10000);
protected string _webPackageRoot = string.Empty;
/// <summary>
@ -173,10 +173,10 @@ namespace YooAsset
}
public string GetWebFileLoadPath(PackageBundle bundle)
{
if (_webFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
if (_webFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_webPackageRoot, bundle.FileName);
_webFilePaths.Add(bundle.BundleGUID, filePath);
_webFilePathMapping.Add(bundle.BundleGUID, filePath);
}
return filePath;
}

View File

@ -20,7 +20,7 @@ namespace YooAsset
/// <summary>
/// 初始化缓存系统
/// 初始化文件系统
/// </summary>
FSInitializeFileSystemOperation InitializeFileSystemAsync();
@ -30,7 +30,7 @@ namespace YooAsset
FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout);
/// <summary>
/// 查询最新的版本
/// 查询包裹版本
/// </summary>
FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout);
@ -40,7 +40,7 @@ namespace YooAsset
FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam);
/// <summary>
/// 下载远端文件
/// 下载Bundle文件
/// </summary>
FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param);

View File

@ -52,6 +52,12 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
_fileSystem.TryRecordBundle(Bundle); //记录下载文件
//TODO 解决微信小游戏插件问题
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
DownloadProgress = 1f;
DownloadedBytes = Bundle.FileSize;
Progress = 1f;
}
else
{

View File

@ -62,6 +62,12 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
Status = EOperationStatus.Succeed;
_fileSystem.TryRecordBundle(_bundle); //记录下载文件
//TODO 解决微信小游戏插件问题
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
Progress = 1f;
}
}
else

View File

@ -34,24 +34,26 @@ internal class RecordWechatCacheFilesOperation : AsyncOperationBase
_steps = ESteps.WaitResponse;
var fileSystemMgr = _fileSystem.GetFileSystemMgr();
var getSavedFileListOption = new GetSavedFileListOption();
getSavedFileListOption.success = (GetSavedFileListSuccessCallbackResult response) =>
var statOption = new WXStatOption();
statOption.path = _fileSystem.FileRoot;
statOption.recursive = true;
statOption.success = (WXStatResponse response) =>
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
foreach (var fileInfo in response.fileList)
foreach (var fileStat in response.stats)
{
//TODO 需要确认存储文件为Bundle文件
_fileSystem.RecordBundleFile(fileInfo.filePath);
_fileSystem.RecordBundleFile(_fileSystem.FileRoot + fileStat.path);
}
};
getSavedFileListOption.fail = (FileError fileError) =>
statOption.fail = (WXStatResponse response) =>
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = fileError.errMsg;
Error = response.errMsg;
};
fileSystemMgr.GetSavedFileList(getSavedFileListOption);
fileSystemMgr.Stat(statOption);
}
}
}

View File

@ -62,6 +62,8 @@ internal class WechatFileSystem : IFileSystem
/// 包裹名称
/// </summary>
public string PackageName { private set; get; }
private readonly string _packageRoot = YooAssetSettingsData.Setting.DefaultYooFolderName;
/// <summary>
/// 文件根目录
@ -255,7 +257,7 @@ internal class WechatFileSystem : IFileSystem
{
if (_cacheFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_wxCacheRoot, bundle.FileName);
filePath = PathUtility.Combine(_wxCacheRoot, "__GAME_FILE_CACHE", _packageRoot, bundle.FileName);
_cacheFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;

View File

@ -1,14 +1,12 @@
using System.Collections;
#if UNITY_2019_4_OR_NEWER
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using YooAsset.Editor;
#if UNITY_2019_4_OR_NEWER
using UnityEditor.UIElements;
using UnityEngine.UIElements;
#endif
[CreateAssetMenu(fileName = "TextureSchema", menuName = "YooAssetArt/Create TextureSchema")]
public class TextureSchema : ScannerSchema
@ -37,9 +35,9 @@ public class TextureSchema : ScannerSchema
public override ScanReport RunScanner(AssetArtScanner scanner)
{
// 创建扫描报告
string title = "扫描所有纹理资产";
string name = "扫描所有纹理资产";
string desc = GetUserGuide();
var report = new ScanReport(title, desc);
var report = new ScanReport(name, desc);
report.AddHeader("资源路径", 600, 500, 1000).SetStretchable().SetSearchable().SetSortable().SetHeaderType(EHeaderType.AssetPath);
report.AddHeader("图片宽度", 100).SetSortable().SetHeaderType(EHeaderType.LongValue);
report.AddHeader("图片高度", 100).SetSortable().SetHeaderType(EHeaderType.LongValue);
@ -105,9 +103,9 @@ public class TextureSchema : ScannerSchema
// 添加扫描信息
ReportElement result = new ReportElement(assetGUID);
result.AddScanInfo("资源路径", assetPath);
result.AddScanInfo("图片宽度", texture.width.ToString());
result.AddScanInfo("图片高度", texture.height.ToString());
result.AddScanInfo("内存大小", memorySize.ToString());
result.AddScanInfo("图片宽度", texture.width);
result.AddScanInfo("图片高度", texture.height);
result.AddScanInfo("内存大小", memorySize);
result.AddScanInfo("苹果格式", iosFormat.ToString());
result.AddScanInfo("安卓格式", androidFormat.ToString());
result.AddScanInfo("错误信息", errorInfo);
@ -157,7 +155,6 @@ public class TextureSchema : ScannerSchema
/// </summary>
public override SchemaInspector CreateInspector()
{
#if UNITY_2019_4_OR_NEWER
var container = new VisualElement();
// 图片最大宽度
@ -183,8 +180,6 @@ public class TextureSchema : ScannerSchema
SchemaInspector inspector = new SchemaInspector();
inspector.Containner = container;
return inspector;
#else
return null;
#endif
}
}
}
#endif