Compare commits

..

11 Commits
main ... mlyDev

Author SHA1 Message Date
Nocye db81ba8d67 update 版本号 2023-07-18 16:32:50 +08:00
hevinci dc5086a644 update asset system
修复了在销毁Package时,如果存在正在加载的bundle,会导致后续加载该bundle报错的问题。
2023-07-18 16:26:20 +08:00
Nocye 92e385bd73 update 版本号 2023-06-25 11:26:06 +08:00
Nocye 340a69b251 fix 修复tag没计算的问题 2023-06-22 20:16:35 +08:00
Nocye 6f3198a2e1 update 更新版本号 2023-06-22 20:06:11 +08:00
Nocye 79a9763555 update 添加一个方法,获取还没下载的带tag原生文件的列表 2023-06-22 20:04:23 +08:00
Nocye fa111f8d93 update 修改版本号测试 2023-06-21 11:27:41 +08:00
Nocye 693711c23b update 版本号 2023-06-20 22:57:45 +08:00
Nocye fc2ea03a5e update 版本号 2023-06-20 22:54:39 +08:00
Nocye 374feaf82d update init检测 2023-06-20 21:15:03 +08:00
Nocye 92cba88853 add 添加更灵活的操作tag和原生文件的方法 2023-06-20 16:49:28 +08:00
13 changed files with 264 additions and 36 deletions

View File

@ -79,30 +79,6 @@ namespace YooAsset
_isUnloadSafe = true; _isUnloadSafe = true;
} }
/// <summary>
/// 销毁
/// </summary>
public void DestroyAll()
{
foreach (var provider in _providerList)
{
provider.Destroy();
}
_providerList.Clear();
_providerDic.Clear();
foreach (var loader in _loaderList)
{
loader.Destroy(true);
}
_loaderList.Clear();
_loaderDic.Clear();
ClearSceneHandle();
DecryptionServices = null;
BundleServices = null;
}
/// <summary> /// <summary>
/// 资源回收(卸载引用计数为零的资源) /// 资源回收(卸载引用计数为零的资源)
/// </summary> /// </summary>
@ -149,10 +125,12 @@ namespace YooAsset
{ {
foreach (var provider in _providerList) foreach (var provider in _providerList)
{ {
provider.WaitForAsyncComplete();
provider.Destroy(); provider.Destroy();
} }
foreach (var loader in _loaderList) foreach (var loader in _loaderList)
{ {
loader.WaitForAsyncComplete();
loader.Destroy(true); loader.Destroy(true);
} }

View File

@ -246,7 +246,7 @@ namespace YooAsset
var result = CacheSystem.VerifyingRecordFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID); var result = CacheSystem.VerifyingRecordFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID);
if (result != EVerifyResult.Succeed) if (result != EVerifyResult.Succeed)
{ {
YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}"); YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID}");
CacheSystem.DiscardFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID); CacheSystem.DiscardFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID);
} }
} }

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c9fd0b949af8480fa2e882cf65f7b01b
timeCreated: 1687234632

View File

@ -0,0 +1,90 @@
using System.Collections.Generic;
namespace YooAsset
{
public class ClearTagsCachedRawFilesOperation : AsyncOperationBase
{
private enum ESteps
{
None,
GetCacheFiles,
ClearCacheFiles,
Done
}
private ESteps steps;
private List<PackageBundle> cachedBundles;
private ResourcePackage package;
private string[] tags;
private int clearTotalCount;
internal ClearTagsCachedRawFilesOperation(ResourcePackage package, string[] tags)
{
this.package = package;
this.tags = tags;
}
internal override void Start()
{
steps = ESteps.GetCacheFiles;
}
internal override void Update()
{
if (steps == ESteps.None || steps == ESteps.Done)
{
return;
}
if (steps == ESteps.GetCacheFiles)
{
var bundles = package.GetCachedTagsRawFiles(tags);
cachedBundles = new List<PackageBundle>();
foreach (PackageBundle b in bundles)
{
if (!b.IsRawFile)
{
continue;
}
if (CacheSystem.IsCached(b.PackageName, b.CacheGUID))
{
cachedBundles.Add(b);
}
}
clearTotalCount = cachedBundles.Count;
steps = ESteps.ClearCacheFiles;
}
if (steps == ESteps.ClearCacheFiles)
{
for (var i = cachedBundles.Count - 1; i >= 0; i--)
{
var b = cachedBundles[i];
CacheSystem.DiscardFile(b.PackageName, b.CacheGUID);
cachedBundles.RemoveAt(i);
if (OperationSystem.IsBusy)
{
break;
}
}
if (clearTotalCount == 0)
{
Progress = 1f;
}
else
{
Progress = 1f - (1f * cachedBundles.Count / clearTotalCount);
}
if (cachedBundles.Count == 0)
{
steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 93d20d548161467fb47833ab204f4651
timeCreated: 1687235010

View File

@ -121,5 +121,28 @@ namespace YooAsset
return _activeManifest != null; return _activeManifest != null;
} }
#endregion #endregion
#region MLY
public List<PackageBundle> GetCachedTagsRawFiles(string[] tags)
{
List<PackageBundle> result = new List<PackageBundle>(1000);
foreach (PackageBundle b in _activeManifest.BundleList)
{
if (b.HasTag(tags))
{
result.Add(b);
}
}
return result;
}
public List<PackageBundle> GetNeedDownloadTagsRawFiles(string[] tags)
{
return new List<PackageBundle>();
}
#endregion
} }
} }

View File

@ -344,5 +344,68 @@ namespace YooAsset
return _activeManifest != null; return _activeManifest != null;
} }
#endregion #endregion
#region MLY修改
public List<PackageBundle> GetCachedTagsRawFiles(string[] tags)
{
return GetCachedTagsBundle(_activeManifest, tags);
}
public List<PackageBundle> GetCachedTagsBundle(PackageManifest manifest,string[] tags)
{
List<PackageBundle> result = new List<PackageBundle>(1000);
foreach (PackageBundle b in manifest.BundleList)
{
if (IsBuildinPackageBundle(b))
{
continue;
}
if (!b.IsRawFile)
{
continue;
}
if (IsCachedPackageBundle(b))
{
if (b.HasTag(tags))
{
result.Add(b);
}
}
}
return result;
}
public List<PackageBundle> GetNeedDownloadTagsRawFiles(string[] tags)
{
List<PackageBundle> neetDownloadList = new List<PackageBundle>(200);
foreach (PackageBundle bundle in _activeManifest.BundleList)
{
if (IsCachedPackageBundle(bundle))
{
continue;
}
if (IsBuildinPackageBundle(bundle))
{
continue;
}
if (!bundle.HasAnyTags())
{
continue;
}
if (bundle.HasTag(tags))
{
neetDownloadList.Add(bundle);
}
}
return neetDownloadList;
}
#endregion
} }
} }

View File

@ -131,5 +131,19 @@ namespace YooAsset
return _activeManifest != null; return _activeManifest != null;
} }
#endregion #endregion
#region MLy
public List<PackageBundle> GetCachedTagsRawFiles(string[] tags)
{
return new List<PackageBundle>();
}
public List<PackageBundle> GetNeedDownloadTagsRawFiles(string[] tags)
{
return new List<PackageBundle>();
}
#endregion
} }
} }

View File

@ -62,7 +62,7 @@ namespace YooAsset
if (_assetSystemImpl != null) if (_assetSystemImpl != null)
{ {
_assetSystemImpl.DestroyAll(); _assetSystemImpl.ForceUnloadAllAssets();
_assetSystemImpl = null; _assetSystemImpl = null;
} }
} }
@ -839,5 +839,46 @@ namespace YooAsset
return data; return data;
} }
#endregion #endregion
#region MLY扩展
public long GetCachedTagsRawFileSize(string[] tags)
{
DebugCheckInitialize();
var list = _playModeServices.GetCachedTagsRawFiles(tags);
long size = 0;
for (var i = 0; i < list.Count; i++)
{
size += list[i].FileSize;
}
return size;
}
internal List<PackageBundle> GetCachedTagsRawFiles(string[] tags)
{
DebugCheckInitialize();
return _playModeServices.GetCachedTagsRawFiles(tags);
}
public ClearTagsCachedRawFilesOperation ClearTagsCacheFilesAsync(string[] tags)
{
DebugCheckInitialize();
var operation = new ClearTagsCachedRawFilesOperation(this,tags);
OperationSystem.StartOperation(operation);
return operation;
}
public long GetNeedDownloadTagsRawFileSize(string[] tags)
{
DebugCheckInitialize();
var list=_playModeServices.GetNeedDownloadTagsRawFiles(tags);
long size = 0;
foreach (PackageBundle packageBundle in list)
{
size += packageBundle.FileSize;
}
return size;
}
#endregion
} }
} }

View File

@ -1,4 +1,6 @@
 
using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal interface IPlayModeServices internal interface IPlayModeServices
@ -36,5 +38,8 @@ namespace YooAsset
// 解压相关 // 解压相关
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout); ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout);
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout); ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout);
List<PackageBundle> GetCachedTagsRawFiles(string[] tags);
List<PackageBundle> GetNeedDownloadTagsRawFiles(string[] tags);
} }
} }

View File

@ -414,5 +414,21 @@ namespace YooAsset
throw new Exception($"Default package is null. Please use {nameof(YooAssets.SetDefaultPackage)} !"); throw new Exception($"Default package is null. Please use {nameof(YooAssets.SetDefaultPackage)} !");
} }
#endregion #endregion
#region MLY
public static long GetCachedTagsRawFileSize(string[] tags)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetCachedTagsRawFileSize(tags);
}
public static ClearTagsCachedRawFilesOperation ClearTagsCacheRawFilesAsync(string[] tags)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.ClearTagsCacheFilesAsync(tags);
}
#endregion
} }
} }

View File

@ -23,13 +23,6 @@ public sealed class StreamingAssetsHelper
private static bool _isInit = false; private static bool _isInit = false;
private static readonly HashSet<string> _cacheData = new HashSet<string>(); private static readonly HashSet<string> _cacheData = new HashSet<string>();
#if UNITY_EDITOR
public static void Init() { _isInit = true; }
public static bool FileExists(string fileName)
{
return File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, "BuildinFiles", fileName));
}
#else
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
@ -56,7 +49,6 @@ public sealed class StreamingAssetsHelper
return _cacheData.Contains(fileName); return _cacheData.Contains(fileName);
} }
#endif
} }
#if UNITY_EDITOR #if UNITY_EDITOR

View File

@ -1,7 +1,7 @@
{ {
"name": "com.tuyoogame.yooasset", "name": "com.tuyoogame.yooasset",
"displayName": "YooAsset", "displayName": "YooAsset",
"version": "1.4.16", "version": "1.4.16005",
"unity": "2019.4", "unity": "2019.4",
"description": "unity3d resources management system.", "description": "unity3d resources management system.",
"author": { "author": {