Compare commits
30 Commits
1.4.6-prev
...
1.4.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39ffad6da6 | ||
|
|
13924fca13 | ||
|
|
438f006d1d | ||
|
|
6fb5626230 | ||
|
|
ab29069af5 | ||
|
|
fc3ed28eda | ||
|
|
46c9110b85 | ||
|
|
06b033ed36 | ||
|
|
ab96f3f28c | ||
|
|
295238cbb6 | ||
|
|
4f0f0e54ac | ||
|
|
a9a01b08dc | ||
|
|
c27a3e105c | ||
|
|
3cfc084e62 | ||
|
|
7c1873e861 | ||
|
|
c57c313dbe | ||
|
|
19cf9c0129 | ||
|
|
ebcb05cc55 | ||
|
|
7c4dbb1f38 | ||
|
|
091b46ccaf | ||
|
|
4da2bf441f | ||
|
|
365ed560f6 | ||
|
|
bcf6372602 | ||
|
|
a5e24be5d4 | ||
|
|
cdaf6f0dca | ||
|
|
e38d0bc6d0 | ||
|
|
eb16ba8365 | ||
|
|
3beb4f53d6 | ||
|
|
f8ba0c9753 | ||
|
|
0232e5adec |
@@ -2,6 +2,41 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.4.7] - 2023-03-03
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了在运行时资源引用链无效的问题。
|
||||
- 修复了在构建过程中发生异常后进度条未消失的问题。
|
||||
- 修复了使用SBP构建管线,如果有原生文件会导致打包失败的问题。
|
||||
|
||||
### Changed
|
||||
|
||||
- 支持自定义下载请求
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 设置下载系统参数,自定义下载请求
|
||||
/// </summary>
|
||||
public static void SetDownloadSystemUnityWebRequest(DownloadRequestDelegate requestDelegate)
|
||||
```
|
||||
|
||||
- 优化了打包时资源包引用关系计算的逻辑。
|
||||
|
||||
- 优化了缓存系统初始化逻辑,支持分帧获取所有缓存文件。
|
||||
|
||||
- 优化了缓存系统的存储目录结构,提高了文件夹查询速度。
|
||||
|
||||
- 优化了在资源收集界面,点击查看Collector主资源列表卡顿问题。
|
||||
|
||||
- 优化了资源对象加载耗时统计的逻辑,现在更加准确了。
|
||||
|
||||
- 优化了资源加载器查询逻辑。
|
||||
|
||||
- 优化了资源下载系统,下载文件的验证支持了多线程。
|
||||
|
||||
- 着色器变种收集界面增加单次照射数量的控制。
|
||||
|
||||
## [1.4.6-preview] - 2023-02-22
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -41,9 +41,9 @@ namespace YooAsset.Editor
|
||||
|
||||
// 是否显示LOG
|
||||
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
BuildRunner.EnableLog = false;
|
||||
BuildLogger.EnableLog = false;
|
||||
else
|
||||
BuildRunner.EnableLog = true;
|
||||
BuildLogger.EnableLog = true;
|
||||
|
||||
// 创建构建节点
|
||||
List<IBuildTask> pipeline;
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 加密服务类
|
||||
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
|
||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.Name).ToList();
|
||||
|
||||
// 输出目录
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
BuildRunner.Log($"发现未被依赖的资源并自动移除 : {dependAssetPath}");
|
||||
BuildLogger.Log($"发现未被依赖的资源并自动移除 : {dependAssetPath}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class BuildParametersContext : IContextObject
|
||||
{
|
||||
private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch();
|
||||
|
||||
private string _pipelineOutputDirectory = string.Empty;
|
||||
private string _packageOutputDirectory = string.Empty;
|
||||
|
||||
@@ -117,22 +115,5 @@ namespace YooAsset.Editor
|
||||
|
||||
return buildParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建的耗时(单位:秒)
|
||||
/// </summary>
|
||||
public float GetBuildingSeconds()
|
||||
{
|
||||
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
|
||||
return seconds;
|
||||
}
|
||||
public void BeginWatch()
|
||||
{
|
||||
_buildWatch.Start();
|
||||
}
|
||||
public void StopWatch()
|
||||
{
|
||||
_buildWatch.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string[] Tags;
|
||||
|
||||
/// <summary>
|
||||
/// 引用该资源包的ID列表
|
||||
/// </summary>
|
||||
public int[] ReferenceIDs;
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源分类标签的字符串
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public static class BuildLogger
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否启用LOG
|
||||
/// </summary>
|
||||
public static bool EnableLog = true;
|
||||
|
||||
/// <summary>
|
||||
/// 日志输出
|
||||
/// </summary>
|
||||
public static void Log(string info)
|
||||
{
|
||||
if (EnableLog)
|
||||
{
|
||||
UnityEngine.Debug.Log(info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日志输出
|
||||
/// </summary>
|
||||
public static void Info(string info)
|
||||
{
|
||||
UnityEngine.Debug.Log(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bc82466a51f50141975e4424095aa09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -2,13 +2,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class BuildRunner
|
||||
{
|
||||
public static bool EnableLog = true;
|
||||
private static Stopwatch _buildWatch;
|
||||
|
||||
/// <summary>
|
||||
/// 总耗时
|
||||
/// </summary>
|
||||
public static int TotalSeconds = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 执行构建流程
|
||||
@@ -23,17 +29,26 @@ namespace YooAsset.Editor
|
||||
|
||||
BuildResult buildResult = new BuildResult();
|
||||
buildResult.Success = true;
|
||||
TotalSeconds = 0;
|
||||
for (int i = 0; i < pipeline.Count; i++)
|
||||
{
|
||||
IBuildTask task = pipeline[i];
|
||||
try
|
||||
{
|
||||
_buildWatch = Stopwatch.StartNew();
|
||||
var taskAttribute = task.GetType().GetCustomAttribute<TaskAttribute>();
|
||||
Log($"---------------------------------------->{taskAttribute.Desc}<---------------------------------------");
|
||||
BuildLogger.Log($"---------------------------------------->{taskAttribute.Desc}<---------------------------------------");
|
||||
task.Run(context);
|
||||
_buildWatch.Stop();
|
||||
|
||||
// 统计耗时
|
||||
int seconds = GetBuildSeconds();
|
||||
TotalSeconds += seconds;
|
||||
BuildLogger.Log($"{taskAttribute.Desc}耗时:{seconds}秒");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
EditorTools.ClearProgressBar();
|
||||
buildResult.FailedTask = task.GetType().Name;
|
||||
buildResult.FailedInfo = e.ToString();
|
||||
buildResult.Success = false;
|
||||
@@ -42,26 +57,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 返回运行结果
|
||||
BuildLogger.Log($"构建过程总计耗时:{TotalSeconds}秒");
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日志输出
|
||||
/// </summary>
|
||||
public static void Log(string info)
|
||||
private static int GetBuildSeconds()
|
||||
{
|
||||
if (EnableLog)
|
||||
{
|
||||
UnityEngine.Debug.Log(info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日志输出
|
||||
/// </summary>
|
||||
public static void Info(string info)
|
||||
{
|
||||
UnityEngine.Debug.Log(info);
|
||||
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
|
||||
return (int)seconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace YooAsset.Editor
|
||||
throw new Exception("构建过程中发生严重错误!请查阅上下文日志!");
|
||||
}
|
||||
|
||||
BuildRunner.Log("Unity引擎打包成功!");
|
||||
BuildLogger.Log("Unity引擎打包成功!");
|
||||
BuildResultContext buildResultContext = new BuildResultContext();
|
||||
buildResultContext.UnityManifest = buildResults;
|
||||
context.SetContextObject(buildResultContext);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace YooAsset.Editor
|
||||
throw new Exception($"构建过程中发生错误 : {exitCode}");
|
||||
}
|
||||
|
||||
BuildRunner.Log("Unity引擎打包成功!");
|
||||
BuildLogger.Log("Unity引擎打包成功!");
|
||||
BuildResultContext buildResultContext = new BuildResultContext();
|
||||
buildResultContext.Results = buildResults;
|
||||
context.SetContextObject(buildResultContext);
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 刷新目录
|
||||
AssetDatabase.Refresh();
|
||||
BuildRunner.Log($"内置文件拷贝完成:{streamingAssetsDirectory}");
|
||||
BuildLogger.Log($"内置文件拷贝完成:{streamingAssetsDirectory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset.Editor
|
||||
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
var buildResultContext = context.GetContextObject<TaskBuilding.BuildResultContext>();
|
||||
UpdateBuiltinPipelineReference(patchManifest, buildResultContext, buildMapContext);
|
||||
UpdateBuiltinPipelineReference(patchManifest, buildResultContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace YooAsset.Editor
|
||||
string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
PatchManifestTools.SerializeToJson(filePath, patchManifest);
|
||||
BuildRunner.Log($"创建补丁清单文件:{filePath}");
|
||||
BuildLogger.Log($"创建补丁清单文件:{filePath}");
|
||||
}
|
||||
|
||||
// 创建补丁清单二进制文件
|
||||
@@ -86,7 +86,7 @@ namespace YooAsset.Editor
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
PatchManifestTools.SerializeToBinary(filePath, patchManifest);
|
||||
packageHash = HashUtility.FileMD5(filePath);
|
||||
BuildRunner.Log($"创建补丁清单文件:{filePath}");
|
||||
BuildLogger.Log($"创建补丁清单文件:{filePath}");
|
||||
|
||||
PatchManifestContext patchManifestContext = new PatchManifestContext();
|
||||
byte[] bytesData = FileUtility.ReadAllBytes(filePath);
|
||||
@@ -99,7 +99,7 @@ namespace YooAsset.Editor
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
FileUtility.CreateFile(filePath, packageHash);
|
||||
BuildRunner.Log($"创建补丁清单哈希文件:{filePath}");
|
||||
BuildLogger.Log($"创建补丁清单哈希文件:{filePath}");
|
||||
}
|
||||
|
||||
// 创建补丁清单版本文件
|
||||
@@ -107,7 +107,7 @@ namespace YooAsset.Editor
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildParameters.PackageName);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
FileUtility.CreateFile(filePath, buildParameters.PackageVersion);
|
||||
BuildRunner.Log($"创建补丁清单版本文件:{filePath}");
|
||||
BuildLogger.Log($"创建补丁清单版本文件:{filePath}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,30 +231,99 @@ namespace YooAsset.Editor
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新资源包之间的引用关系
|
||||
/// </summary>
|
||||
#region 资源包引用关系相关
|
||||
private readonly Dictionary<string, int> _cachedBundleID = new Dictionary<string, int>(10000);
|
||||
private readonly Dictionary<string, string[]> _cachedBundleDepends = new Dictionary<string, string[]>(10000);
|
||||
|
||||
private void UpdateScriptPipelineReference(PatchManifest patchManifest, TaskBuilding_SBP.BuildResultContext buildResultContext)
|
||||
{
|
||||
int progressValue;
|
||||
int totalCount = patchManifest.BundleList.Count;
|
||||
|
||||
// 缓存资源包ID
|
||||
_cachedBundleID.Clear();
|
||||
progressValue = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
patchBundle.ReferenceIDs = GetScriptPipelineRefrenceIDs(patchManifest, patchBundle, buildResultContext);
|
||||
}
|
||||
}
|
||||
private int[] GetScriptPipelineRefrenceIDs(PatchManifest patchManifest, PatchBundle patchBundle, TaskBuilding_SBP.BuildResultContext buildResultContext)
|
||||
{
|
||||
if (buildResultContext.Results.BundleInfos.TryGetValue(patchBundle.BundleName, out var details) == false)
|
||||
{
|
||||
throw new Exception("Should never get here !");
|
||||
int bundleID = GetAssetBundleID(patchBundle.BundleName, patchManifest);
|
||||
_cachedBundleID.Add(patchBundle.BundleName, bundleID);
|
||||
EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
List<string> referenceList = new List<string>();
|
||||
foreach (var keyValuePair in buildResultContext.Results.BundleInfos)
|
||||
// 缓存资源包依赖
|
||||
_cachedBundleDepends.Clear();
|
||||
progressValue = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
string bundleName = keyValuePair.Key;
|
||||
if (bundleName == patchBundle.BundleName)
|
||||
if (patchBundle.IsRawFile)
|
||||
continue;
|
||||
if (keyValuePair.Value.Dependencies.Contains(patchBundle.BundleName))
|
||||
|
||||
if (buildResultContext.Results.BundleInfos.ContainsKey(patchBundle.BundleName) == false)
|
||||
throw new Exception($"Not found bundle in SBP build results : {patchBundle.BundleName}");
|
||||
|
||||
var depends = buildResultContext.Results.BundleInfos[patchBundle.BundleName].Dependencies;
|
||||
_cachedBundleDepends.Add(patchBundle.BundleName, depends);
|
||||
EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
// 计算资源包引用列表
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
patchBundle.ReferenceIDs = GetBundleRefrenceIDs(patchManifest, patchBundle);
|
||||
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
}
|
||||
private void UpdateBuiltinPipelineReference(PatchManifest patchManifest, TaskBuilding.BuildResultContext buildResultContext)
|
||||
{
|
||||
int progressValue;
|
||||
int totalCount = patchManifest.BundleList.Count;
|
||||
|
||||
// 缓存资源包ID
|
||||
_cachedBundleID.Clear();
|
||||
progressValue = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
int bundleID = GetAssetBundleID(patchBundle.BundleName, patchManifest);
|
||||
_cachedBundleID.Add(patchBundle.BundleName, bundleID);
|
||||
EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
// 缓存资源包依赖
|
||||
_cachedBundleDepends.Clear();
|
||||
progressValue = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
var depends = buildResultContext.UnityManifest.GetDirectDependencies(patchBundle.BundleName);
|
||||
_cachedBundleDepends.Add(patchBundle.BundleName, depends);
|
||||
EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
// 计算资源包引用列表
|
||||
progressValue = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
patchBundle.ReferenceIDs = GetBundleRefrenceIDs(patchManifest, patchBundle);
|
||||
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
}
|
||||
|
||||
private int[] GetBundleRefrenceIDs(PatchManifest patchManifest, PatchBundle targetBundle)
|
||||
{
|
||||
List<string> referenceList = new List<string>();
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
string bundleName = patchBundle.BundleName;
|
||||
if (bundleName == targetBundle.BundleName)
|
||||
continue;
|
||||
|
||||
string[] dependencies = GetCachedBundleDepends(bundleName);
|
||||
if (dependencies.Contains(targetBundle.BundleName))
|
||||
{
|
||||
referenceList.Add(bundleName);
|
||||
}
|
||||
@@ -263,46 +332,28 @@ namespace YooAsset.Editor
|
||||
List<int> result = new List<int>();
|
||||
foreach (var bundleName in referenceList)
|
||||
{
|
||||
int bundleID = GetAssetBundleID(bundleName, patchManifest);
|
||||
int bundleID = GetCachedBundleID(bundleName);
|
||||
if (result.Contains(bundleID) == false)
|
||||
result.Add(bundleID);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新资源包之间的引用关系
|
||||
/// </summary>
|
||||
private void UpdateBuiltinPipelineReference(PatchManifest patchManifest, TaskBuilding.BuildResultContext buildResultContext, BuildMapContext buildMapContext)
|
||||
private int GetCachedBundleID(string bundleName)
|
||||
{
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
if (_cachedBundleID.TryGetValue(bundleName, out int value) == false)
|
||||
{
|
||||
patchBundle.ReferenceIDs = GetBuiltinPipelineRefrenceIDs(patchManifest, patchBundle, buildResultContext, buildMapContext);
|
||||
throw new Exception($"Not found cached bundle ID : {bundleName}");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
private int[] GetBuiltinPipelineRefrenceIDs(PatchManifest patchManifest, PatchBundle patchBundle, TaskBuilding.BuildResultContext buildResultContext, BuildMapContext buildMapContext)
|
||||
private string[] GetCachedBundleDepends(string bundleName)
|
||||
{
|
||||
List<string> referenceList = new List<string>();
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
if (_cachedBundleDepends.TryGetValue(bundleName, out string[] value) == false)
|
||||
{
|
||||
string bundleName = bundleInfo.BundleName;
|
||||
if (bundleName == patchBundle.BundleName)
|
||||
continue;
|
||||
string[] dependencies = buildResultContext.UnityManifest.GetAllDependencies(bundleName);
|
||||
if (dependencies.Contains(patchBundle.BundleName))
|
||||
{
|
||||
referenceList.Add(bundleName);
|
||||
}
|
||||
throw new Exception($"Not found cached bundle depends : {bundleName}");
|
||||
}
|
||||
|
||||
List<int> result = new List<int>();
|
||||
foreach (var bundleName in referenceList)
|
||||
{
|
||||
int bundleID = GetAssetBundleID(bundleName, patchManifest);
|
||||
if (result.Contains(bundleID) == false)
|
||||
result.Add(bundleID);
|
||||
}
|
||||
return result.ToArray();
|
||||
return value;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace YooAsset.Editor
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageOutputDirectory}");
|
||||
BuildLogger.Log($"开始拷贝补丁文件到补丁包目录:{packageOutputDirectory}");
|
||||
|
||||
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
|
||||
@@ -13,16 +13,12 @@ namespace YooAsset.Editor
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var patchManifestContext = context.GetContextObject<PatchManifestContext>();
|
||||
buildParameters.StopWatch();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
CreateReportFile(buildParameters, buildMapContext, patchManifestContext);
|
||||
}
|
||||
|
||||
float buildSeconds = buildParameters.GetBuildingSeconds();
|
||||
BuildRunner.Info($"Build time consuming {buildSeconds} seconds.");
|
||||
}
|
||||
|
||||
private void CreateReportFile(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext, PatchManifestContext patchManifestContext)
|
||||
@@ -42,7 +38,7 @@ namespace YooAsset.Editor
|
||||
#endif
|
||||
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
|
||||
buildReport.Summary.BuildDate = DateTime.Now.ToString();
|
||||
buildReport.Summary.BuildSeconds = (int)buildParametersContext.GetBuildingSeconds();
|
||||
buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds;
|
||||
buildReport.Summary.BuildTarget = buildParameters.BuildTarget;
|
||||
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
|
||||
buildReport.Summary.BuildMode = buildParameters.BuildMode;
|
||||
@@ -98,6 +94,7 @@ namespace YooAsset.Editor
|
||||
reportBundleInfo.FileCRC = patchBundle.FileCRC;
|
||||
reportBundleInfo.FileSize = patchBundle.FileSize;
|
||||
reportBundleInfo.Tags = patchBundle.Tags;
|
||||
reportBundleInfo.ReferenceIDs = patchBundle.ReferenceIDs;
|
||||
reportBundleInfo.IsRawFile = patchBundle.IsRawFile;
|
||||
reportBundleInfo.LoadMethod = (EBundleLoadMethod)patchBundle.LoadMethod;
|
||||
buildReport.BundleInfos.Add(reportBundleInfo);
|
||||
@@ -107,7 +104,7 @@ namespace YooAsset.Editor
|
||||
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
BuildReport.Serialize(filePath, buildReport);
|
||||
BuildRunner.Log($"资源构建报告文件创建完成:{filePath}");
|
||||
BuildLogger.Log($"资源构建报告文件创建完成:{filePath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -27,17 +27,16 @@ namespace YooAsset.Editor
|
||||
private void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
{
|
||||
var encryptionServices = buildParametersContext.Parameters.EncryptionServices;
|
||||
|
||||
// 如果没有设置加密类
|
||||
if (encryptionServices == null)
|
||||
return;
|
||||
|
||||
if (encryptionServices.GetType() == typeof(EncryptionNone))
|
||||
return;
|
||||
|
||||
int progressValue = 0;
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
bundleInfo.LoadMethod = EBundleLoadMethod.Normal;
|
||||
|
||||
EncryptFileInfo fileInfo = new EncryptFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.BundleName;
|
||||
fileInfo.FilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
@@ -56,7 +55,7 @@ namespace YooAsset.Editor
|
||||
FileUtility.CreateFile(filePath, encryptResult.EncryptedData);
|
||||
bundleInfo.EncryptedFilePath = filePath;
|
||||
bundleInfo.LoadMethod = encryptResult.LoadMethod;
|
||||
BuildRunner.Log($"Bundle文件加密完成:{filePath}");
|
||||
BuildLogger.Log($"Bundle文件加密完成:{filePath}");
|
||||
}
|
||||
|
||||
// 进度条
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace YooAsset.Editor
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.PackageName);
|
||||
context.SetContextObject(buildMapContext);
|
||||
BuildRunner.Log("构建内容准备完毕!");
|
||||
BuildLogger.Log("构建内容准备完毕!");
|
||||
|
||||
// 检测构建结果
|
||||
CheckBuildMapContent(buildMapContext);
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
buildParametersContext.BeginWatch();
|
||||
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
|
||||
// 检测构建参数合法性
|
||||
@@ -57,7 +55,7 @@ namespace YooAsset.Editor
|
||||
string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.PackageName}/{buildParameters.BuildTarget}";
|
||||
if (EditorTools.DeleteDirectory(platformDirectory))
|
||||
{
|
||||
BuildRunner.Log($"删除平台总目录:{platformDirectory}");
|
||||
BuildLogger.Log($"删除平台总目录:{platformDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +63,7 @@ namespace YooAsset.Editor
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
|
||||
{
|
||||
BuildRunner.Log($"创建输出目录:{pipelineOutputDirectory}");
|
||||
BuildLogger.Log($"创建输出目录:{pipelineOutputDirectory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
*/
|
||||
|
||||
BuildRunner.Log("构建结果验证成功!");
|
||||
BuildLogger.Log("构建结果验证成功!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace YooAsset.Editor
|
||||
throw new System.Exception("存在差异资源包!请查看警告信息!");
|
||||
}
|
||||
|
||||
BuildRunner.Log("构建结果验证成功!");
|
||||
BuildLogger.Log("构建结果验证成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class EncryptionNone : IEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46b8b200b841799498896403d9d427c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -794,7 +794,7 @@ namespace YooAsset.Editor
|
||||
|
||||
try
|
||||
{
|
||||
CollectCommand command = new CollectCommand(EBuildMode.DryRunBuild, _packageNameTxt.value, _enableAddressableToogle.value, _uniqueBundleNameToogle.value);
|
||||
CollectCommand command = new CollectCommand(EBuildMode.SimulateBuild, _packageNameTxt.value, _enableAddressableToogle.value, _uniqueBundleNameToogle.value);
|
||||
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
@@ -812,12 +812,7 @@ namespace YooAsset.Editor
|
||||
|
||||
string showInfo = collectAssetInfo.AssetPath;
|
||||
if (_enableAddressableToogle.value)
|
||||
{
|
||||
IAddressRule instance = AssetBundleCollectorSettingData.GetAddressRuleInstance(collector.AddressRuleName);
|
||||
AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName, collector.UserData);
|
||||
string addressValue = instance.GetAssetAddress(ruleData);
|
||||
showInfo = $"[{addressValue}] {showInfo}";
|
||||
}
|
||||
showInfo = $"[{collectAssetInfo.Address}] {collectAssetInfo.AssetPath}";
|
||||
|
||||
var label = new Label();
|
||||
label.text = showInfo;
|
||||
|
||||
@@ -13,5 +13,10 @@ namespace YooAsset.Editor
|
||||
/// 收集的包裹名称
|
||||
/// </summary>
|
||||
public string CollectPackage = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 容器值
|
||||
/// </summary>
|
||||
public int ProcessCapacity = 1000;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ namespace YooAsset.Editor
|
||||
private TextField _collectOutputField;
|
||||
private Label _currentShaderCountField;
|
||||
private Label _currentVariantCountField;
|
||||
private SliderInt _processCapacitySlider;
|
||||
private PopupField<string> _packageField;
|
||||
|
||||
public void CreateGUI()
|
||||
@@ -72,6 +73,23 @@ namespace YooAsset.Editor
|
||||
packageContainer.Add(_packageField);
|
||||
}
|
||||
|
||||
// 容器值
|
||||
_processCapacitySlider = root.Q<SliderInt>("ProcessCapacity");
|
||||
_processCapacitySlider.SetValueWithoutNotify(ShaderVariantCollectorSettingData.Setting.ProcessCapacity);
|
||||
#if !UNITY_2020_3_OR_NEWER
|
||||
_processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})";
|
||||
_processCapacitySlider.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
ShaderVariantCollectorSettingData.Setting.ProcessCapacity = _processCapacitySlider.value;
|
||||
_processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})";
|
||||
});
|
||||
#else
|
||||
_processCapacitySlider.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
ShaderVariantCollectorSettingData.Setting.ProcessCapacity = _processCapacitySlider.value;
|
||||
});
|
||||
#endif
|
||||
|
||||
_currentShaderCountField = root.Q<Label>("CurrentShaderCount");
|
||||
_currentVariantCountField = root.Q<Label>("CurrentVariantCount");
|
||||
|
||||
@@ -103,7 +121,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string savePath = ShaderVariantCollectorSettingData.Setting.SavePath;
|
||||
string packageName = ShaderVariantCollectorSettingData.Setting.CollectPackage;
|
||||
ShaderVariantCollector.Run(savePath, packageName, int.MaxValue, null);
|
||||
int processCapacity = _processCapacitySlider.value;
|
||||
ShaderVariantCollector.Run(savePath, packageName, processCapacity, null);
|
||||
}
|
||||
|
||||
// 构建包裹相关
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
|
||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;" />
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:VisualElement name="CollectContainer">
|
||||
<ui:TextField picking-mode="Ignore" label="文件保存路径" name="CollectOutput" style="height: 22px;" />
|
||||
<ui:VisualElement name="PackageContainer" style="height: 24px;" />
|
||||
<ui:VisualElement name="PackageContainer" style="height: 24px;">
|
||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;" />
|
||||
</ui:VisualElement>
|
||||
<ui:Label text="Current Shader Count" display-tooltip-when-elided="true" name="CurrentShaderCount" style="height: 20px; padding-left: 4px;" />
|
||||
<ui:Label text="Current Variant Count" display-tooltip-when-elided="true" name="CurrentVariantCount" style="height: 20px; padding-left: 4px;" />
|
||||
<ui:SliderInt picking-mode="Ignore" label="Capacity" value="9999" high-value="1000" name="ProcessCapacity" low-value="10" show-input-field="true" />
|
||||
<ui:Button text="开始搜集" display-tooltip-when-elided="true" name="CollectButton" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
|
||||
@@ -8,11 +8,16 @@ namespace YooAsset
|
||||
{
|
||||
internal class AssetSystemImpl
|
||||
{
|
||||
private readonly List<BundleLoaderBase> _loaders = new List<BundleLoaderBase>(1000);
|
||||
private readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
|
||||
private readonly Dictionary<string, BundleLoaderBase> _loaderDic = new Dictionary<string, BundleLoaderBase>(5000);
|
||||
private readonly List<BundleLoaderBase> _loaderList = new List<BundleLoaderBase>(5000);
|
||||
|
||||
private readonly Dictionary<string, ProviderBase> _providerDic = new Dictionary<string, ProviderBase>(5000);
|
||||
private readonly List<ProviderBase> _providerList = new List<ProviderBase>(5000);
|
||||
|
||||
private readonly static Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
||||
private static long _sceneCreateCount = 0;
|
||||
|
||||
private bool _isUnloadSafe = true;
|
||||
private string _packageName;
|
||||
private bool _simulationOnEditor;
|
||||
private int _loadingMaxNumber;
|
||||
@@ -39,7 +44,7 @@ namespace YooAsset
|
||||
public void Update()
|
||||
{
|
||||
// 更新加载器
|
||||
foreach (var loader in _loaders)
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.Update();
|
||||
}
|
||||
@@ -47,10 +52,11 @@ namespace YooAsset
|
||||
// 更新资源提供者
|
||||
// 注意:循环更新的时候,可能会扩展列表
|
||||
// 注意:不能限制场景对象的加载
|
||||
_isUnloadSafe = false;
|
||||
int loadingCount = 0;
|
||||
for (int i = 0; i < _providers.Count; i++)
|
||||
for (int i = 0; i < _providerList.Count; i++)
|
||||
{
|
||||
var provider = _providers[i];
|
||||
var provider = _providerList[i];
|
||||
if (provider.IsSceneProvider())
|
||||
{
|
||||
provider.Update();
|
||||
@@ -64,6 +70,7 @@ namespace YooAsset
|
||||
loadingCount++;
|
||||
}
|
||||
}
|
||||
_isUnloadSafe = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -71,17 +78,19 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void DestroyAll()
|
||||
{
|
||||
foreach (var provider in _providers)
|
||||
foreach (var provider in _providerList)
|
||||
{
|
||||
provider.Destroy();
|
||||
}
|
||||
_providers.Clear();
|
||||
_providerList.Clear();
|
||||
_providerDic.Clear();
|
||||
|
||||
foreach (var loader in _loaders)
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.Destroy(true);
|
||||
}
|
||||
_loaders.Clear();
|
||||
_loaderList.Clear();
|
||||
_loaderDic.Clear();
|
||||
|
||||
ClearSceneHandle();
|
||||
DecryptionServices = null;
|
||||
@@ -93,6 +102,12 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void UnloadUnusedAssets()
|
||||
{
|
||||
if (_isUnloadSafe == false)
|
||||
{
|
||||
YooLogger.Warning("Can not unload unused assets when processing resource loading !");
|
||||
return;
|
||||
}
|
||||
|
||||
// 注意:资源包之间可能存在多层深层嵌套,需要多次循环释放。
|
||||
int loopCount = 10;
|
||||
for (int i = 0; i < loopCount; i++)
|
||||
@@ -104,29 +119,33 @@ namespace YooAsset
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
{
|
||||
for (int i = _providers.Count - 1; i >= 0; i--)
|
||||
for (int i = _providerList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (_providers[i].CanDestroy())
|
||||
var provider = _providerList[i];
|
||||
if (provider.CanDestroy())
|
||||
{
|
||||
_providers[i].Destroy();
|
||||
_providers.RemoveAt(i);
|
||||
provider.Destroy();
|
||||
_providerList.RemoveAt(i);
|
||||
_providerDic.Remove(provider.ProviderGUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = _loaders.Count - 1; i >= 0; i--)
|
||||
for (int i = _loaderList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
BundleLoaderBase loader = _loaders[i];
|
||||
BundleLoaderBase loader = _loaderList[i];
|
||||
loader.TryDestroyAllProviders();
|
||||
}
|
||||
for (int i = _loaders.Count - 1; i >= 0; i--)
|
||||
for (int i = _loaderList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
BundleLoaderBase loader = _loaders[i];
|
||||
BundleLoaderBase loader = _loaderList[i];
|
||||
if (loader.CanDestroy())
|
||||
{
|
||||
string bundleName = loader.MainBundleInfo.Bundle.BundleName;
|
||||
loader.Destroy(false);
|
||||
_loaders.RemoveAt(i);
|
||||
_loaderList.RemoveAt(i);
|
||||
_loaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,17 +156,19 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void ForceUnloadAllAssets()
|
||||
{
|
||||
foreach (var provider in _providers)
|
||||
foreach (var provider in _providerList)
|
||||
{
|
||||
provider.Destroy();
|
||||
}
|
||||
foreach (var loader in _loaders)
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.Destroy(true);
|
||||
}
|
||||
|
||||
_providers.Clear();
|
||||
_loaders.Clear();
|
||||
_providerList.Clear();
|
||||
_providerDic.Clear();
|
||||
_loaderList.Clear();
|
||||
_loaderDic.Clear();
|
||||
ClearSceneHandle();
|
||||
|
||||
// 注意:调用底层接口释放所有资源
|
||||
@@ -182,7 +203,8 @@ namespace YooAsset
|
||||
else
|
||||
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, activateOnLoad, priority);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
_providerList.Add(provider);
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
}
|
||||
|
||||
var handle = provider.CreateHandle<SceneOperationHandle>();
|
||||
@@ -213,7 +235,8 @@ namespace YooAsset
|
||||
else
|
||||
provider = new BundledAssetProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
_providerList.Add(provider);
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
}
|
||||
return provider.CreateHandle<AssetOperationHandle>();
|
||||
}
|
||||
@@ -240,7 +263,8 @@ namespace YooAsset
|
||||
else
|
||||
provider = new BundledSubAssetsProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
_providerList.Add(provider);
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
}
|
||||
return provider.CreateHandle<SubAssetsOperationHandle>();
|
||||
}
|
||||
@@ -267,7 +291,8 @@ namespace YooAsset
|
||||
else
|
||||
provider = new BundledRawFileProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
_providerList.Add(provider);
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
}
|
||||
return provider.CreateHandle<RawFileOperationHandle>();
|
||||
}
|
||||
@@ -338,22 +363,24 @@ namespace YooAsset
|
||||
{
|
||||
foreach (var provider in providers)
|
||||
{
|
||||
_providers.Remove(provider);
|
||||
_providerList.Remove(provider);
|
||||
_providerDic.Remove(provider.ProviderGUID);
|
||||
}
|
||||
}
|
||||
internal bool CheckBundleCanDestroy(int bundleID)
|
||||
internal bool CheckBundleDestroyed(int bundleID)
|
||||
{
|
||||
string bundleName = BundleServices.GetBundleName(bundleID);
|
||||
BundleLoaderBase loader = TryGetAssetBundleLoader(bundleName);
|
||||
if (loader == null)
|
||||
return true;
|
||||
return loader.CanDestroy();
|
||||
return loader.IsDestroyed;
|
||||
}
|
||||
|
||||
private BundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
|
||||
{
|
||||
// 如果加载器已经存在
|
||||
BundleLoaderBase loader = TryGetAssetBundleLoader(bundleInfo.Bundle.BundleName);
|
||||
string bundleName = bundleInfo.Bundle.BundleName;
|
||||
BundleLoaderBase loader = TryGetAssetBundleLoader(bundleName);
|
||||
if (loader != null)
|
||||
return loader;
|
||||
|
||||
@@ -370,43 +397,30 @@ namespace YooAsset
|
||||
loader = new AssetBundleFileLoader(this, bundleInfo);
|
||||
#endif
|
||||
|
||||
_loaders.Add(loader);
|
||||
_loaderList.Add(loader);
|
||||
_loaderDic.Add(bundleName, loader);
|
||||
return loader;
|
||||
}
|
||||
private BundleLoaderBase TryGetAssetBundleLoader(string bundleName)
|
||||
{
|
||||
BundleLoaderBase loader = null;
|
||||
for (int i = 0; i < _loaders.Count; i++)
|
||||
{
|
||||
BundleLoaderBase temp = _loaders[i];
|
||||
if (temp.MainBundleInfo.Bundle.BundleName.Equals(bundleName))
|
||||
{
|
||||
loader = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return loader;
|
||||
if (_loaderDic.TryGetValue(bundleName, out BundleLoaderBase value))
|
||||
return value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
private ProviderBase TryGetProvider(string providerGUID)
|
||||
{
|
||||
ProviderBase provider = null;
|
||||
for (int i = 0; i < _providers.Count; i++)
|
||||
{
|
||||
ProviderBase temp = _providers[i];
|
||||
if (temp.ProviderGUID.Equals(providerGUID))
|
||||
{
|
||||
provider = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
if (_providerDic.TryGetValue(providerGUID, out ProviderBase value))
|
||||
return value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
internal List<DebugProviderInfo> GetDebugReportInfos()
|
||||
{
|
||||
List<DebugProviderInfo> result = new List<DebugProviderInfo>(_providers.Count);
|
||||
foreach (var provider in _providers)
|
||||
List<DebugProviderInfo> result = new List<DebugProviderInfo>(_providerList.Count);
|
||||
foreach (var provider in _providerList)
|
||||
{
|
||||
DebugProviderInfo providerInfo = new DebugProviderInfo();
|
||||
providerInfo.AssetPath = provider.MainAssetInfo.AssetPath;
|
||||
@@ -429,9 +443,9 @@ namespace YooAsset
|
||||
internal List<BundleInfo> GetLoadedBundleInfos()
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>(100);
|
||||
foreach (var bundleLoader in _loaders)
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
result.Add(bundleLoader.MainBundleInfo);
|
||||
result.Add(loader.MainBundleInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,18 @@ namespace YooAsset
|
||||
if (IsDone() == false)
|
||||
return false;
|
||||
|
||||
return RefCount <= 0;
|
||||
if (RefCount > 0)
|
||||
return false;
|
||||
|
||||
// 检查引用链上的资源包是否已经全部销毁
|
||||
// 注意:互相引用的资源包无法卸载!
|
||||
foreach (var bundleID in MainBundleInfo.Bundle.ReferenceIDs)
|
||||
{
|
||||
if (Impl.CheckBundleDestroyed(bundleID) == false)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -122,24 +133,15 @@ namespace YooAsset
|
||||
if (RefCount > _providers.Count)
|
||||
return;
|
||||
|
||||
// 条件3:检查依赖链上的资源包
|
||||
// 依赖该资源包的所有资源包可以销毁
|
||||
// 注意:互相引用的资源包无法卸载!
|
||||
foreach (var bundleID in MainBundleInfo.Bundle.ReferenceIDs)
|
||||
{
|
||||
if (Impl.CheckBundleCanDestroy(bundleID) == false)
|
||||
return;
|
||||
}
|
||||
|
||||
// 销毁所有Providers
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
provider.Destroy();
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
provider.Destroy();
|
||||
}
|
||||
Impl.RemoveBundleProviders(_providers);
|
||||
_providers.Clear();
|
||||
}
|
||||
|
||||
// 从列表里移除Providers
|
||||
Impl.RemoveBundleProviders(_providers);
|
||||
_providers.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
DebugBeginRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace YooAsset
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
DebugBeginRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace YooAsset
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
DebugBeginRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
DebugBeginRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
@@ -221,6 +221,8 @@ namespace YooAsset
|
||||
private TaskCompletionSource<object> _taskCompletionSource;
|
||||
protected void InvokeCompletion()
|
||||
{
|
||||
DebugEndRecording();
|
||||
|
||||
// 进度百分百完成
|
||||
Progress = 1f;
|
||||
|
||||
@@ -256,8 +258,7 @@ namespace YooAsset
|
||||
public long LoadingTime { protected set; get; }
|
||||
|
||||
// 加载耗时统计
|
||||
private bool _isRecording = false;
|
||||
private Stopwatch _watch;
|
||||
private Stopwatch _watch = null;
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public void InitSpawnDebugInfo()
|
||||
@@ -274,21 +275,21 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
protected void DebugRecording()
|
||||
protected void DebugBeginRecording()
|
||||
{
|
||||
if (_isRecording == false)
|
||||
if (_watch == null)
|
||||
{
|
||||
_isRecording = true;
|
||||
_watch = Stopwatch.StartNew();
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugEndRecording()
|
||||
{
|
||||
if (_watch != null)
|
||||
{
|
||||
if (IsDone)
|
||||
{
|
||||
LoadingTime = _watch.ElapsedMilliseconds;
|
||||
_watch = null;
|
||||
}
|
||||
LoadingTime = _watch.ElapsedMilliseconds;
|
||||
_watch = null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -23,6 +23,15 @@ namespace YooAsset
|
||||
_cachedDic.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存文件总数
|
||||
/// </summary>
|
||||
public static int GetCachedFilesCount(string packageName)
|
||||
{
|
||||
var cache = GetOrCreateCache(packageName);
|
||||
return cache.GetCachedFilesCount();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询是否为验证文件
|
||||
/// </summary>
|
||||
@@ -70,7 +79,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 验证缓存文件(子线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingCacheFile(VerifyElement element)
|
||||
public static EVerifyResult VerifyingCacheFile(VerifyCacheElement element)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -100,15 +109,15 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证下载文件
|
||||
/// 验证下载文件(子线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingTempFile(PatchBundle patchBundle)
|
||||
public static EVerifyResult VerifyingTempFile(VerifyTempElement element)
|
||||
{
|
||||
return VerifyingInternal(patchBundle.TempDataFilePath, patchBundle.FileSize, patchBundle.FileCRC, EVerifyLevel.High);
|
||||
return VerifyingInternal(element.TempDataFilePath, element.FileSize, element.FileCRC, EVerifyLevel.High);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 验证记录文件
|
||||
/// 验证记录文件(主线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingRecordFile(string packageName, string cacheGUID)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a93a516506b2b5c4492fdefe26eb1175
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class FindCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
FindPrepare,
|
||||
FindBundleFiles,
|
||||
FindRawFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private float _verifyStartTime;
|
||||
private IEnumerator<DirectoryInfo> _bundleFilesEnumerator = null;
|
||||
private IEnumerator<DirectoryInfo> _rawFilesEnumerator = null;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 需要验证的元素
|
||||
/// </summary>
|
||||
public readonly List<VerifyCacheElement> VerifyElements = new List<VerifyCacheElement>(5000);
|
||||
|
||||
public FindCacheFilesOperation(string packageName)
|
||||
{
|
||||
_packageName = packageName;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.FindPrepare;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.FindPrepare)
|
||||
{
|
||||
// BundleFiles
|
||||
{
|
||||
string rootPath = PersistentHelper.GetCachedBundleFileFolderPath(_packageName);
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
var directorieInfos = rootDirectory.EnumerateDirectories();
|
||||
_bundleFilesEnumerator = directorieInfos.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
// RawFiles
|
||||
{
|
||||
string rootPath = PersistentHelper.GetCachedRawFileFolderPath(_packageName);
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
var directorieInfos = rootDirectory.EnumerateDirectories();
|
||||
_rawFilesEnumerator = directorieInfos.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.FindBundleFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.FindBundleFiles)
|
||||
{
|
||||
if (UpdateFindBundleFiles())
|
||||
return;
|
||||
|
||||
_steps = ESteps.FindRawFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.FindRawFiles)
|
||||
{
|
||||
if (UpdateFindRawFiles())
|
||||
return;
|
||||
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Find cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
}
|
||||
|
||||
private bool UpdateFindBundleFiles()
|
||||
{
|
||||
if (_bundleFilesEnumerator == null)
|
||||
return false;
|
||||
|
||||
bool isFindItem;
|
||||
while (true)
|
||||
{
|
||||
isFindItem = _bundleFilesEnumerator.MoveNext();
|
||||
if (isFindItem == false)
|
||||
break;
|
||||
|
||||
var rootFoder = _bundleFilesEnumerator.Current;
|
||||
var childDirectories = rootFoder.GetDirectories();
|
||||
foreach(var chidDirectory in childDirectories)
|
||||
{
|
||||
string cacheGUID = chidDirectory.Name;
|
||||
if (CacheSystem.IsCached(_packageName, cacheGUID))
|
||||
continue;
|
||||
|
||||
// 创建验证元素类
|
||||
string fileRootPath = chidDirectory.FullName;
|
||||
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}";
|
||||
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
|
||||
VerifyCacheElement element = new VerifyCacheElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
|
||||
VerifyElements.Add(element);
|
||||
}
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
return isFindItem;
|
||||
}
|
||||
private bool UpdateFindRawFiles()
|
||||
{
|
||||
if (_rawFilesEnumerator == null)
|
||||
return false;
|
||||
|
||||
bool isFindItem;
|
||||
while (true)
|
||||
{
|
||||
isFindItem = _rawFilesEnumerator.MoveNext();
|
||||
if (isFindItem == false)
|
||||
break;
|
||||
|
||||
var rootFoder = _rawFilesEnumerator.Current;
|
||||
var childDirectories = rootFoder.GetDirectories();
|
||||
foreach (var chidDirectory in childDirectories)
|
||||
{
|
||||
string cacheGUID = chidDirectory.Name;
|
||||
if (CacheSystem.IsCached(_packageName, cacheGUID))
|
||||
continue;
|
||||
|
||||
// 获取数据文件的后缀名
|
||||
string dataFileExtension = string.Empty;
|
||||
var fileInfos = chidDirectory.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Extension == ".temp")
|
||||
continue;
|
||||
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
|
||||
{
|
||||
dataFileExtension = fileInfo.Extension;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建验证元素类
|
||||
string fileRootPath = chidDirectory.FullName;
|
||||
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}{dataFileExtension}";
|
||||
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
|
||||
VerifyCacheElement element = new VerifyCacheElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
|
||||
VerifyElements.Add(element);
|
||||
}
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
return isFindItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00ec004354d75ac499606d6959192f9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,14 +6,14 @@ using System.Threading;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class PackageVerifyOperation : AsyncOperationBase
|
||||
internal abstract class VerifyCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
public static PackageVerifyOperation CreateOperation(List<VerifyElement> elements)
|
||||
public static VerifyCacheFilesOperation CreateOperation(List<VerifyCacheElement> elements)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
var operation = new PackageVerifyWithoutThreadOperation(elements);
|
||||
var operation = new VerifyCacheFilesWithoutThreadOperation(elements);
|
||||
#else
|
||||
var operation = new PackageVerifyWithThreadOperation(elements);
|
||||
var operation = new VerifyCacheFilesWithThreadOperation(elements);
|
||||
#endif
|
||||
return operation;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(线程版)
|
||||
/// </summary>
|
||||
internal class PackageVerifyWithThreadOperation : PackageVerifyOperation
|
||||
internal class VerifyCacheFilesWithThreadOperation : VerifyCacheFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
@@ -33,8 +33,8 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||
private List<VerifyElement> _waitingList;
|
||||
private List<VerifyElement> _verifyingList;
|
||||
private List<VerifyCacheElement> _waitingList;
|
||||
private List<VerifyCacheElement> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
@@ -42,7 +42,7 @@ namespace YooAsset
|
||||
private int _failedCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public PackageVerifyWithThreadOperation(List<VerifyElement> elements)
|
||||
public VerifyCacheFilesWithThreadOperation(List<VerifyCacheElement> elements)
|
||||
{
|
||||
_waitingList = elements;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace YooAsset
|
||||
if (_verifyMaxNum < 1)
|
||||
_verifyMaxNum = 1;
|
||||
|
||||
_verifyingList = new List<VerifyElement>(_verifyMaxNum);
|
||||
_verifyingList = new List<VerifyCacheElement>(_verifyMaxNum);
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Package verify elapsed time {costTime:f1} seconds");
|
||||
YooLogger.Log($"Verify cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
|
||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||
@@ -114,19 +114,19 @@ namespace YooAsset
|
||||
return 1f;
|
||||
return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
|
||||
}
|
||||
private bool BeginVerifyFileWithThread(VerifyElement element)
|
||||
private bool BeginVerifyFileWithThread(VerifyCacheElement element)
|
||||
{
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
|
||||
}
|
||||
private void VerifyInThread(object obj)
|
||||
{
|
||||
VerifyElement element = (VerifyElement)obj;
|
||||
VerifyCacheElement element = (VerifyCacheElement)obj;
|
||||
element.Result = CacheSystem.VerifyingCacheFile(element);
|
||||
_syncContext.Post(VerifyCallback, element);
|
||||
}
|
||||
private void VerifyCallback(object obj)
|
||||
{
|
||||
VerifyElement element = (VerifyElement)obj;
|
||||
VerifyCacheElement element = (VerifyCacheElement)obj;
|
||||
_verifyingList.Remove(element);
|
||||
|
||||
if (element.Result == EVerifyResult.Succeed)
|
||||
@@ -148,7 +148,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(非线程版)
|
||||
/// </summary>
|
||||
internal class PackageVerifyWithoutThreadOperation : PackageVerifyOperation
|
||||
internal class VerifyCacheFilesWithoutThreadOperation : VerifyCacheFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
@@ -158,16 +158,16 @@ namespace YooAsset
|
||||
Done,
|
||||
}
|
||||
|
||||
private List<VerifyElement> _waitingList;
|
||||
private List<VerifyElement> _verifyingList;
|
||||
private List<VerifyCacheElement> _waitingList;
|
||||
private List<VerifyCacheElement> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private int _succeedCount;
|
||||
private int _failedCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public PackageVerifyWithoutThreadOperation(List<VerifyElement> elements)
|
||||
|
||||
public VerifyCacheFilesWithoutThreadOperation(List<VerifyCacheElement> elements)
|
||||
{
|
||||
_waitingList = elements;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ namespace YooAsset
|
||||
_verifyMaxNum = fileCount;
|
||||
_verifyTotalCount = fileCount;
|
||||
|
||||
_verifyingList = new List<VerifyElement>(_verifyMaxNum);
|
||||
_verifyingList = new List<VerifyCacheElement>(_verifyMaxNum);
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace YooAsset
|
||||
return 1f;
|
||||
return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
|
||||
}
|
||||
private void BeginVerifyFileWithoutThread(VerifyElement element)
|
||||
private void BeginVerifyFileWithoutThread(VerifyCacheElement element)
|
||||
{
|
||||
element.Result = CacheSystem.VerifyingCacheFile(element);
|
||||
if (element.Result == EVerifyResult.Succeed)
|
||||
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class VerifyTempFileOperation : AsyncOperationBase
|
||||
{
|
||||
public EVerifyResult VerifyResult { protected set; get; }
|
||||
|
||||
public static VerifyTempFileOperation CreateOperation(VerifyTempElement element)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
var operation = new VerifyTempFileWithoutThreadOperation(element);
|
||||
#else
|
||||
var operation = new VerifyTempFileWithThreadOperation(element);
|
||||
#endif
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件验证(线程版)
|
||||
/// </summary>
|
||||
internal class VerifyTempFileWithThreadOperation : VerifyTempFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
VerifyFile,
|
||||
Waiting,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly VerifyTempElement _element;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyTempFileWithThreadOperation(VerifyTempElement element)
|
||||
{
|
||||
_element = element;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.VerifyFile;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.VerifyFile)
|
||||
{
|
||||
if (BeginVerifyFileWithThread(_element))
|
||||
{
|
||||
_steps = ESteps.Waiting;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool BeginVerifyFileWithThread(VerifyTempElement element)
|
||||
{
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
|
||||
}
|
||||
private void VerifyInThread(object obj)
|
||||
{
|
||||
VerifyTempElement element = (VerifyTempElement)obj;
|
||||
element.Result = CacheSystem.VerifyingTempFile(element);
|
||||
DownloadSystem.SyncContext.Post(VerifyCallback, element);
|
||||
}
|
||||
private void VerifyCallback(object obj)
|
||||
{
|
||||
VerifyTempElement element = (VerifyTempElement)obj;
|
||||
VerifyResult = element.Result;
|
||||
if (element.Result == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed verify file : {element.TempDataFilePath} ! ErrorCode : {element.Result}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件验证(非线程版)
|
||||
/// </summary>
|
||||
internal class VerifyTempFileWithoutThreadOperation : VerifyTempFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
VerifyFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly VerifyTempElement _element;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyTempFileWithoutThreadOperation(VerifyTempElement element)
|
||||
{
|
||||
_element = element;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.VerifyFile;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.VerifyFile)
|
||||
{
|
||||
_element.Result = CacheSystem.VerifyingTempFile(_element);
|
||||
VerifyResult = _element.Result;
|
||||
if (_element.Result == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {_element.Result}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd356e68c5b4ef04ab018a6388f5173a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,13 +10,14 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetCacheFiles,
|
||||
FindCacheFiles,
|
||||
VerifyCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private PackageVerifyOperation _packageVerifyOp;
|
||||
private FindCacheFilesOperation _findCacheFilesOp;
|
||||
private VerifyCacheFilesOperation _verifyCacheFilesOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public PackageCachingOperation(string packageName)
|
||||
@@ -25,71 +26,47 @@ namespace YooAsset
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.GetCacheFiles;
|
||||
_steps = ESteps.FindCacheFiles;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetCacheFiles)
|
||||
if (_steps == ESteps.FindCacheFiles)
|
||||
{
|
||||
var elements = GetVerifyElements();
|
||||
_packageVerifyOp = PackageVerifyOperation.CreateOperation(elements);
|
||||
OperationSystem.StartOperation(_packageVerifyOp);
|
||||
if (_findCacheFilesOp == null)
|
||||
{
|
||||
_findCacheFilesOp = new FindCacheFilesOperation(_packageName);
|
||||
OperationSystem.StartOperation(_findCacheFilesOp);
|
||||
}
|
||||
|
||||
Progress = _findCacheFilesOp.Progress;
|
||||
if (_findCacheFilesOp.IsDone == false)
|
||||
return;
|
||||
|
||||
_steps = ESteps.VerifyCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyCacheFiles)
|
||||
{
|
||||
Progress = _packageVerifyOp.Progress;
|
||||
if (_packageVerifyOp.IsDone == false)
|
||||
if (_verifyCacheFilesOp == null)
|
||||
{
|
||||
_verifyCacheFilesOp = VerifyCacheFilesOperation.CreateOperation(_findCacheFilesOp.VerifyElements);
|
||||
OperationSystem.StartOperation(_verifyCacheFilesOp);
|
||||
}
|
||||
|
||||
Progress = _verifyCacheFilesOp.Progress;
|
||||
if (_verifyCacheFilesOp.IsDone == false)
|
||||
return;
|
||||
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
||||
int totalCount = CacheSystem.GetCachedFilesCount(_packageName);
|
||||
YooLogger.Log($"Package '{_packageName}' cached files count : {totalCount}");
|
||||
}
|
||||
}
|
||||
|
||||
private List<VerifyElement> GetVerifyElements()
|
||||
{
|
||||
string cacheFolderPath = PersistentHelper.GetCacheFolderPath(_packageName);
|
||||
if (Directory.Exists(cacheFolderPath) == false)
|
||||
return new List<VerifyElement>();
|
||||
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(cacheFolderPath);
|
||||
DirectoryInfo[] fileFolders = rootDirectory.GetDirectories();
|
||||
List<VerifyElement> result = new List<VerifyElement>(fileFolders.Length);
|
||||
foreach (var fileFoder in fileFolders)
|
||||
{
|
||||
string cacheGUID = fileFoder.Name;
|
||||
if (CacheSystem.IsCached(_packageName, cacheGUID))
|
||||
continue;
|
||||
|
||||
// 获取数据文件的后缀名
|
||||
string dataFileExtension = string.Empty;
|
||||
var fileInfos = fileFoder.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Extension == ".temp")
|
||||
continue;
|
||||
|
||||
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
|
||||
{
|
||||
dataFileExtension = fileInfo.Extension;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string fileRootPath = fileFoder.FullName;
|
||||
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}{dataFileExtension}";
|
||||
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
|
||||
VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
|
||||
result.Add(element);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,14 @@ namespace YooAsset
|
||||
_wrappers.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存文件总数
|
||||
/// </summary>
|
||||
public int GetCachedFilesCount()
|
||||
{
|
||||
return _wrappers.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询缓存记录
|
||||
/// </summary>
|
||||
|
||||
@@ -2,19 +2,22 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VerifyElement
|
||||
/// <summary>
|
||||
/// 缓存文件验证元素
|
||||
/// </summary>
|
||||
internal class VerifyCacheElement
|
||||
{
|
||||
public string PackageName { private set; get; }
|
||||
public string CacheGUID { private set; get; }
|
||||
public string FileRootPath { private set; get; }
|
||||
public string DataFilePath { private set; get; }
|
||||
public string InfoFilePath { private set; get; }
|
||||
|
||||
|
||||
public EVerifyResult Result;
|
||||
public string DataFileCRC;
|
||||
public long DataFileSize;
|
||||
|
||||
public VerifyElement(string packageName, string cacheGUID, string fileRootPath, string dataFilePath, string infoFilePath)
|
||||
public VerifyCacheElement(string packageName, string cacheGUID, string fileRootPath, string dataFilePath, string infoFilePath)
|
||||
{
|
||||
PackageName = packageName;
|
||||
CacheGUID = cacheGUID;
|
||||
@@ -36,4 +39,23 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件验证元素
|
||||
/// </summary>
|
||||
internal class VerifyTempElement
|
||||
{
|
||||
public string TempDataFilePath { private set; get; }
|
||||
public string FileCRC { private set; get; }
|
||||
public long FileSize { private set; get; }
|
||||
|
||||
public EVerifyResult Result;
|
||||
|
||||
public VerifyTempElement(string tempDataFilePath, string fileCRC, long fileSize)
|
||||
{
|
||||
TempDataFilePath = tempDataFilePath;
|
||||
FileCRC = fileCRC;
|
||||
FileSize = fileSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,16 @@
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义下载器的请求委托
|
||||
/// </summary>
|
||||
public delegate UnityWebRequest DownloadRequestDelegate(string url);
|
||||
|
||||
/// <summary>
|
||||
/// 1. 保证每一时刻资源文件只存在一个下载器
|
||||
/// 2. 保证下载器下载完成后立刻验证并缓存
|
||||
@@ -16,11 +22,20 @@ namespace YooAsset
|
||||
private static readonly Dictionary<string, DownloaderBase> _downloaderDic = new Dictionary<string, DownloaderBase>();
|
||||
private static readonly List<string> _removeList = new List<string>(100);
|
||||
|
||||
/// <summary>
|
||||
/// 线程同步
|
||||
/// </summary>
|
||||
public static ThreadSyncContext SyncContext { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义下载器的请求委托
|
||||
/// </summary>
|
||||
public static DownloadRequestDelegate RequestDelegate = null;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义的证书认证实例
|
||||
/// </summary>
|
||||
public static CertificateHandler CertificateHandlerInstance;
|
||||
public static CertificateHandler CertificateHandlerInstance = null;
|
||||
|
||||
/// <summary>
|
||||
/// 启用断点续传功能文件的最小字节数
|
||||
@@ -32,11 +47,23 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static List<long> ClearFileResponseCodes { set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新所有下载器
|
||||
/// 初始化下载器
|
||||
/// </summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
SyncContext = new ThreadSyncContext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新下载器
|
||||
/// </summary>
|
||||
public static void Update()
|
||||
{
|
||||
if (SyncContext != null)
|
||||
SyncContext.Update();
|
||||
|
||||
// 更新下载器
|
||||
_removeList.Clear();
|
||||
foreach (var valuePair in _downloaderDic)
|
||||
@@ -66,7 +93,12 @@ namespace YooAsset
|
||||
}
|
||||
_downloaderDic.Clear();
|
||||
_removeList.Clear();
|
||||
|
||||
SyncContext = null;
|
||||
RequestDelegate = null;
|
||||
CertificateHandlerInstance = null;
|
||||
BreakpointResumeFileSize = int.MaxValue;
|
||||
ClearFileResponseCodes = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +133,18 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个新的网络请求
|
||||
/// </summary>
|
||||
public static UnityWebRequest NewRequest(string requestURL)
|
||||
{
|
||||
if (RequestDelegate != null)
|
||||
return RequestDelegate.Invoke(requestURL);
|
||||
|
||||
var request = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载器的总数
|
||||
/// </summary>
|
||||
|
||||
@@ -7,11 +7,13 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
CheckTempFile,
|
||||
WaitingCheckTempFile,
|
||||
PrepareDownload,
|
||||
CreateResumeDownloader,
|
||||
CreateGeneralDownloader,
|
||||
CheckDownload,
|
||||
VerifyingFile,
|
||||
VerifyTempFile,
|
||||
WaitingVerifyTempFile,
|
||||
CachingFile,
|
||||
TryAgain,
|
||||
Succeed,
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace YooAsset
|
||||
private readonly string _tempFilePath;
|
||||
private UnityWebRequest _webRequest = null;
|
||||
private DownloadHandlerFileRange _downloadHandle = null;
|
||||
private VerifyTempFileOperation _checkFileOp = null;
|
||||
private VerifyTempFileOperation _verifyFileOp = null;
|
||||
|
||||
// 重置变量
|
||||
private bool _isAbort = false;
|
||||
@@ -34,17 +36,28 @@ namespace YooAsset
|
||||
if (IsDone())
|
||||
return;
|
||||
|
||||
// 检测本地临时文件
|
||||
// 检测临时文件
|
||||
if (_steps == ESteps.CheckTempFile)
|
||||
{
|
||||
var verifyResult = CacheSystem.VerifyingTempFile(_bundleInfo.Bundle);
|
||||
if (verifyResult == EVerifyResult.Succeed)
|
||||
VerifyTempElement element = new VerifyTempElement(_bundleInfo.Bundle.TempDataFilePath, _bundleInfo.Bundle.FileCRC, _bundleInfo.Bundle.FileSize);
|
||||
_checkFileOp = VerifyTempFileOperation.CreateOperation(element);
|
||||
OperationSystem.StartOperation(_checkFileOp);
|
||||
_steps = ESteps.WaitingCheckTempFile;
|
||||
}
|
||||
|
||||
// 等待检测结果
|
||||
if (_steps == ESteps.WaitingCheckTempFile)
|
||||
{
|
||||
if (_checkFileOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_checkFileOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CachingFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verifyResult == EVerifyResult.FileOverflow)
|
||||
if (_checkFileOp.VerifyResult == EVerifyResult.FileOverflow)
|
||||
{
|
||||
if (File.Exists(_tempFilePath))
|
||||
File.Delete(_tempFilePath);
|
||||
@@ -80,7 +93,7 @@ namespace YooAsset
|
||||
if (File.Exists(_tempFilePath))
|
||||
File.Delete(_tempFilePath);
|
||||
|
||||
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
|
||||
_webRequest = DownloadSystem.NewRequest(_requestURL);
|
||||
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||
handler.removeFileOnAbort = true;
|
||||
_webRequest.downloadHandler = handler;
|
||||
@@ -109,11 +122,11 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
|
||||
_webRequest = DownloadSystem.NewRequest(_requestURL);
|
||||
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
||||
handler.removeFileOnAbort = false;
|
||||
#else
|
||||
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
|
||||
_webRequest = DownloadSystem.NewRequest(_requestURL);
|
||||
var handler = new DownloadHandlerFileRange(_tempFilePath, _bundleInfo.Bundle.FileSize, _webRequest);
|
||||
_downloadHandle = handler;
|
||||
#endif
|
||||
@@ -188,7 +201,7 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.VerifyingFile;
|
||||
_steps = ESteps.VerifyTempFile;
|
||||
}
|
||||
|
||||
// 释放下载器
|
||||
@@ -196,21 +209,30 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 验证下载文件
|
||||
if (_steps == ESteps.VerifyingFile)
|
||||
if (_steps == ESteps.VerifyTempFile)
|
||||
{
|
||||
var verifyResult = CacheSystem.VerifyingTempFile(_bundleInfo.Bundle);
|
||||
if (verifyResult == EVerifyResult.Succeed)
|
||||
VerifyTempElement element = new VerifyTempElement(_bundleInfo.Bundle.TempDataFilePath, _bundleInfo.Bundle.FileCRC, _bundleInfo.Bundle.FileSize);
|
||||
_verifyFileOp = VerifyTempFileOperation.CreateOperation(element);
|
||||
OperationSystem.StartOperation(_verifyFileOp);
|
||||
_steps = ESteps.WaitingVerifyTempFile;
|
||||
}
|
||||
|
||||
// 等待验证完成
|
||||
if (_steps == ESteps.WaitingVerifyTempFile)
|
||||
{
|
||||
if (_verifyFileOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_verifyFileOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CachingFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastError = $"Failed to verifying file : {_bundleInfo.Bundle.FileName}, ErrorCode : {verifyResult}";
|
||||
|
||||
// 注意:验证失败后删除文件
|
||||
if (File.Exists(_tempFilePath))
|
||||
File.Delete(_tempFilePath);
|
||||
|
||||
_lastError = _verifyFileOp.Error;
|
||||
_steps = ESteps.TryAgain;
|
||||
}
|
||||
}
|
||||
@@ -226,7 +248,7 @@ namespace YooAsset
|
||||
long dataFileSize = _bundleInfo.Bundle.FileSize;
|
||||
|
||||
if (File.Exists(infoFilePath))
|
||||
File.Delete(infoFilePath);
|
||||
File.Delete(infoFilePath);
|
||||
if (File.Exists(dataFilePath))
|
||||
File.Delete(dataFilePath);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace YooAsset
|
||||
if (_webRequest == null)
|
||||
{
|
||||
URL = url;
|
||||
_webRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
|
||||
_webRequest = DownloadSystem.NewRequest(URL);
|
||||
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
||||
_webRequest.downloadHandler = handler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
||||
_latestDownloadBytes = 0;
|
||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||
|
||||
_webRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
|
||||
_webRequest = DownloadSystem.NewRequest(URL);
|
||||
DownloadHandlerFile handler = new DownloadHandlerFile(savePath);
|
||||
handler.removeFileOnAbort = true;
|
||||
_webRequest.downloadHandler = handler;
|
||||
|
||||
@@ -32,28 +32,36 @@ namespace YooAsset
|
||||
private bool _isPause = false;
|
||||
private long _lastDownloadBytes = 0;
|
||||
private int _lastDownloadCount = 0;
|
||||
private long _cachedDownloadBytes = 0;
|
||||
private int _cachedDownloadCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件总数量
|
||||
/// 统计的下载文件总数量
|
||||
/// </summary>
|
||||
public int TotalDownloadCount { private set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件的总大小
|
||||
/// 统计的下载文件的总大小
|
||||
/// </summary>
|
||||
public long TotalDownloadBytes { private set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前已经完成的下载总数量
|
||||
/// </summary>
|
||||
public int CurrentDownloadCount { private set; get; }
|
||||
public int CurrentDownloadCount
|
||||
{
|
||||
get { return _lastDownloadCount; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前已经完成的下载总大小
|
||||
/// </summary>
|
||||
public long CurrentDownloadBytes { private set; get; }
|
||||
public long CurrentDownloadBytes
|
||||
{
|
||||
get { return _lastDownloadBytes; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当下载器结束(无论成功或失败)
|
||||
@@ -120,7 +128,7 @@ namespace YooAsset
|
||||
{
|
||||
// 检测下载器结果
|
||||
_removeList.Clear();
|
||||
long downloadBytes = CurrentDownloadBytes;
|
||||
long downloadBytes = _cachedDownloadBytes;
|
||||
foreach (var downloader in _downloaders)
|
||||
{
|
||||
downloadBytes += (long)downloader.DownloadedBytes;
|
||||
@@ -139,8 +147,8 @@ namespace YooAsset
|
||||
|
||||
// 下载成功
|
||||
_removeList.Add(downloader);
|
||||
CurrentDownloadCount++;
|
||||
CurrentDownloadBytes += bundleInfo.Bundle.FileSize;
|
||||
_cachedDownloadCount++;
|
||||
_cachedDownloadBytes += bundleInfo.Bundle.FileSize;
|
||||
}
|
||||
|
||||
// 移除已经完成的下载器(无论成功或失败)
|
||||
@@ -150,10 +158,10 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 如果下载进度发生变化
|
||||
if (_lastDownloadBytes != downloadBytes || _lastDownloadCount != CurrentDownloadCount)
|
||||
if (_lastDownloadBytes != downloadBytes || _lastDownloadCount != _cachedDownloadCount)
|
||||
{
|
||||
_lastDownloadBytes = downloadBytes;
|
||||
_lastDownloadCount = CurrentDownloadCount;
|
||||
_lastDownloadCount = _cachedDownloadCount;
|
||||
Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
|
||||
OnDownloadProgressCallback?.Invoke(TotalDownloadCount, _lastDownloadCount, TotalDownloadBytes, _lastDownloadBytes);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public int[] ReferenceIDs;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 所属的包裹名称
|
||||
/// </summary>
|
||||
@@ -71,8 +71,17 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(_cachedDataFilePath) == false)
|
||||
return _cachedDataFilePath;
|
||||
|
||||
string cacheRoot = PersistentHelper.GetCacheFolderPath(PackageName);
|
||||
_cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}";
|
||||
string folderName = FileHash.Substring(0, 2);
|
||||
if (IsRawFile)
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
|
||||
_cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}";
|
||||
}
|
||||
else
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
|
||||
_cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}";
|
||||
}
|
||||
return _cachedDataFilePath;
|
||||
}
|
||||
}
|
||||
@@ -88,8 +97,17 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(_cachedInfoFilePath) == false)
|
||||
return _cachedInfoFilePath;
|
||||
|
||||
string cacheRoot = PersistentHelper.GetCacheFolderPath(PackageName);
|
||||
_cachedInfoFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
|
||||
string folderName = FileHash.Substring(0, 2);
|
||||
if (IsRawFile)
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
|
||||
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
|
||||
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
|
||||
}
|
||||
return _cachedInfoFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ namespace YooAsset
|
||||
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";
|
||||
|
||||
@@ -120,12 +122,33 @@ namespace YooAsset
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存文件夹路径
|
||||
/// 获取缓存的BundleFile文件夹路径
|
||||
/// </summary>
|
||||
public static string GetCacheFolderPath(string packageName)
|
||||
private readonly static Dictionary<string, string> _cachedBundleFileFolder = new Dictionary<string, string>(100);
|
||||
public static string GetCachedBundleFileFolderPath(string packageName)
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
return $"{root}/{packageName}";
|
||||
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
value = $"{root}/{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)
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
value = $"{root}/{packageName}/{CachedRawFileFolder}";
|
||||
_cachedRawFileFolder.Add(packageName, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace YooAsset
|
||||
_driver.AddComponent<RemoteDebuggerInRuntime>();
|
||||
#endif
|
||||
|
||||
// 初始化异步系统
|
||||
OperationSystem.Initialize();
|
||||
DownloadSystem.Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +184,14 @@ namespace YooAsset
|
||||
DownloadSystem.CertificateHandlerInstance = instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置下载系统参数,自定义下载请求
|
||||
/// </summary>
|
||||
public static void SetDownloadSystemUnityWebRequest(DownloadRequestDelegate requestDelegate)
|
||||
{
|
||||
DownloadSystem.RequestDelegate = requestDelegate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
||||
/// </summary>
|
||||
|
||||
@@ -16,7 +16,7 @@ MonoBehaviour:
|
||||
BuildMode: 0
|
||||
BuildPackage: DefaultPackage
|
||||
CompressOption: 2
|
||||
OutputNameStyle: 4
|
||||
OutputNameStyle: 1
|
||||
CopyBuildinFileOption: 1
|
||||
CopyBuildinFileTags:
|
||||
EncyptionClassName: FileStreamEncryption
|
||||
|
||||
@@ -12,4 +12,6 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 44454e58a49818040a1aef5799e71b30, type: 3}
|
||||
m_Name: ShaderVariantCollectorSetting
|
||||
m_EditorClassIdentifier:
|
||||
SavePath: Assets/Samples/BassicSample/GameArt/ShaderVariants/MyShaderVariants.shadervariants
|
||||
SavePath: Assets/ShaderVariants/MyShaderVariants.shadervariants
|
||||
CollectPackage: DefaultPackage
|
||||
ProcessCapacity: 1000
|
||||
|
||||
@@ -3,21 +3,11 @@ using System.IO;
|
||||
using System.Text;
|
||||
using YooAsset;
|
||||
|
||||
public class EncryptionNone : IEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
{
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.LoadMethod = EBundleLoadMethod.Normal;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class FileOffsetEncryption : IEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
{
|
||||
if(fileInfo.BundleName.Contains("gameres_music"))
|
||||
if (fileInfo.BundleName.Contains("_gameres_audio"))
|
||||
{
|
||||
int offset = 32;
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FilePath);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// 作者:Stark
|
||||
//-------------------------------------
|
||||
|
||||
#if UNITY_ANDROID
|
||||
/// <summary>
|
||||
/// 为Github对开发者的友好,采用自动补充UnityPlayerActivity.java文件的通用姿势满足各个开发者
|
||||
/// </summary>
|
||||
@@ -34,11 +35,24 @@ internal class AndroidPost : UnityEditor.Android.IPostGenerateGradleAndroidProje
|
||||
" return false; \n" +
|
||||
" } \n" +
|
||||
"}";
|
||||
if (!readContent[readContent.Length - 18].Contains("CheckAssetExist"))
|
||||
|
||||
if (CheckFunctionExist(readContent) == false)
|
||||
readContent[readContent.Length - 1] = postContent;
|
||||
System.IO.File.WriteAllLines(untityActivityFilePath, readContent);
|
||||
}
|
||||
private bool CheckFunctionExist(string[] contents)
|
||||
{
|
||||
for (int i = 0; i < contents.Length; i++)
|
||||
{
|
||||
if (contents[i].Contains("CheckAssetExist"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
//auto-gen-function
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.4.6-preview",
|
||||
"version": "1.4.7",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 资源构建
|
||||
|
||||

|
||||

|
||||
|
||||
### 界面介绍
|
||||
|
||||
@@ -50,9 +50,7 @@
|
||||
|
||||
HashName:哈希值
|
||||
|
||||
HashName_Extension:哈希值+后缀名
|
||||
|
||||
HashName_BundleName_Extension:资源包名+哈希值+后缀名
|
||||
BundleName_HashName:资源包名+哈希值
|
||||
|
||||
- **Copy Buildin File Option**
|
||||
|
||||
@@ -78,17 +76,23 @@
|
||||
|
||||
补丁包文件夹里包含补丁清单文件,资源包文件,构建报告文件等。
|
||||
|
||||

|
||||

|
||||
|
||||
### 补丁清单
|
||||
|
||||
补丁清单是一个Json格式的文本文件。
|
||||
补丁清单文件是上图中以PatchManifest开头命名的文件。
|
||||
|
||||
AssetList组记录的是主资源对象列表。
|
||||
- PatchManifest_DefaultPackage_xxxxxx.hash
|
||||
|
||||
BundleList组记录的是资源包列表。
|
||||
记录了补丁清单文件的哈希值。
|
||||
|
||||

|
||||
- PatchManifest_DefaultPackage_xxxxxx.json
|
||||
|
||||
该文件为Json文本格式,主要用于开发者预览信息。
|
||||
|
||||
- PatchManifest_DefaultPackage_xxxxxx.bytes
|
||||
|
||||
该文件为二进制格式,主要用于程序内读取加载。
|
||||
|
||||
### Jenkins支持
|
||||
|
||||
@@ -109,10 +113,10 @@ private static void BuildInternal(BuildTarget buildTarget)
|
||||
buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
|
||||
buildParameters.BuildMode = EBuildMode.ForceRebuild;
|
||||
buildParameters.PackageName = "DefaultPackage";
|
||||
buildParameters.PackageVersion = "1.0.0";
|
||||
buildParameters.PackageVersion = "1.0";
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.CompressOption = ECompressOption.LZ4;
|
||||
buildParameters.OutputNameStyle = EOutputNameStyle.HashName_Extension;
|
||||
buildParameters.OutputNameStyle = EOutputNameStyle.HashName;
|
||||
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
// 执行构建
|
||||
@@ -122,6 +126,10 @@ private static void BuildInternal(BuildTarget buildTarget)
|
||||
{
|
||||
Debug.Log($"构建成功 : {buildResult.OutputPackageDirectory}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"构建失败 : {buildResult.FailedInfo}");
|
||||
}
|
||||
}
|
||||
|
||||
// 从构建命令里获取参数示例
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
# 资源收集
|
||||
|
||||

|
||||

|
||||
|
||||
左侧为分组列表,右侧为该分组的配置界面。
|
||||
|
||||
导出按钮可以将配置数据导出为XML文件,导入按钮可以导入保存的XML文件。
|
||||
导入按钮:可以导入保存的XML文件。
|
||||
|
||||
导出按钮:可以将配置数据导出为XML文件。
|
||||
|
||||
修复按钮:在配置里的文件夹挪动位置之后,可以通过该按钮按钮来修正。
|
||||
|
||||
**注意**:该工具仅支持Unity2019.4+
|
||||
|
||||
@@ -13,11 +17,15 @@
|
||||
- Show Packages
|
||||
|
||||
是否展示资源包列表视图。
|
||||
|
||||
|
||||
- Show Editor Alias
|
||||
|
||||
是否显示为中文模式。
|
||||
|
||||
- Enable Addressable
|
||||
|
||||
启用可寻址资源定位系统。
|
||||
|
||||
|
||||
- Unique Bundle Name
|
||||
|
||||
资源包名追加PackageName作为前缀。
|
||||
@@ -36,10 +44,10 @@
|
||||
//自定义扩展范例
|
||||
public class DisableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
@@ -83,18 +91,18 @@
|
||||
|
||||
- AddressByFileName 以文件名为定位地址。
|
||||
|
||||
- AddressByGrouperAndFileName 以分组名称+文件名为定位地址。
|
||||
- AddressByGrouperAndFileName 以分组名+文件名为定位地址。
|
||||
|
||||
- AddressByCollectorAndFileName 以收集器名+文件名为定位地址。
|
||||
- AddressByFolderAndFileName 以文件夹名+文件名为定位地址。
|
||||
|
||||
````c#
|
||||
//自定义扩展范例
|
||||
public class AddressByFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
}
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
@@ -102,21 +110,28 @@
|
||||
|
||||
打包规则,规则可以自定义扩展。下面是内置规则:
|
||||
|
||||
- PackSeparately 以收集文件路径作为资源包名,每个资源文件单独打包。
|
||||
- PackDirectory 以收集文件所在的文件夹路径作为资源包名,该文件夹下所有文件打进一个资源包。
|
||||
- PackTopDirectory 以收集器路径下顶级文件夹为资源包名,该文件夹下所有文件打进一个资源包。
|
||||
- PackSeparately 以文件路径作为资源包名,每个资源文件单独打包。
|
||||
- PackDirectory 以文件所在的文件夹路径作为资源包名,该文件夹下所有文件打进一个资源包。
|
||||
- PackTopDirectory 以收集器下顶级文件夹为资源包名,该文件夹下所有文件打进一个资源包。
|
||||
- PackCollector 以收集器路径作为资源包名,收集的所有文件打进一个资源包。
|
||||
- PackGrouper 以分组名称作为资源包名,收集的所有文件打进一个资源包。
|
||||
- PackGroup 以分组名称作为资源包名,收集的所有文件打进一个资源包。
|
||||
- PackRawFile 目录下的资源文件会被处理为原生资源包。
|
||||
|
||||
````c#
|
||||
//自定义扩展范例
|
||||
public class PackDirectory : IPackRule
|
||||
{
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
{
|
||||
return Path.GetDirectoryName(data.AssetPath); //"Assets/Config/test.txt" --> "Assets/Config"
|
||||
}
|
||||
PackRuleResult IPackRule.GetBundleName(PackRuleData data)
|
||||
{
|
||||
//"Assets/Config/test.txt" --> "Assets/Config"
|
||||
string bundleName = Path.GetDirectoryName(data.AssetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
@@ -133,13 +148,17 @@
|
||||
//自定义扩展范例
|
||||
public class CollectScene : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
}
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
- **UserData**
|
||||
|
||||
用户自定义数据,可以帮助定制化AddressRule和PackRule。
|
||||
|
||||
- **AssetTags**
|
||||
|
||||
资源分类标签列表,该收集器下收集的资源会全部被打上该标签。
|
||||
|
||||
@@ -4,22 +4,40 @@
|
||||
|
||||
如果是本地测试,可以在本地创建一个WEB服务器,然后将补丁包拷贝到WEB服务器下。
|
||||
|
||||
**按照游戏版本目录部署**
|
||||
**部署目录**
|
||||
|
||||
在业务开发过程中,每个游戏版本实际都会创建一个SVN分支,该分支工程内每次构建的补丁包上传到对应的CDN目录下即可。
|
||||
在业务开发过程中,发版本之前都会创建一个SVN或GIT分支,以分支工程为基础去构建APP。
|
||||
|
||||
````
|
||||
CDN
|
||||
└─android
|
||||
├─v1.0
|
||||
├─v1.1
|
||||
└─v2.0
|
||||
├─v1.0(APP版本)
|
||||
├─v1.1(APP版本)
|
||||
└─v2.0(APP版本)
|
||||
└─iphone
|
||||
├─v1.0
|
||||
├─v1.1
|
||||
└─v2.0
|
||||
├─v1.0(APP版本)
|
||||
├─v1.1(APP版本)
|
||||
└─v2.0(APP版本)
|
||||
````
|
||||
|
||||
**游戏版本说明**
|
||||
**APP版本说明**
|
||||
|
||||
v1.0 代表的是APP版本,不是资源版本。在没有更换安装包的情况下,不需要新增加APP版本目录。
|
||||
|
||||
例如:我们游戏的当前APP版本是v1.0,那么每次生成的补丁文件全部覆盖到v1.0的目录下即可。
|
||||
|
||||
下面的示例里一共上传过2次补丁包。第二次上传的补丁包会把第一次的版本记录文件(PatchManifest_DefaultPackage.version)覆盖掉。当我们想回退资源版本的时候,把第一次生成的版本记录文件覆盖到同目录下即可。
|
||||
|
||||
````
|
||||
v1.0(游戏版本)
|
||||
├─PatchManifest_DefaultPackage.version
|
||||
├─PatchManifest_DefaultPackage_2023-02-01-654.hash
|
||||
├─PatchManifest_DefaultPackage_2023-02-01-654.bytes
|
||||
├─PatchManifest_DefaultPackage_2023-02-12-789.hash
|
||||
├─PatchManifest_DefaultPackage_2023-02-12-789.bytes
|
||||
├─2bb5a28d37dabf27df8bc6a4706b8f80.bundle
|
||||
├─2dbea9c3056c8839bc03d80a2aebd105.bundle
|
||||
├─6e8c3003a64ead36a0bd2d5cdebfbcf4.bundle
|
||||
...
|
||||
````
|
||||
|
||||
v1.0 代表的是游戏版本,不是资源版本。在没有更换安装包的前提下,不需要递增这个游戏版本。每次生成的补丁包只需要覆盖掉当前游戏版本目录下即可。
|
||||
|
||||
@@ -73,15 +73,17 @@ private class QueryStreamingAssetsFileServices : IQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string fileName)
|
||||
{
|
||||
// 注意:使用了BetterStreamingAssets插件,使用前需要初始化该插件!
|
||||
// StreamingAssetsHelper.cs是太空战机里提供的一个查询脚本。
|
||||
string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
|
||||
return BetterStreamingAssets.FileExists($"{buildinFolderName}/{fileName}");
|
||||
return StreamingAssetsHelper.FileExists($"{buildinFolderName}/{fileName}");
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
### 源代码解析
|
||||
|
||||
Package.InitializeAsync()方法解析。
|
||||
|
||||
- 编辑器模拟模式
|
||||
|
||||
每次启动调用EditorSimulateModeHelper.SimulateBuild()方法,都会在底层执行一次模拟构建(Simulate Build)。
|
||||
@@ -90,11 +92,11 @@ private class QueryStreamingAssetsFileServices : IQueryServices
|
||||
|
||||
- 单机运行模式
|
||||
|
||||
在初始化的时候,会直接读取内置清单文件(StreamingAssets文件夹里的文件),最后根据加载的清单去验证沙盒里缓存的文件。
|
||||
在初始化的时候,会直接读取内置清单文件(StreamingAssets文件夹里的文件),最后初始化缓存系统。
|
||||
|
||||
- 联机运行模式
|
||||
|
||||
在初始化的时候,会优先从沙盒里加载清单,如果沙盒里不存在,则会尝试加载内置清单并将其拷贝到沙盒里。最后根据加载的清单去验证沙盒里缓存的文件。
|
||||
在初始化的时候,会优先从沙盒里加载清单,如果沙盒里不存在,则会尝试加载内置清单并将其拷贝到沙盒里。最后初始化缓存系统。
|
||||
|
||||
**注意**:如果沙盒清单和内置清单都不存在,初始化也会被判定为成功!
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ private IEnumerator UpdateStaticVersion()
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//更新成功
|
||||
string PackageVersion = operation.PackageVersion;
|
||||
Debug.Log($"Updated package Version : {PackageVersion}");
|
||||
string packageVersion = operation.PackageVersion;
|
||||
Debug.Log($"Updated package Version : {packageVersion}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -66,7 +66,7 @@ private IEnumerator UpdatePatchManifest()
|
||||
|
||||
用于下载更新资源标签指定的资源包文件。
|
||||
|
||||
- YooAssets.CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
- YooAssets.CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
|
||||
用于下载更新指定的资源列表依赖的资源包文件。
|
||||
|
||||
@@ -131,25 +131,37 @@ private IEnumerator Start()
|
||||
// 如果获取远端资源版本失败,说明当前网络无连接。
|
||||
// 在正常开始游戏之前,需要验证本地清单内容的完整性。
|
||||
string packageVersion = package.GetPackageVersion();
|
||||
var operation = package.CheckPackageContentsAsync(packageVersion);
|
||||
var operation = package.PreDownloadPackageAsync(packageVersion);
|
||||
yield return operation;
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
if (operation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
StartGame();
|
||||
ShowMessageBox("请检查本地网络,有新的游戏内容需要更新!");
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
int timeout = 60;
|
||||
var downloader = operation.CreatePatchDownloader(downloadingMaxNum, failedTryAgain, timeout);
|
||||
if (downloader.TotalDownloadCount > 0)
|
||||
{
|
||||
// 资源内容本地并不完整,需要提示玩家联网更新。
|
||||
ShowMessageBox("请检查本地网络,有新的游戏内容需要更新!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 开始游戏
|
||||
StartGame();
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
### 源代码解析
|
||||
|
||||
Package.UpdatePackageManifestAsync()方法解析。
|
||||
|
||||
- 联机运行模式
|
||||
|
||||
UpdatePackageManifestAsync()为资源清单更新方法。该方法的内部实现原理如下:
|
||||
通过传入的清单版本,优先比对当前激活清单的版本,如果相同就直接返回成功。如果有差异就从缓存里去查找匹配的清单,如果缓存里不存在,就去远端下载并保存到沙盒里。最后加载沙盒内匹配的清单文件。
|
||||
|
||||

|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
- LoadAssetAsync() 异步加载资源对象
|
||||
- LoadSubAssetsSync() 同步加载子资源对象
|
||||
- LoadSubAssetsAsync() 异步加载子资源对象
|
||||
- LoadSceneSync() 同步加载场景
|
||||
- LoadSceneAsync() 异步加载场景
|
||||
- LoadRawFileSync() 同步获取原生文件
|
||||
- LoadRawFileAsync() 异步获取原生文件
|
||||
|
||||
**统一约定**
|
||||
@@ -152,6 +154,7 @@ IEnumerator Start()
|
||||
yield return handle;
|
||||
byte[] fileData = handle.GetRawFileData();
|
||||
string fileText = handle.GetRawFileText();
|
||||
string filePath = handle.GetRawFilePath();
|
||||
}
|
||||
````
|
||||
|
||||
@@ -160,7 +163,7 @@ IEnumerator Start()
|
||||
通过资源标签来获取资源信息列表。
|
||||
|
||||
````c#
|
||||
private GetAssetInfosByTag(string tag)
|
||||
void GetAssetInfosByTag(string tag)
|
||||
{
|
||||
AssetInfo[] assetInfos = package.GetAssetInfos(tag);
|
||||
foreach (var assetInfo in assetInfos)
|
||||
|
||||
@@ -29,6 +29,10 @@ YooAsset依赖于ScriptBuildPipeline(SBP),在PackageManager里找到SBP插
|
||||
|
||||
Unity引擎不允许把场景文件和其它资源文件一起打包。
|
||||
|
||||
#### 问题:WebGL平台运行时报错:Failed to decompress data for the AssetBundle.
|
||||
|
||||
WebGL平台不支持资源文件加密。在构建选项里,可以将加密方法设置为空
|
||||
|
||||
#### 问题:ClearCacheWhenDirty参数没了吗?
|
||||
|
||||
不是很必须的一个功能,已经移除了。可以使用以下方法代替:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 全局配置
|
||||
|
||||

|
||||

|
||||
|
||||
通过右键创建配置文件(Project窗体内右键 -> Create -> YooAsset -> Create Setting)
|
||||
|
||||
@@ -8,7 +8,5 @@
|
||||
|
||||
配置说明:
|
||||
|
||||
- **Asset Bundle File Variant** : AssetBundle资源包后缀名
|
||||
- **Raw File Variant** : 原生资源包后缀名
|
||||
- **Patch Manifest File Name** : 补丁清单文件名称
|
||||
|
||||
|
||||
BIN
Docs/Image/AssetBuilder-img1.jpg
Normal file
|
After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 46 KiB |
BIN
Docs/Image/AssetBuilder-img2.jpg
Normal file
|
After Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 48 KiB |
BIN
Docs/Image/AssetCollector-img1.jpg
Normal file
|
After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 85 KiB |
BIN
Docs/Image/Settings-img1.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 21 KiB |
BIN
Docs/Image/ShaderVariantCollector-img1.jpg
Normal file
|
After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 26 KiB |
@@ -12,7 +12,7 @@
|
||||
|
||||
#### 导入流程注意事项
|
||||
|
||||

|
||||

|
||||
|
||||
1. Space Shooter在导入完成后,打开YooAsset->AssetBundle Collector窗口。
|
||||
1. 点击修复按钮,然后点击Save按钮保存配置,最后关闭窗口。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 着色器变种收集
|
||||
|
||||

|
||||

|
||||
|
||||
点击搜集变种按钮开始收集,请耐心等待结束。
|
||||
|
||||
|
||||