Compare commits

..

2 Commits
mlyDev ... main

Author SHA1 Message Date
hevinci dc33abde46 update asset system 2023-06-16 15:01:13 +08:00
hevinci aae7b08dd1 update space shooter 2023-06-16 14:10:33 +08:00
13 changed files with 36 additions and 264 deletions

View File

@ -79,6 +79,30 @@ 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>
@ -125,12 +149,10 @@ 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}"); YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}");
CacheSystem.DiscardFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID); CacheSystem.DiscardFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID);
} }
} }

View File

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

View File

@ -1,90 +0,0 @@
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

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

View File

@ -121,28 +121,5 @@ 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,68 +344,5 @@ 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,19 +131,5 @@ 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.ForceUnloadAllAssets(); _assetSystemImpl.DestroyAll();
_assetSystemImpl = null; _assetSystemImpl = null;
} }
} }
@ -839,46 +839,5 @@ 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,6 +1,4 @@
 
using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal interface IPlayModeServices internal interface IPlayModeServices
@ -38,8 +36,5 @@ 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,21 +414,5 @@ 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,6 +23,13 @@ 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>
@ -49,6 +56,7 @@ 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.16005", "version": "1.4.16",
"unity": "2019.4", "unity": "2019.4",
"description": "unity3d resources management system.", "description": "unity3d resources management system.",
"author": { "author": {