mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-15 20:20:08 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd0a6579b8 | ||
|
|
18c2e232cf | ||
|
|
ad680638ac | ||
|
|
0764061d8f | ||
|
|
d448026250 | ||
|
|
34f553b9e3 | ||
|
|
25d1e32ce9 | ||
|
|
8686c32ada | ||
|
|
f043c6710a | ||
|
|
acd27e36fa | ||
|
|
37f0d1e5a1 | ||
|
|
e6397559ff | ||
|
|
812c46adeb | ||
|
|
4d7fb6301a | ||
|
|
f0951f2a25 | ||
|
|
7d2defedb7 | ||
|
|
17ab618bed | ||
|
|
0f9e932616 |
@@ -2,6 +2,50 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.4.14] - 2023-05-26
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了收集器对着色器未过滤的问题。
|
||||
- 修复了内置着色器Tag特殊情况下未正确传染给依赖资源包的问题。
|
||||
|
||||
### Changed
|
||||
|
||||
- Unity2021版本及以上推荐使用可编程构建管线(SBP)
|
||||
|
||||
## [1.4.13] - 2023-05-12
|
||||
|
||||
### Changed
|
||||
|
||||
- 可寻址地址冲突时,打印冲突地址的资源路径。
|
||||
- 销毁Package的时候清空该Package的缓存记录。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增方法ResoucePackage.ClearAllCacheFilesAsync()
|
||||
|
||||
```c#
|
||||
public class ResoucePackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理包裹本地所有的缓存文件
|
||||
/// </summary>
|
||||
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync();
|
||||
}
|
||||
```
|
||||
|
||||
- 新增方法YooAssets.SetCacheSystemSandboxPath()
|
||||
|
||||
```c#
|
||||
public class YooAssets
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置缓存系统参数,沙盒目录的存储路径
|
||||
/// </summary>
|
||||
public static void SetCacheSystemSandboxPath(string sandboxPath);
|
||||
}
|
||||
```
|
||||
|
||||
## [1.4.12] - 2023-04-22
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -205,6 +205,7 @@ namespace YooAsset.Editor
|
||||
throw new Exception("没有发现着色器资源包!");
|
||||
|
||||
// 检测依赖交集并更新依赖ID
|
||||
HashSet<string> tagTemps = new HashSet<string>();
|
||||
foreach (var packageAsset in manifest.AssetList)
|
||||
{
|
||||
List<string> dependBundles = GetPackageAssetAllDependBundles(manifest, packageAsset);
|
||||
@@ -215,8 +216,23 @@ namespace YooAsset.Editor
|
||||
if (newDependIDs.Contains(shaderBundleId) == false)
|
||||
newDependIDs.Add(shaderBundleId);
|
||||
packageAsset.DependIDs = newDependIDs.ToArray();
|
||||
foreach (var tag in packageAsset.AssetTags)
|
||||
{
|
||||
if (tagTemps.Contains(tag) == false)
|
||||
tagTemps.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新资源包标签
|
||||
var packageBundle = manifest.BundleList[shaderBundleId];
|
||||
List<string> newTags = new List<string>(packageBundle.Tags);
|
||||
foreach (var tag in tagTemps)
|
||||
{
|
||||
if (newTags.Contains(tag) == false)
|
||||
newTags.Add(tag);
|
||||
}
|
||||
packageBundle.Tags = newTags.ToArray();
|
||||
}
|
||||
private List<string> GetPackageAssetAllDependBundles(PackageManifest manifest, PackageAsset packageAsset)
|
||||
{
|
||||
@@ -302,7 +318,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (packageBundle.IsRawFile)
|
||||
{
|
||||
_cachedBundleDepends.Add(packageBundle.BundleName, new string[] { } );
|
||||
_cachedBundleDepends.Add(packageBundle.BundleName, new string[] { });
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -321,7 +337,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
}
|
||||
|
||||
|
||||
private int[] GetBundleRefrenceIDs(PackageManifest manifest, PackageBundle targetBundle)
|
||||
{
|
||||
List<string> referenceList = new List<string>();
|
||||
|
||||
@@ -24,6 +24,13 @@ namespace YooAsset.Editor
|
||||
|
||||
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||
{
|
||||
BuildLogger.Warning("推荐使用可编程构建管线(SBP)!");
|
||||
}
|
||||
#endif
|
||||
|
||||
// 检测当前是否正在构建资源包
|
||||
if (BuildPipeline.isBuildingPlayer)
|
||||
throw new Exception("当前正在构建资源包,请结束后再试");
|
||||
|
||||
@@ -197,16 +197,17 @@ namespace YooAsset.Editor
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
HashSet<string> adressTemper = new HashSet<string>();
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
if (adressTemper.Contains(address) == false)
|
||||
adressTemper.Add(address);
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} in collector : {CollectPath}");
|
||||
throw new Exception($"The address is existed : {address} in collector : {CollectPath} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,10 +290,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private bool IsCollectAsset(string assetPath)
|
||||
{
|
||||
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
return true;
|
||||
|
||||
// 根据规则设置过滤资源文件
|
||||
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
|
||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath));
|
||||
|
||||
@@ -96,16 +96,17 @@ namespace YooAsset.Editor
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
HashSet<string> adressTemper = new HashSet<string>();
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
if (adressTemper.Contains(address) == false)
|
||||
adressTemper.Add(address);
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address} in group : {GroupName}");
|
||||
throw new Exception($"The address is existed : {address} in group : {GroupName} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,16 +76,17 @@ namespace YooAsset.Editor
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
HashSet<string> adressTemper = new HashSet<string>();
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
if (adressTemper.Contains(address) == false)
|
||||
adressTemper.Add(address);
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
throw new Exception($"The address is existed : {address}");
|
||||
throw new Exception($"The address is existed : {address} \nAssetPath:\n {existed}\n {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +112,6 @@ namespace YooAsset
|
||||
var retObject = assetObject as TObject;
|
||||
if (retObject != null)
|
||||
ret.Add(retObject);
|
||||
else
|
||||
YooLogger.Warning($"The type conversion failed : {assetObject.name}");
|
||||
}
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
return; //下载完毕等待一帧再去加载!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadCacheFile;
|
||||
return; //下载完毕等待一帧再去加载!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,15 @@ namespace YooAsset
|
||||
_cachedDic.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空指定包裹的所有缓存数据
|
||||
/// </summary>
|
||||
public static void ClearPackage(string packageName)
|
||||
{
|
||||
var cache = GetOrCreateCache(packageName);
|
||||
cache.ClearAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存文件总数
|
||||
/// </summary>
|
||||
@@ -115,7 +124,7 @@ namespace YooAsset
|
||||
{
|
||||
return VerifyingInternal(element.TempDataFilePath, element.FileSize, element.FileCRC, EVerifyLevel.High);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 验证记录文件(主线程内操作)
|
||||
/// </summary>
|
||||
@@ -148,6 +157,14 @@ namespace YooAsset
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的缓存文件
|
||||
/// </summary>
|
||||
public static List<string> GetAllCacheGUIDs(ResourcePackage package)
|
||||
{
|
||||
var cache = GetOrCreateCache(package.PackageName);
|
||||
return cache.GetAllKeys();
|
||||
}
|
||||
|
||||
private static EVerifyResult VerifyingInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理本地包裹所有的缓存文件
|
||||
/// </summary>
|
||||
public sealed class ClearAllCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetAllCacheFiles,
|
||||
ClearAllCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ResourcePackage _package;
|
||||
private List<string> _allCacheGUIDs;
|
||||
private int _fileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearAllCacheFilesOperation(ResourcePackage package)
|
||||
{
|
||||
_package = package;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.GetAllCacheFiles;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetAllCacheFiles)
|
||||
{
|
||||
_allCacheGUIDs = CacheSystem.GetAllCacheGUIDs(_package);
|
||||
_fileTotalCount = _allCacheGUIDs.Count;
|
||||
YooLogger.Log($"Found all cache file count : {_fileTotalCount}");
|
||||
_steps = ESteps.ClearAllCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearAllCacheFiles)
|
||||
{
|
||||
for (int i = _allCacheGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string cacheGUID = _allCacheGUIDs[i];
|
||||
CacheSystem.DiscardFile(_package.PackageName, cacheGUID);
|
||||
_allCacheGUIDs.RemoveAt(i);
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_fileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_allCacheGUIDs.Count / _fileTotalCount);
|
||||
|
||||
if (_allCacheGUIDs.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bfd05221983858429246096617dff1d
|
||||
guid: 4eb0b0eafee709d478ab6d81faacb304
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
{
|
||||
// BundleFiles
|
||||
{
|
||||
string rootPath = PersistentHelper.GetCachedBundleFileFolderPath(_packageName);
|
||||
string rootPath = PersistentTools.GetCachedBundleFileFolderPath(_packageName);
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace YooAsset
|
||||
|
||||
// RawFiles
|
||||
{
|
||||
string rootPath = PersistentHelper.GetCachedRawFileFolderPath(_packageName);
|
||||
string rootPath = PersistentTools.GetCachedRawFileFolderPath(_packageName);
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,59 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径帮助类
|
||||
/// </summary>
|
||||
internal static class PathHelper
|
||||
internal static class PersistentTools
|
||||
{
|
||||
private const string CacheFolderName = "CacheFiles";
|
||||
private const string CachedBundleFileFolder = "BundleFiles";
|
||||
private const string CachedRawFileFolder = "RawFiles";
|
||||
private const string ManifestFolderName = "ManifestFiles";
|
||||
private const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
|
||||
|
||||
private static string _buildinPath;
|
||||
private static string _sandboxPath;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重写沙盒跟路径
|
||||
/// </summary>
|
||||
public static void OverwriteSandboxPath(string sandboxPath)
|
||||
{
|
||||
_sandboxPath = sandboxPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒文件夹路径
|
||||
/// </summary>
|
||||
public static string GetPersistentRootPath()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
string directory = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
string projectPath = GetRegularPath(directory);
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", projectPath);
|
||||
}
|
||||
#elif UNITY_STANDALONE
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.dataPath);
|
||||
}
|
||||
#else
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath);
|
||||
}
|
||||
#endif
|
||||
|
||||
return _sandboxPath;
|
||||
}
|
||||
private static string GetRegularPath(string path)
|
||||
{
|
||||
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取基于流文件夹的加载路径
|
||||
/// </summary>
|
||||
@@ -32,33 +77,6 @@ namespace YooAsset
|
||||
return StringUtility.Format("{0}/{1}", root, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒文件夹路径
|
||||
/// </summary>
|
||||
public static string GetPersistentRootPath()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
string directory = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
string projectPath = GetRegularPath(directory);
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", projectPath);
|
||||
}
|
||||
return _sandboxPath;
|
||||
#else
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath);
|
||||
}
|
||||
return _sandboxPath;
|
||||
#endif
|
||||
}
|
||||
private static string GetRegularPath(string path)
|
||||
{
|
||||
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取WWW加载本地资源的路径
|
||||
/// </summary>
|
||||
@@ -76,18 +94,6 @@ namespace YooAsset
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 持久化目录帮助类
|
||||
/// </summary>
|
||||
internal static class PersistentHelper
|
||||
{
|
||||
private const string CacheFolderName = "CacheFiles";
|
||||
private const string CachedBundleFileFolder = "BundleFiles";
|
||||
private const string CachedRawFileFolder = "RawFiles";
|
||||
private const string ManifestFolderName = "ManifestFiles";
|
||||
private const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -95,7 +101,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void DeleteSandbox()
|
||||
{
|
||||
string directoryPath = PathHelper.MakePersistentLoadPath(string.Empty);
|
||||
string directoryPath = MakePersistentLoadPath(string.Empty);
|
||||
if (Directory.Exists(directoryPath))
|
||||
Directory.Delete(directoryPath, true);
|
||||
}
|
||||
@@ -105,7 +111,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void DeleteCacheFolder()
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
string root = MakePersistentLoadPath(CacheFolderName);
|
||||
if (Directory.Exists(root))
|
||||
Directory.Delete(root, true);
|
||||
}
|
||||
@@ -115,7 +121,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void DeleteManifestFolder()
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(ManifestFolderName);
|
||||
string root = MakePersistentLoadPath(ManifestFolderName);
|
||||
if (Directory.Exists(root))
|
||||
Directory.Delete(root, true);
|
||||
}
|
||||
@@ -129,7 +135,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
string root = MakePersistentLoadPath(CacheFolderName);
|
||||
value = $"{root}/{packageName}/{CachedBundleFileFolder}";
|
||||
_cachedBundleFileFolder.Add(packageName, value);
|
||||
}
|
||||
@@ -144,7 +150,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false)
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
string root = MakePersistentLoadPath(CacheFolderName);
|
||||
value = $"{root}/{packageName}/{CachedRawFileFolder}";
|
||||
_cachedRawFileFolder.Add(packageName, value);
|
||||
}
|
||||
@@ -156,7 +162,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string GetAppFootPrintFilePath()
|
||||
{
|
||||
return PathHelper.MakePersistentLoadPath(AppFootPrintFileName);
|
||||
return MakePersistentLoadPath(AppFootPrintFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,7 +171,7 @@ namespace YooAsset
|
||||
public static string GetCacheManifestFilePath(string packageName, string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||
return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,7 +180,7 @@ namespace YooAsset
|
||||
public static string GetCachePackageHashFilePath(string packageName, string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
|
||||
return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,7 +189,7 @@ namespace YooAsset
|
||||
public static string GetCachePackageVersionFilePath(string packageName)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||
return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,7 +193,7 @@ namespace YooAsset
|
||||
public static BundleInfo GetUnpackInfo(PackageBundle packageBundle)
|
||||
{
|
||||
// 注意:我们把流加载路径指定为远端下载地址
|
||||
string streamingPath = PathHelper.ConvertToWWWPath(packageBundle.StreamingFilePath);
|
||||
string streamingPath = PersistentTools.ConvertToWWWPath(packageBundle.StreamingFilePath);
|
||||
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace YooAsset
|
||||
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
|
||||
if (appFootPrint.IsDirty())
|
||||
{
|
||||
PersistentHelper.DeleteManifestFolder();
|
||||
PersistentTools.DeleteManifestFolder();
|
||||
appFootPrint.Coverage();
|
||||
YooLogger.Log("Delete manifest files when application foot print dirty !");
|
||||
}
|
||||
@@ -376,7 +376,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void Load()
|
||||
{
|
||||
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
|
||||
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
|
||||
if (File.Exists(footPrintFilePath))
|
||||
{
|
||||
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
|
||||
@@ -409,7 +409,7 @@ namespace YooAsset
|
||||
#else
|
||||
_footPrint = Application.buildGUID;
|
||||
#endif
|
||||
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
|
||||
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
|
||||
FileUtility.CreateFile(footPrintFilePath, _footPrint);
|
||||
YooLogger.Log($"Save application foot print : {_footPrint}");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader1 == null)
|
||||
{
|
||||
string savePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
string savePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download package hash file : {webURL}");
|
||||
@@ -71,7 +71,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader2 == null)
|
||||
{
|
||||
string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||
string savePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download manifest file : {webURL}");
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace YooAsset
|
||||
if (_downloader == null)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(url);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.VerifyFileHash)
|
||||
{
|
||||
_manifestFilePath = PersistentHelper.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||
_manifestFilePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||
if (File.Exists(_manifestFilePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -131,7 +131,7 @@ namespace YooAsset
|
||||
File.Delete(_manifestFilePath);
|
||||
}
|
||||
|
||||
string hashFilePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
string hashFilePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
if (File.Exists(hashFilePath))
|
||||
{
|
||||
File.Delete(hashFilePath);
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace YooAsset
|
||||
if (_downloader == null)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(url);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadCachePackageHashFile)
|
||||
{
|
||||
string filePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
string filePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadCachePackageVersionFile)
|
||||
{
|
||||
string filePath = PersistentHelper.GetCachePackageVersionFilePath(_packageName);
|
||||
string filePath = PersistentTools.GetCachePackageVersionFilePath(_packageName);
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -35,10 +35,10 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader1 == null)
|
||||
{
|
||||
string savePath = PersistentHelper.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||
string savePath = PersistentTools.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader1 = new UnityWebFileRequester();
|
||||
_downloader1.SendRequest(url, savePath);
|
||||
}
|
||||
@@ -64,10 +64,10 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader2 == null)
|
||||
{
|
||||
string savePath = PersistentHelper.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||
string savePath = PersistentTools.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader2 = new UnityWebFileRequester();
|
||||
_downloader2.SendRequest(url, savePath);
|
||||
}
|
||||
|
||||
@@ -74,12 +74,12 @@ namespace YooAsset
|
||||
string folderName = FileHash.Substring(0, 2);
|
||||
if (IsRawFile)
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
|
||||
_cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}";
|
||||
}
|
||||
else
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
|
||||
_cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}";
|
||||
}
|
||||
return _cachedDataFilePath;
|
||||
@@ -100,12 +100,12 @@ namespace YooAsset
|
||||
string folderName = FileHash.Substring(0, 2);
|
||||
if (IsRawFile)
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
|
||||
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
|
||||
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
|
||||
}
|
||||
return _cachedInfoFilePath;
|
||||
@@ -139,7 +139,7 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(_streamingFilePath) == false)
|
||||
return _streamingFilePath;
|
||||
|
||||
_streamingFilePath = PathHelper.MakeStreamingLoadPath(FileName);
|
||||
_streamingFilePath = PersistentTools.MakeStreamingLoadPath(FileName);
|
||||
return _streamingFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace YooAsset
|
||||
public void FlushManifestVersionFile()
|
||||
{
|
||||
if (_activeManifest != null)
|
||||
PersistentHelper.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
|
||||
PersistentTools.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
|
||||
}
|
||||
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
|
||||
@@ -251,6 +251,17 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹本地所有的缓存文件
|
||||
/// </summary>
|
||||
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new ClearAllCacheFilesOperation(this);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地包裹的版本信息
|
||||
/// </summary>
|
||||
|
||||
@@ -150,6 +150,9 @@ namespace YooAsset
|
||||
YooLogger.Log($"Destroy resource package : {packageName}");
|
||||
_packages.Remove(package);
|
||||
package.DestroyPackage();
|
||||
|
||||
// 清空缓存
|
||||
CacheSystem.ClearPackage(packageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -231,6 +234,27 @@ namespace YooAsset
|
||||
{
|
||||
CacheSystem.InitVerifyLevel = verifyLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置缓存系统参数,沙盒目录的存储路径
|
||||
/// </summary>
|
||||
public static void SetCacheSystemSandboxPath(string sandboxPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sandboxPath))
|
||||
{
|
||||
YooLogger.Error($"Sandbox path is null or empty !");
|
||||
return;
|
||||
}
|
||||
|
||||
// 注意:需要确保没有任何资源系统起效之前才可以设置沙盒目录!
|
||||
if (_packages.Count > 0)
|
||||
{
|
||||
YooLogger.Error($"Please call this method {nameof(SetCacheSystemSandboxPath)} before the package is created !");
|
||||
return;
|
||||
}
|
||||
|
||||
PersistentTools.OverwriteSandboxPath(sandboxPath);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 沙盒相关
|
||||
@@ -247,7 +271,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string GetSandboxRoot()
|
||||
{
|
||||
return PathHelper.GetPersistentRootPath();
|
||||
return PersistentTools.GetPersistentRootPath();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -256,7 +280,7 @@ namespace YooAsset
|
||||
public static void ClearSandbox()
|
||||
{
|
||||
YooLogger.Warning("Clear sandbox folder files, Finally, restart the application !");
|
||||
PersistentHelper.DeleteSandbox();
|
||||
PersistentTools.DeleteSandbox();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -47,20 +47,6 @@ public class FileStreamEncryption : IEncryptionServices
|
||||
return result;
|
||||
}
|
||||
|
||||
// LoadFromFileOffset
|
||||
if (fileInfo.BundleName.Contains("_gameres_uiimage"))
|
||||
{
|
||||
var fileData = File.ReadAllBytes(fileInfo.FilePath);
|
||||
int offset = 32;
|
||||
var temper = new byte[fileData.Length + offset];
|
||||
Buffer.BlockCopy(fileData, 0, temper, offset, fileData.Length);
|
||||
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.LoadMethod = EBundleLoadMethod.LoadFromFileOffset;
|
||||
result.EncryptedData = temper;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Normal
|
||||
{
|
||||
EncryptResult result = new EncryptResult();
|
||||
|
||||
@@ -74,7 +74,7 @@ internal class FsmInitialize : IStateNode
|
||||
}
|
||||
|
||||
yield return initializationOperation;
|
||||
if (package.InitializeStatus == EOperationStatus.Succeed)
|
||||
if (initializationOperation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_machine.ChangeState<FsmUpdateVersion>();
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b1fa97e8bb8c5c46ad030b9554e1b5c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b19a7385dee2d0141901167dbfda9300
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,57 +0,0 @@
|
||||
//-------------------------------------
|
||||
// 作者:Stark
|
||||
//-------------------------------------
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
private static readonly Dictionary<string, bool> _cacheData = new Dictionary<string, bool>(1000);
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
private static AndroidJavaClass _unityPlayerClass;
|
||||
public static AndroidJavaClass UnityPlayerClass
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_unityPlayerClass == null)
|
||||
_unityPlayerClass = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
||||
return _unityPlayerClass;
|
||||
}
|
||||
}
|
||||
|
||||
private static AndroidJavaObject _currentActivity;
|
||||
public static AndroidJavaObject CurrentActivity
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentActivity == null)
|
||||
_currentActivity = UnityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
|
||||
return _currentActivity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 利用安卓原生接口查询内置文件是否存在
|
||||
/// </summary>
|
||||
public static bool FileExists(string filePath)
|
||||
{
|
||||
if (_cacheData.TryGetValue(filePath, out bool result) == false)
|
||||
{
|
||||
result = CurrentActivity.Call<bool>("CheckAssetExist", filePath);
|
||||
_cacheData.Add(filePath, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
public static bool FileExists(string filePath)
|
||||
{
|
||||
if (_cacheData.TryGetValue(filePath, out bool result) == false)
|
||||
{
|
||||
result = System.IO.File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, filePath));
|
||||
_cacheData.Add(filePath, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,8 +1,66 @@
|
||||
//-------------------------------------
|
||||
// 作者:Stark
|
||||
//-------------------------------------
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
/// <summary>
|
||||
/// StreamingAssets目录下资源查询帮助类
|
||||
/// </summary>
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
private static readonly Dictionary<string, bool> _cacheData = new Dictionary<string, bool>(1000);
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
private static AndroidJavaClass _unityPlayerClass;
|
||||
public static AndroidJavaClass UnityPlayerClass
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_unityPlayerClass == null)
|
||||
_unityPlayerClass = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
||||
return _unityPlayerClass;
|
||||
}
|
||||
}
|
||||
|
||||
private static AndroidJavaObject _currentActivity;
|
||||
public static AndroidJavaObject CurrentActivity
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentActivity == null)
|
||||
_currentActivity = UnityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
|
||||
return _currentActivity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 利用安卓原生接口查询内置文件是否存在
|
||||
/// </summary>
|
||||
public static bool FileExists(string filePath)
|
||||
{
|
||||
if (_cacheData.TryGetValue(filePath, out bool result) == false)
|
||||
{
|
||||
result = CurrentActivity.Call<bool>("CheckAssetExist", filePath);
|
||||
_cacheData.Add(filePath, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
public static bool FileExists(string filePath)
|
||||
{
|
||||
if (_cacheData.TryGetValue(filePath, out bool result) == false)
|
||||
{
|
||||
result = System.IO.File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, filePath));
|
||||
_cacheData.Add(filePath, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_ANDROID && UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 为Github对开发者的友好,采用自动补充UnityPlayerActivity.java文件的通用姿势满足各个开发者
|
||||
/// </summary>
|
||||
@@ -30,7 +88,6 @@ internal class AndroidPost : UnityEditor.Android.IPostGenerateGradleAndroidProje
|
||||
" } \n" +
|
||||
" catch(java.io.IOException e) \n" +
|
||||
" { \n" +
|
||||
" e.printStackTrace(); \n" +
|
||||
" } \n" +
|
||||
" return false; \n" +
|
||||
" } \n" +
|
||||
@@ -70,7 +127,7 @@ public boolean CheckAssetExist(String filePath)
|
||||
}
|
||||
catch(java.io.IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
//e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.4.12",
|
||||
"version": "1.4.14",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user