Compare commits

...

6 Commits

Author SHA1 Message Date
hevinci a7d9a4ecbc update extension sample 2023-07-05 15:20:34 +08:00
hevinci 2643ab81ed update runtime code
重构了PersistentTools类
2023-07-05 15:14:21 +08:00
hevinci c5314c72f0 update runtime code
1. 新增了ResourcePackage.GetPackageBuildinRootDirectory()方法
2. 新增了ResourcePackage.GetPackageSandboxRootDirectory()方法
3. 新增了ResourcePackage.ClearPackageSandbox()方法
2023-07-05 14:56:18 +08:00
hevinci fbb48ba330 Update InitializeParameters.cs
1. 新增了InitializeParameters.BuildinRootDirectory字段
2. 新增了InitializeParameters.SandboxRootDirectory字段
2023-07-05 14:52:13 +08:00
hevinci 4e6879e34f update runtime code
1. 移除了YooAssets.SetCacheSystemBuildinPath()方法
2. 移除了YooAssets.SetCacheSystemSandboxPath()方法
3. 移除了YooAssets.GetStreamingAssetBuildinFolderName()方法
4. 移除了YooAssets.GetSandboxRoot()方法
5. 移除了YooAssets.ClearSandbox()方法
2023-07-05 14:50:21 +08:00
hevinci 09c3d4e479 update editor code
1. BuildParameters.OutputRoot重命名为BuildOutputRoot
2. 新增了BuildParameters.StreamingAssetsRoot字段
2023-07-05 11:51:49 +08:00
28 changed files with 372 additions and 363 deletions

View File

@ -23,20 +23,7 @@ namespace YooAsset.Editor
// 检测构建参数是否为空
if (buildPipeline.Count == 0)
throw new Exception($"Build pipeline is empty !");
// 检测可编程构建管线参数
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
if (buildParameters.SBPParameters == null)
throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !");
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !");
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.ForceRebuild)} build mode !");
}
throw new Exception($"Build pipeline is empty !");
// 清空旧数据
_buildContext.ClearAllContext();

View File

@ -11,7 +11,7 @@ namespace YooAsset.Editor
/// <summary>
/// 获取默认的输出根路录
/// </summary>
public static string GetDefaultOutputRoot()
public static string GetDefaultBuildOutputRoot()
{
string projectPath = EditorTools.GetProjectPath();
return $"{projectPath}/Bundles";
@ -20,43 +20,9 @@ namespace YooAsset.Editor
/// <summary>
/// 获取流文件夹路径
/// </summary>
public static string GetStreamingAssetsFolderPath()
public static string GetDefaultStreamingAssetsRoot()
{
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.StreamingAssetsBuildinFolder}/";
}
/// <summary>
/// 清空流文件夹
/// </summary>
public static void ClearStreamingAssetsFolder()
{
string streamingFolderPath = GetStreamingAssetsFolderPath();
EditorTools.ClearFolder(streamingFolderPath);
}
/// <summary>
/// 删除流文件夹内无关的文件
/// 删除.manifest文件和.meta文件
/// </summary>
public static void DeleteStreamingAssetsIgnoreFiles()
{
string streamingFolderPath = GetStreamingAssetsFolderPath();
if (Directory.Exists(streamingFolderPath))
{
string[] files = Directory.GetFiles(streamingFolderPath, "*.manifest", SearchOption.AllDirectories);
foreach (var file in files)
{
FileInfo info = new FileInfo(file);
info.Delete();
}
files = Directory.GetFiles(streamingFolderPath, "*.meta", SearchOption.AllDirectories);
foreach (var item in files)
{
FileInfo info = new FileInfo(item);
info.Delete();
}
}
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.DefaultYooFolderName}/";
}
}
}

View File

@ -63,7 +63,7 @@ namespace YooAsset.Editor
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.Name).ToList();
// 输出目录
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
_buildOutputField = root.Q<TextField>("BuildOutput");
_buildOutputField.SetValueWithoutNotify(defaultOutputRoot);
_buildOutputField.SetEnabled(false);
@ -266,9 +266,9 @@ namespace YooAsset.Editor
/// </summary>
private void ExecuteBuild()
{
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
BuildParameters buildParameters = new BuildParameters();
buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildTarget = _buildTarget;
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;

View File

@ -11,9 +11,9 @@ namespace YooAsset.Editor
public static string SimulateBuild(string packageName)
{
Debug.Log($"Begin to create simulate package : {packageName}");
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
BuildParameters buildParameters = new BuildParameters();
buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.PackageName = packageName;

View File

@ -37,9 +37,14 @@ namespace YooAsset.Editor
/// <summary>
/// 输出的根目录
/// 内置资源的根目录
/// </summary>
public string OutputRoot;
public string StreamingAssetsRoot;
/// <summary>
/// 构建输出的根目录
/// </summary>
public string BuildOutputRoot;
/// <summary>
/// 构建的平台

View File

@ -9,6 +9,8 @@ namespace YooAsset.Editor
{
private string _pipelineOutputDirectory = string.Empty;
private string _packageOutputDirectory = string.Empty;
private string _packageRootDirectory = string.Empty;
private string _streamingAssetsDirectory = string.Empty;
/// <summary>
/// 构建参数
@ -29,23 +31,47 @@ namespace YooAsset.Editor
{
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
{
_pipelineOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{YooAssetSettings.OutputFolderName}";
_pipelineOutputDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{YooAssetSettings.OutputFolderName}";
}
return _pipelineOutputDirectory;
}
/// <summary>
/// 获取本次构建的补丁目录
/// 获取本次构建的补丁输出目录
/// </summary>
public string GetPackageOutputDirectory()
{
if (string.IsNullOrEmpty(_packageOutputDirectory))
{
_packageOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{Parameters.PackageVersion}";
_packageOutputDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{Parameters.PackageVersion}";
}
return _packageOutputDirectory;
}
/// <summary>
/// 获取本次构建的补丁根目录
/// </summary>
public string GetPackageRootDirectory()
{
if (string.IsNullOrEmpty(_packageRootDirectory))
{
_packageRootDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}";
}
return _packageRootDirectory;
}
/// <summary>
/// 获取内置资源的目录
/// </summary>
public string GetStreamingAssetsDirectory()
{
if (string.IsNullOrEmpty(_streamingAssetsDirectory))
{
_streamingAssetsDirectory = $"{Parameters.StreamingAssetsRoot}/{Parameters.PackageName}";
}
return _streamingAssetsDirectory;
}
/// <summary>
/// 获取内置构建管线的构建选项
/// </summary>

View File

@ -30,7 +30,7 @@ namespace YooAsset.Editor
{
ECopyBuildinFileOption option = buildParametersContext.Parameters.CopyBuildinFileOption;
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
string streamingAssetsDirectory = AssetBundleBuilderHelper.GetStreamingAssetsFolderPath();
string streamingAssetsDirectory = buildParametersContext.GetStreamingAssetsDirectory();
string buildPackageName = buildParametersContext.Parameters.PackageName;
string buildPackageVersion = buildParametersContext.Parameters.PackageVersion;
@ -40,7 +40,7 @@ namespace YooAsset.Editor
// 清空流目录
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.ClearAndCopyByTags)
{
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
EditorTools.ClearFolder(streamingAssetsDirectory);
}
// 拷贝补丁清单文件

View File

@ -147,17 +147,17 @@ namespace YooAsset.Editor
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)
{
// 1. 检测是否任何存在依赖资源
bool hasAnyDependAsset = false;
bool hasAnyDependCollector = false;
foreach (var collectAssetInfo in allCollectAssetInfos)
{
var collectorType = collectAssetInfo.CollectorType;
if (collectorType == ECollectorType.DependAssetCollector)
{
hasAnyDependAsset = true;
hasAnyDependCollector = true;
break;
}
}
if (hasAnyDependAsset == false)
if (hasAnyDependCollector == false)
return;
// 2. 获取所有主资源的依赖资源集合

View File

@ -16,11 +16,27 @@ namespace YooAsset.Editor
// 检测构建参数合法性
if (buildParameters.BuildTarget == BuildTarget.NoTarget)
throw new Exception("请选择目标平台");
throw new Exception("请选择目标平台");
if (string.IsNullOrEmpty(buildParameters.PackageName))
throw new Exception("包裹名称不能为空");
throw new Exception("包裹名称不能为空");
if (string.IsNullOrEmpty(buildParameters.PackageVersion))
throw new Exception("包裹版本不能为空");
throw new Exception("包裹版本不能为空!");
if (string.IsNullOrEmpty(buildParameters.BuildOutputRoot))
throw new Exception("构建输出的根目录为空!");
if (string.IsNullOrEmpty(buildParameters.StreamingAssetsRoot))
throw new Exception("内置资源根目录为空!");
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
if (buildParameters.SBPParameters == null)
throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !");
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !");
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.ForceRebuild)} build mode !");
}
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
{
@ -72,11 +88,10 @@ namespace YooAsset.Editor
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
{
// 删除总目录
string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.PackageName}";
if (EditorTools.DeleteDirectory(platformDirectory))
string packageRootDirectory = buildParametersContext.GetPackageRootDirectory();
if (EditorTools.DeleteDirectory(packageRootDirectory))
{
BuildLogger.Log($"删除平台总目录:{platformDirectory}");
BuildLogger.Log($"删除包裹目录:{packageRootDirectory}");
}
}

View File

@ -45,7 +45,7 @@ namespace YooAsset
{
// BundleFiles
{
string rootPath = PersistentTools.GetCachedBundleFileFolderPath(_packageName);
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheBundleFilesRoot;
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists)
{
@ -56,7 +56,7 @@ namespace YooAsset
// RawFiles
{
string rootPath = PersistentTools.GetCachedRawFileFolderPath(_packageName);
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheRawFilesRoot;
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists)
{

View File

@ -0,0 +1,163 @@
using System.IO;
namespace YooAsset
{
internal class Persistent
{
private readonly string _packageName;
public string BuildinRoot { private set; get; }
public string BuildinPackageRoot { private set; get; }
public string SandboxRoot { private set; get; }
public string SandboxPackageRoot { private set; get; }
public string SandboxCacheBundleFilesRoot { private set; get; }
public string SandboxCacheRawFilesRoot { private set; get; }
public string SandboxManifestFilesRoot { private set; get; }
public string SandboxAppFootPrintFilePath { private set; get; }
public Persistent(string packageName)
{
_packageName = packageName;
}
/// <summary>
/// 重写根路径
/// </summary>
public void OverwriteRootDirectory(string buildinRoot, string sandboxRoot)
{
if (string.IsNullOrEmpty(buildinRoot))
BuildinRoot = CreateDefaultBuildinRoot();
else
BuildinRoot = buildinRoot;
if (string.IsNullOrEmpty(sandboxRoot))
SandboxRoot = CreateDefaultSandboxRoot();
else
SandboxRoot = sandboxRoot;
BuildinPackageRoot = PathUtility.Combine(BuildinRoot, _packageName);
SandboxPackageRoot = PathUtility.Combine(SandboxRoot, _packageName);
SandboxCacheBundleFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedBundleFileFolder);
SandboxCacheRawFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedRawFileFolder);
SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName);
SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName);
}
private static string CreateDefaultBuildinRoot()
{
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.DefaultYooFolderName);
}
private static string CreateDefaultSandboxRoot()
{
#if UNITY_EDITOR
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
projectPath = PathUtility.RegularPath(projectPath);
return PathUtility.Combine(projectPath, YooAssetSettings.DefaultYooFolderName);
#elif UNITY_STANDALONE
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettings.DefaultYooFolderName);
#else
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettings.DefaultYooFolderName);
#endif
}
/// <summary>
/// 删除沙盒里的包裹目录
/// </summary>
public void DeleteSandboxPackageFolder()
{
if (Directory.Exists(SandboxPackageRoot))
Directory.Delete(SandboxPackageRoot, true);
}
/// <summary>
/// 删除沙盒内的缓存文件夹
/// </summary>
public void DeleteSandboxCacheFilesFolder()
{
// CacheBundleFiles
if (Directory.Exists(SandboxCacheBundleFilesRoot))
Directory.Delete(SandboxCacheBundleFilesRoot, true);
// CacheRawFiles
if (Directory.Exists(SandboxCacheRawFilesRoot))
Directory.Delete(SandboxCacheRawFilesRoot, true);
}
/// <summary>
/// 删除沙盒内的清单文件夹
/// </summary>
public void DeleteSandboxManifestFilesFolder()
{
if (Directory.Exists(SandboxManifestFilesRoot))
Directory.Delete(SandboxManifestFilesRoot, true);
}
/// <summary>
/// 获取沙盒内包裹的清单文件的路径
/// </summary>
public string GetSandboxPackageManifestFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion);
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
}
/// <summary>
/// 获取沙盒内包裹的哈希文件的路径
/// </summary>
public string GetSandboxPackageHashFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion);
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
}
/// <summary>
/// 获取沙盒内包裹的版本文件的路径
/// </summary>
public string GetSandboxPackageVersionFilePath()
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
}
/// <summary>
/// 保存沙盒内默认的包裹版本
/// </summary>
public void SaveSandboxPackageVersionFile(string version)
{
string filePath = GetSandboxPackageVersionFilePath();
FileUtility.WriteAllText(filePath, version);
}
/// <summary>
/// 获取APP内包裹的清单文件的路径
/// </summary>
public string GetBuildinPackageManifestFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion);
return PathUtility.Combine(BuildinPackageRoot, fileName);
}
/// <summary>
/// 获取APP内包裹的哈希文件的路径
/// </summary>
public string GetBuildinPackageHashFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion);
return PathUtility.Combine(BuildinPackageRoot, fileName);
}
/// <summary>
/// 获取APP内包裹的版本文件的路径
/// </summary>
public string GetBuildinPackageVersionFilePath()
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
return PathUtility.Combine(BuildinPackageRoot, fileName);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62ee5fd2821fe85488efff3f8242b703
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,92 +3,31 @@ using System.Collections.Generic;
namespace YooAsset
{
internal static class PersistentTools
internal class PersistentTools
{
private const string SandboxFolderName = "Sandbox";
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;
private static readonly Dictionary<string, Persistent> _persitentDic = new Dictionary<string, Persistent>(100);
/// <summary>
/// 重写内置跟路径
/// 获取包裹的持久化类
/// </summary>
public static void OverwriteBuildinPath(string path)
public static Persistent GetPersistent(string packageName)
{
_buildinPath = path;
if (_persitentDic.ContainsKey(packageName) == false)
throw new System.Exception("Should never get here !");
return _persitentDic[packageName];
}
/// <summary>
/// 重写沙盒跟路径
/// 获取或创建包裹的持久化类
/// </summary>
public static void OverwriteSandboxPath(string path)
public static Persistent GetOrCreatePersistent(string packageName)
{
_sandboxPath = path;
}
/// <summary>
/// 获取沙盒文件夹路径
/// </summary>
public static string GetPersistentRootPath()
{
#if UNITY_EDITOR
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
if (string.IsNullOrEmpty(_sandboxPath))
if (_persitentDic.ContainsKey(packageName) == false)
{
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
projectPath = PathUtility.RegularPath(projectPath);
_sandboxPath = PathUtility.Combine(projectPath, SandboxFolderName);
Persistent persistent = new Persistent(packageName);
_persitentDic.Add(packageName, persistent);
}
#elif UNITY_STANDALONE
if (string.IsNullOrEmpty(_sandboxPath))
{
_sandboxPath = PathUtility.Combine(UnityEngine.Application.dataPath, SandboxFolderName);
}
#else
if (string.IsNullOrEmpty(_sandboxPath))
{
_sandboxPath = PathUtility.Combine(UnityEngine.Application.persistentDataPath, SandboxFolderName);
}
#endif
return _sandboxPath;
}
/// <summary>
/// 获取基于流文件夹的加载路径
/// </summary>
public static string MakeStreamingLoadPath(string path)
{
if (string.IsNullOrEmpty(_buildinPath))
{
_buildinPath = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder);
}
return PathUtility.Combine(_buildinPath, path);
}
/// <summary>
/// 获取基于沙盒文件夹的加载路径
/// </summary>
public static string MakePersistentLoadPath(string path)
{
string root = GetPersistentRootPath();
return PathUtility.Combine(root, path);
}
public static string MakePersistentLoadPath(string path1, string path2)
{
string root = GetPersistentRootPath();
return PathUtility.Combine(root, path1, path2);
}
public static string MakePersistentLoadPath(string path1, string path2, string path3)
{
string root = GetPersistentRootPath();
return PathUtility.Combine(root, path1, path2, path3);
return _persitentDic[packageName];
}
/// <summary>
@ -108,109 +47,5 @@ namespace YooAsset
return path;
#endif
}
/// <summary>
/// 删除沙盒总目录
/// </summary>
public static void DeleteSandbox()
{
string directoryPath = GetPersistentRootPath();
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
}
/// <summary>
/// 删除沙盒内的缓存文件夹
/// </summary>
public static void DeleteCacheFolder()
{
string root = MakePersistentLoadPath(CacheFolderName);
if (Directory.Exists(root))
Directory.Delete(root, true);
}
/// <summary>
/// 删除沙盒内的清单文件夹
/// </summary>
public static void DeleteManifestFolder()
{
string root = MakePersistentLoadPath(ManifestFolderName);
if (Directory.Exists(root))
Directory.Delete(root, true);
}
/// <summary>
/// 获取缓存的BundleFile文件夹路径
/// </summary>
private readonly static Dictionary<string, string> _cachedBundleFileFolder = new Dictionary<string, string>(100);
public static string GetCachedBundleFileFolderPath(string packageName)
{
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
{
value = MakePersistentLoadPath(CacheFolderName, packageName, CachedBundleFileFolder);
_cachedBundleFileFolder.Add(packageName, value);
}
return value;
}
/// <summary>
/// 获取缓存的RawFile文件夹路径
/// </summary>
private readonly static Dictionary<string, string> _cachedRawFileFolder = new Dictionary<string, string>(100);
public static string GetCachedRawFileFolderPath(string packageName)
{
if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false)
{
value = MakePersistentLoadPath(CacheFolderName, packageName, CachedRawFileFolder);
_cachedRawFileFolder.Add(packageName, value);
}
return value;
}
/// <summary>
/// 获取应用程序的水印文件路径
/// </summary>
public static string GetAppFootPrintFilePath()
{
return MakePersistentLoadPath(AppFootPrintFileName);
}
/// <summary>
/// 获取沙盒内清单文件的路径
/// </summary>
public static string GetCacheManifestFilePath(string packageName, string packageVersion)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
return MakePersistentLoadPath(ManifestFolderName, fileName);
}
/// <summary>
/// 获取沙盒内包裹的哈希文件的路径
/// </summary>
public static string GetCachePackageHashFilePath(string packageName, string packageVersion)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
return MakePersistentLoadPath(ManifestFolderName, fileName);
}
/// <summary>
/// 获取沙盒内包裹的版本文件的路径
/// </summary>
public static string GetCachePackageVersionFilePath(string packageName)
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
return MakePersistentLoadPath(ManifestFolderName, fileName);
}
/// <summary>
/// 保存默认的包裹版本
/// </summary>
public static void SaveCachePackageVersionFile(string packageName, string version)
{
string filePath = GetCachePackageVersionFilePath(packageName);
FileUtility.WriteAllText(filePath, version);
}
}
}

View File

@ -32,6 +32,18 @@ namespace YooAsset
/// </summary>
public IDecryptionServices DecryptionServices = null;
/// <summary>
/// 内置文件的根路径
/// 注意:当参数为空的时候会使用默认的根目录。
/// </summary>
public string BuildinRootDirectory = string.Empty;
/// <summary>
/// 沙盒文件的根路径
/// 注意:当参数为空的时候会使用默认的根目录。
/// </summary>
public string SandboxRootDirectory = string.Empty;
/// <summary>
/// 资源加载每帧处理的最大时间片段
/// 注意默认值为MaxValue

View File

@ -217,13 +217,13 @@ namespace YooAsset
if (_steps == ESteps.CheckAppFootPrint)
{
var appFootPrint = new AppFootPrint();
appFootPrint.Load();
appFootPrint.Load(_packageName);
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
if (appFootPrint.IsDirty())
{
PersistentTools.DeleteManifestFolder();
appFootPrint.Coverage();
PersistentTools.GetPersistent(_packageName).DeleteSandboxManifestFilesFolder();
appFootPrint.Coverage(_packageName);
YooLogger.Log("Delete manifest files when application foot print dirty !");
}
_steps = ESteps.QueryCachePackageVersion;
@ -374,16 +374,16 @@ namespace YooAsset
/// <summary>
/// 读取应用程序水印
/// </summary>
public void Load()
public void Load(string packageName)
{
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
if (File.Exists(footPrintFilePath))
{
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
}
else
{
Coverage();
Coverage(packageName);
}
}
@ -402,14 +402,14 @@ namespace YooAsset
/// <summary>
/// 覆盖掉水印
/// </summary>
public void Coverage()
public void Coverage(string packageName)
{
#if UNITY_EDITOR
_footPrint = Application.version;
#else
_footPrint = Application.buildGUID;
#endif
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
YooLogger.Log($"Save application foot print : {_footPrint}");
}

View File

@ -41,7 +41,7 @@ namespace YooAsset
{
if (_downloader1 == null)
{
string savePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_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 = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download manifest file : {webURL}");

View File

@ -41,8 +41,7 @@ namespace YooAsset
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string filePath = PersistentTools.GetPersistent(_buildinPackageName).GetBuildinPackageManifestFilePath(_buildinPackageVersion);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);

View File

@ -67,7 +67,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileHash)
{
_manifestFilePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
_manifestFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
if (File.Exists(_manifestFilePath) == false)
{
_steps = ESteps.Done;
@ -131,7 +131,7 @@ namespace YooAsset
File.Delete(_manifestFilePath);
}
string hashFilePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
string hashFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
if (File.Exists(hashFilePath))
{
File.Delete(hashFilePath);

View File

@ -37,8 +37,7 @@ namespace YooAsset
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string filePath = PersistentTools.GetPersistent(_packageName).GetBuildinPackageVersionFilePath();
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);

View File

@ -37,7 +37,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCachePackageHashFile)
{
string filePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;

View File

@ -35,7 +35,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCachePackageVersionFile)
{
string filePath = PersistentTools.GetCachePackageVersionFilePath(_packageName);
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageVersionFilePath();
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;

View File

@ -31,13 +31,13 @@ namespace YooAsset
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if(_steps == ESteps.UnpackManifestHashFile)
if (_steps == ESteps.UnpackManifestHashFile)
{
if (_downloader1 == null)
{
string savePath = PersistentTools.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
string savePath = persistent.GetSandboxPackageHashFilePath(_buildinPackageVersion);
string filePath = persistent.GetBuildinPackageHashFilePath(_buildinPackageVersion);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader1 = new UnityWebFileRequester();
_downloader1.SendRequest(url, savePath);
@ -64,9 +64,9 @@ namespace YooAsset
{
if (_downloader2 == null)
{
string savePath = PersistentTools.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
string savePath = persistent.GetSandboxPackageManifestFilePath(_buildinPackageVersion);
string filePath = persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader2 = new UnityWebFileRequester();
_downloader2.SendRequest(url, savePath);

View File

@ -74,13 +74,13 @@ namespace YooAsset
string folderName = FileHash.Substring(0, 2);
if (IsRawFile)
{
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
_cachedDataFilePath += _fileExtension;
}
else
{
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
}
return _cachedDataFilePath;
@ -101,12 +101,12 @@ namespace YooAsset
string folderName = FileHash.Substring(0, 2);
if (IsRawFile)
{
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
}
else
{
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
}
return _cachedInfoFilePath;
@ -140,7 +140,8 @@ namespace YooAsset
if (string.IsNullOrEmpty(_streamingFilePath) == false)
return _streamingFilePath;
_streamingFilePath = PersistentTools.MakeStreamingLoadPath(FileName);
string root = PersistentTools.GetPersistent(PackageName).BuildinPackageRoot;
_streamingFilePath = PathUtility.Combine(root, FileName);
return _streamingFilePath;
}
}

View File

@ -74,7 +74,9 @@ namespace YooAsset
public void FlushManifestVersionFile()
{
if (_activeManifest != null)
PersistentTools.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
{
PersistentTools.GetPersistent(_packageName).SaveSandboxPackageVersionFile(_activeManifest.PackageVersion);
}
}
private bool IsBuildinPackageBundle(PackageBundle packageBundle)

View File

@ -79,6 +79,10 @@ namespace YooAsset
// 检测初始化参数合法性
CheckInitializeParameters(parameters);
// 重写持久化根目录
var persistent = PersistentTools.GetOrCreatePersistent(PackageName);
persistent.OverwriteRootDirectory(parameters.BuildinRootDirectory, parameters.SandboxRootDirectory);
// 初始化资源系统
InitializationOperation initializeOperation;
_assetSystemImpl = new AssetSystemImpl();
@ -291,6 +295,37 @@ namespace YooAsset
_assetSystemImpl.ForceUnloadAllAssets();
}
#region 沙盒相关
/// <summary>
/// 获取包裹的内置文件根路径
/// </summary>
public string GetPackageBuildinRootDirectory()
{
DebugCheckInitialize();
var persistent = PersistentTools.GetPersistent(PackageName);
return persistent.BuildinRoot;
}
/// <summary>
/// 获取包裹的沙盒文件根路径
/// </summary>
public string GetPackageSandboxRootDirectory()
{
DebugCheckInitialize();
var persistent = PersistentTools.GetPersistent(PackageName);
return persistent.SandboxRoot;
}
/// <summary>
/// 清空包裹的沙盒目录
/// </summary>
public void ClearPackageSandbox()
{
DebugCheckInitialize();
var persistent = PersistentTools.GetPersistent(PackageName);
persistent.DeleteSandboxPackageFolder();
}
#endregion
#region 资源信息
/// <summary>

View File

@ -37,6 +37,31 @@ namespace YooAsset
/// </summary>
public const string CacheBundleInfoFileName = "__info";
/// <summary>
/// 默认的YooAsset文件夹名称
/// </summary>
public const string DefaultYooFolderName = "yoo";
/// <summary>
/// 缓存的资源文件的文件夹名称
/// </summary>
public const string CachedBundleFileFolder = "CacheBundleFiles";
/// <summary>
/// 缓存的原生文件的文件夹名称
/// </summary>
public const string CachedRawFileFolder = "CacheRawFiles";
/// <summary>
/// 缓存的清单文件的文件夹名称
/// </summary>
public const string ManifestFolderName = "ManifestFiles";
/// <summary>
/// 记录应用程序版本的文件名称
/// </summary>
public const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
/// <summary>
/// 构建输出文件夹名称
@ -47,10 +72,5 @@ namespace YooAsset
/// 构建输出的报告文件
/// </summary>
public const string ReportFileName = "BuildReport";
/// <summary>
/// 内置资源目录名称
/// </summary>
public const string StreamingAssetsBuildinFolder = "BuildinFiles";
}
}

View File

@ -253,48 +253,6 @@ namespace YooAsset
CacheSystem.InitVerifyLevel = verifyLevel;
}
/// <summary>
/// 设置缓存系统参数,沙盒目录的存储路径
/// </summary>
public static void SetCacheSystemBuildinPath(string buildinPath)
{
if (string.IsNullOrEmpty(buildinPath))
{
YooLogger.Error($"Buildin path is null or empty !");
return;
}
// 注意:需要确保没有任何资源系统起效之前才可以设置!
if (_packages.Count > 0)
{
YooLogger.Error($"Please call this method {nameof(SetCacheSystemBuildinPath)} before the package is created !");
return;
}
PersistentTools.OverwriteBuildinPath(buildinPath);
}
/// <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);
}
/// <summary>
/// 设置缓存系统参数禁用缓存在WebGL平台
/// </summary>
@ -304,33 +262,6 @@ namespace YooAsset
}
#endregion
#region 沙盒相关
/// <summary>
/// 获取内置文件夹名称
/// </summary>
public static string GetStreamingAssetBuildinFolderName()
{
return YooAssetSettings.StreamingAssetsBuildinFolder;
}
/// <summary>
/// 获取沙盒的根路径
/// </summary>
public static string GetSandboxRoot()
{
return PersistentTools.GetPersistentRootPath();
}
/// <summary>
/// 清空沙盒目录需要重启APP
/// </summary>
public static void ClearSandbox()
{
YooLogger.Warning("Clear sandbox folder files, Finally, restart the application !");
PersistentTools.DeleteSandbox();
}
#endregion
#region 调试信息
internal static DebugReport GetDebugReport()
{

View File

@ -20,6 +20,7 @@ namespace YooAsset.Editor
}
private string _manifestPath = string.Empty;
private string _packageName = "DefaultPackage";
private void OnGUI()
{
@ -39,7 +40,8 @@ namespace YooAsset.Editor
{
if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150)))
{
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
string streamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
EditorTools.ClearFolder(streamingAssetsRoot);
CopyPackageFiles(_manifestPath);
}
}
@ -57,18 +59,18 @@ namespace YooAsset.Editor
// 拷贝核心文件
{
string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.bytes";
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.bytes";
EditorTools.CopyFile(sourcePath, destPath, true);
}
{
string sourcePath = $"{outputDirectory}/{manifestFileName}.hash";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.hash";
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.hash";
EditorTools.CopyFile(sourcePath, destPath, true);
}
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName);
string sourcePath = $"{outputDirectory}/{fileName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{fileName}";
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{fileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
@ -78,7 +80,7 @@ namespace YooAsset.Editor
{
fileCount++;
string sourcePath = $"{outputDirectory}/{packageBundle.FileName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{packageBundle.FileName}";
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{packageBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}