add 添加更灵活的操作tag和原生文件的方法

mlyDev
Nocye 2023-06-20 16:49:28 +08:00
parent f70582af1a
commit 92cba88853
9 changed files with 204 additions and 1 deletions

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,23 @@ 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;
}
#endregion
} }
} }

View File

@ -344,5 +344,39 @@ 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;
}
#endregion
} }
} }

View File

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

View File

@ -839,5 +839,31 @@ namespace YooAsset
return data; return data;
} }
#endregion #endregion
#region MLY扩展
public long GetCachedTagsRawFileSize(string[] tags)
{
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)
{
return _playModeServices.GetCachedTagsRawFiles(tags);
}
public ClearTagsCachedRawFilesOperation ClearTagsCacheFilesAsync(string[] tags)
{
DebugCheckInitialize();
var operation = new ClearTagsCachedRawFilesOperation(this,tags);
OperationSystem.StartOperation(operation);
return operation;
}
#endregion
} }
} }

View File

@ -1,4 +1,6 @@
 
using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal interface IPlayModeServices internal interface IPlayModeServices
@ -36,5 +38,7 @@ 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);
} }
} }

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
} }
} }