mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-26 02:30:18 +00:00
Compare commits
7 Commits
2.3.16
...
4caf733ac6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4caf733ac6 | ||
|
|
014b17f5cb | ||
|
|
f3ebda0c04 | ||
|
|
5602addaca | ||
|
|
c4ae67aa8e | ||
|
|
bbcc3bf971 | ||
|
|
8b0e75b9b3 |
@@ -32,17 +32,10 @@ namespace YooAsset.Editor
|
||||
|
||||
// 开始扫描工作
|
||||
ScanReport report = scanner.RunScanner();
|
||||
|
||||
// 检测报告合法性
|
||||
report.CheckError();
|
||||
|
||||
// 保存扫描结果
|
||||
string saveDirectory = scanner.SaveDirectory;
|
||||
if (string.IsNullOrEmpty(saveDirectory))
|
||||
saveDirectory = "Assets/";
|
||||
string filePath = $"{saveDirectory}/{scanner.ScannerName}_{scanner.ScannerDesc}.json";
|
||||
ScanReportConfig.ExportJsonConfig(filePath, report);
|
||||
return new ScannerResult(filePath, report);
|
||||
// 返回扫描结果
|
||||
return new ScannerResult(report);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -3,11 +3,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class ScannerResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成的报告文件路径
|
||||
/// </summary>
|
||||
public string ReprotFilePath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 报告对象
|
||||
/// </summary>
|
||||
@@ -43,11 +38,9 @@ namespace YooAsset.Editor
|
||||
ErrorInfo = error;
|
||||
ErrorStack = stack;
|
||||
}
|
||||
public ScannerResult(string filePath, ScanReport report)
|
||||
public ScannerResult(ScanReport report)
|
||||
{
|
||||
ReprotFilePath = filePath;
|
||||
Report = report;
|
||||
ErrorInfo = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,5 +54,19 @@ namespace YooAsset.Editor
|
||||
reproterWindow.ImportSingleReprotFile(Report);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存报告文件
|
||||
/// </summary>
|
||||
public void SaveReportFile(string saveDirectory)
|
||||
{
|
||||
if (Report == null)
|
||||
throw new System.Exception("Scan report is invalid !");
|
||||
|
||||
if (string.IsNullOrEmpty(saveDirectory))
|
||||
saveDirectory = "Assets/";
|
||||
string filePath = $"{saveDirectory}/{Report.ReportName}_{Report.ReportDesc}.json";
|
||||
ScanReportConfig.ExportJsonConfig(filePath, Report);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,27 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string[] GetAllPackAssetPaths()
|
||||
{
|
||||
return AllPackAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
|
||||
List<string> results = new List<string>(AllPackAssets.Count);
|
||||
for (int i = 0; i < AllPackAssets.Count; i++)
|
||||
{
|
||||
var packAsset = AllPackAssets[i];
|
||||
results.Add(packAsset.AssetInfo.AssetPath);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建的资源可寻址列表
|
||||
/// </summary>
|
||||
public string[] GetAllPackAssetAddress()
|
||||
{
|
||||
List<string> results = new List<string>(AllPackAssets.Count);
|
||||
for (int i = 0; i < AllPackAssets.Count; i++)
|
||||
{
|
||||
var packAsset = AllPackAssets[i];
|
||||
results.Add(packAsset.Address);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,13 +173,15 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 创建AssetBundleBuild类
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild(bool replaceAssetPathWithAddress)
|
||||
{
|
||||
// 注意:我们不再支持AssetBundle的变种机制
|
||||
AssetBundleBuild build = new AssetBundleBuild();
|
||||
build.assetBundleName = BundleName;
|
||||
build.assetBundleVariant = string.Empty;
|
||||
build.assetNames = GetAllPackAssetPaths();
|
||||
if (replaceAssetPathWithAddress)
|
||||
build.addressableNames = GetAllPackAssetAddress();
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,12 +96,12 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取构建管线里需要的数据
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
|
||||
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds(bool replaceAssetPathWithAddres)
|
||||
{
|
||||
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(_bundleInfoDic.Count);
|
||||
foreach (var bundleInfo in _bundleInfoDic.Values)
|
||||
{
|
||||
builds.Add(bundleInfo.CreatePipelineBuild());
|
||||
builds.Add(bundleInfo.CreatePipelineBuild(replaceAssetPathWithAddres));
|
||||
}
|
||||
return builds.ToArray();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 创建补丁清单文件到输出目录
|
||||
/// </summary>
|
||||
protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, BuildContext context)
|
||||
protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, bool replaceAssetPathWithAddress, BuildContext context)
|
||||
{
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
@@ -36,6 +36,7 @@ namespace YooAsset.Editor
|
||||
manifest.SupportExtensionless = buildMapContext.Command.SupportExtensionless;
|
||||
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
|
||||
manifest.ReplaceAssetPathWithAddress = replaceAssetPathWithAddress;
|
||||
manifest.OutputNameStyle = (int)buildParameters.FileNameStyle;
|
||||
manifest.BuildBundleType = buildParameters.BuildBundleType;
|
||||
manifest.BuildPipeline = buildParameters.BuildPipeline;
|
||||
@@ -58,7 +59,13 @@ namespace YooAsset.Editor
|
||||
|
||||
// 4. 处理内置资源包
|
||||
if (processBundleDepends)
|
||||
{
|
||||
// 注意:初始化资源清单建立引用关系
|
||||
manifest.Initialize();
|
||||
|
||||
ProcessBuiltinBundleDependency(context, manifest);
|
||||
}
|
||||
|
||||
|
||||
// 创建资源清单文本文件
|
||||
{
|
||||
@@ -302,9 +309,6 @@ namespace YooAsset.Editor
|
||||
#region YOOASSET_LEGACY_DEPENDENCY
|
||||
private void ProcessBuiltinBundleDependency(BuildContext context, PackageManifest manifest)
|
||||
{
|
||||
// 注意:初始化资源清单建立引用关系
|
||||
ManifestTools.InitManifest(manifest);
|
||||
|
||||
// 注意:如果是可编程构建管线,需要补充内置资源包
|
||||
// 注意:该步骤依赖前面的操作!
|
||||
var buildResultContext = context.TryGetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption;
|
||||
buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.ReplaceAssetPathWithAddress = builtinBuildParameters.ReplaceAssetPathWithAddress;
|
||||
}
|
||||
else if (buildParameters is ScriptableBuildParameters)
|
||||
{
|
||||
@@ -61,6 +62,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption;
|
||||
buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.ReplaceAssetPathWithAddress = scriptableBuildParameters.ReplaceAssetPathWithAddress;
|
||||
buildReport.Summary.WriteLinkXML = scriptableBuildParameters.WriteLinkXML;
|
||||
buildReport.Summary.CacheServerHost = scriptableBuildParameters.CacheServerHost;
|
||||
buildReport.Summary.CacheServerPort = scriptableBuildParameters.CacheServerPort;
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace YooAsset.Editor
|
||||
// 开始构建
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
BuildAssetBundleOptions buildOptions = builtinBuildParameters.GetBundleBuildOptions();
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget);
|
||||
var bundleBuilds = buildMapContext.GetPipelineBuilds(builtinBuildParameters.ReplaceAssetPathWithAddress);
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, bundleBuilds, buildOptions, buildParametersContext.Parameters.BuildTarget);
|
||||
if (unityManifest == null)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFailed, "UnityEngine build failed !");
|
||||
|
||||
@@ -11,7 +11,10 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(true, true, context);
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var builtinBuildParameters = buildParametersContext.Parameters as BuiltinBuildParameters;
|
||||
bool replaceAssetPathWithAddress = builtinBuildParameters.ReplaceAssetPathWithAddress;
|
||||
CreateManifestFile(true, true, replaceAssetPathWithAddress, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -27,6 +27,12 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置构建管线的构建选项
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, false, context);
|
||||
CreateManifestFile(false, false, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, true, context);
|
||||
CreateManifestFile(false, true, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -24,7 +24,8 @@ namespace YooAsset.Editor
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
|
||||
// 构建内容
|
||||
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
|
||||
var bundleBuilds = buildMapContext.GetPipelineBuilds(scriptableBuildParameters.ReplaceAssetPathWithAddress);
|
||||
var buildContent = new BundleBuildContent(bundleBuilds);
|
||||
|
||||
// 开始构建
|
||||
IBundleBuildResults buildResults;
|
||||
|
||||
@@ -13,7 +13,10 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(true, true, context);
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
bool replaceAssetPathWithAddress = scriptableBuildParameters.ReplaceAssetPathWithAddress;
|
||||
CreateManifestFile(true, true, replaceAssetPathWithAddress, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -29,6 +29,12 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自动建立资源对象对图集的依赖关系
|
||||
/// </summary>
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace YooAsset.Editor
|
||||
public ECompressOption CompressOption;
|
||||
public bool DisableWriteTypeTree;
|
||||
public bool IgnoreTypeTreeChanges;
|
||||
public bool ReplaceAssetPathWithAddress;
|
||||
public bool WriteLinkXML = true;
|
||||
public string CacheServerHost;
|
||||
public int CacheServerPort;
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace YooAsset.Editor
|
||||
BindListViewItem("CompressOption", $"{buildReport.Summary.CompressOption}");
|
||||
BindListViewItem("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}");
|
||||
BindListViewItem("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}");
|
||||
BindListViewItem("ReplaceAssetPathWithAddress", $"{buildReport.Summary.ReplaceAssetPathWithAddress}");
|
||||
BindListViewItem(string.Empty, string.Empty);
|
||||
|
||||
BindListViewHeader("Build Results");
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace YooAsset
|
||||
public string CopyBuildinPackageManifestDestRoot { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace YooAsset
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件服务类
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
/// </summary>
|
||||
public ICopyLocalFileServices CopyLocalFileServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace YooAsset
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// 自定义参数:远程服务接口的实例类
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; }
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace YooAsset
|
||||
public List<long> ResumeDownloadResponseCodes { private set; get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace YooAsset
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件服务类
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
/// </summary>
|
||||
public ICopyLocalFileServices CopyLocalFileServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
@@ -44,12 +44,12 @@ namespace YooAsset
|
||||
public bool DisableUnityWebCache { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:跨域下载服务接口
|
||||
/// 自定义参数:远程服务接口的实例类(支持跨域下载)
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IWebDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace YooAsset
|
||||
public bool DisableUnityWebCache { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IWebDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ namespace YooAsset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_watch == null)
|
||||
return false;
|
||||
|
||||
// NOTE : 单次调用开销约1微秒
|
||||
return _watch.ElapsedMilliseconds - _frameTime >= MaxTimeSlice;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,13 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 文件格式版本
|
||||
/// </summary>
|
||||
public const string FileVersion = "2025.8.28";
|
||||
public const string FileVersion = "2025.9.30";
|
||||
public const string VERSION_2025_8_28 = "2025.8.28";
|
||||
public const string VERSION_2025_9_30 = "2025.9.30";
|
||||
|
||||
/// <summary>
|
||||
/// 版本兼容
|
||||
/// </summary>
|
||||
public const bool BackwardCompatible = true;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ namespace YooAsset
|
||||
buffer.WriteBool(manifest.SupportExtensionless);
|
||||
buffer.WriteBool(manifest.LocationToLower);
|
||||
buffer.WriteBool(manifest.IncludeAssetGUID);
|
||||
buffer.WriteBool(manifest.ReplaceAssetPathWithAddress);
|
||||
buffer.WriteInt32(manifest.OutputNameStyle);
|
||||
buffer.WriteInt32(manifest.BuildBundleType);
|
||||
buffer.WriteUTF8(manifest.BuildPipeline);
|
||||
@@ -119,7 +120,18 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static PackageManifest DeserializeFromJson(string jsonContent)
|
||||
{
|
||||
return JsonUtility.FromJson<PackageManifest>(jsonContent);
|
||||
var manifest = JsonUtility.FromJson<PackageManifest>(jsonContent);
|
||||
|
||||
// 初始化资源包
|
||||
for (int i = 0; i < manifest.BundleList.Count; i++)
|
||||
{
|
||||
var packageBundle = manifest.BundleList[i];
|
||||
packageBundle.InitBundle(manifest);
|
||||
}
|
||||
|
||||
// 初始化资源清单
|
||||
manifest.Initialize();
|
||||
return manifest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,218 +139,12 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static PackageManifest DeserializeFromBinary(byte[] binaryData, IManifestRestoreServices services)
|
||||
{
|
||||
// 创建缓存器
|
||||
BufferReader buffer;
|
||||
if (services != null)
|
||||
{
|
||||
var resultBytes = services.RestoreManifest(binaryData);
|
||||
buffer = new BufferReader(resultBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = new BufferReader(binaryData);
|
||||
}
|
||||
|
||||
// 读取文件标记
|
||||
uint fileSign = buffer.ReadUInt32();
|
||||
if (fileSign != ManifestDefine.FileSign)
|
||||
throw new Exception("Invalid manifest file !");
|
||||
|
||||
// 读取文件版本
|
||||
string fileVersion = buffer.ReadUTF8();
|
||||
if (fileVersion != ManifestDefine.FileVersion)
|
||||
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {ManifestDefine.FileVersion}");
|
||||
|
||||
PackageManifest manifest = new PackageManifest();
|
||||
{
|
||||
// 读取文件头信息
|
||||
manifest.FileVersion = fileVersion;
|
||||
manifest.EnableAddressable = buffer.ReadBool();
|
||||
manifest.SupportExtensionless = buffer.ReadBool();
|
||||
manifest.LocationToLower = buffer.ReadBool();
|
||||
manifest.IncludeAssetGUID = buffer.ReadBool();
|
||||
manifest.OutputNameStyle = buffer.ReadInt32();
|
||||
manifest.BuildBundleType = buffer.ReadInt32();
|
||||
manifest.BuildPipeline = buffer.ReadUTF8();
|
||||
manifest.PackageName = buffer.ReadUTF8();
|
||||
manifest.PackageVersion = buffer.ReadUTF8();
|
||||
manifest.PackageNote = buffer.ReadUTF8();
|
||||
|
||||
// 检测配置
|
||||
if (manifest.EnableAddressable && manifest.LocationToLower)
|
||||
throw new Exception("Addressable not support location to lower !");
|
||||
|
||||
// 读取资源列表
|
||||
int packageAssetCount = buffer.ReadInt32();
|
||||
CreateAssetCollection(manifest, packageAssetCount);
|
||||
for (int i = 0; i < packageAssetCount; i++)
|
||||
{
|
||||
var packageAsset = new PackageAsset();
|
||||
packageAsset.Address = buffer.ReadUTF8();
|
||||
packageAsset.AssetPath = buffer.ReadUTF8();
|
||||
packageAsset.AssetGUID = buffer.ReadUTF8();
|
||||
packageAsset.AssetTags = buffer.ReadUTF8Array();
|
||||
packageAsset.BundleID = buffer.ReadInt32();
|
||||
packageAsset.DependBundleIDs = buffer.ReadInt32Array();
|
||||
FillAssetCollection(manifest, packageAsset);
|
||||
}
|
||||
|
||||
// 读取资源包列表
|
||||
int packageBundleCount = buffer.ReadInt32();
|
||||
CreateBundleCollection(manifest, packageBundleCount);
|
||||
for (int i = 0; i < packageBundleCount; i++)
|
||||
{
|
||||
var packageBundle = new PackageBundle();
|
||||
packageBundle.BundleName = buffer.ReadUTF8();
|
||||
packageBundle.UnityCRC = buffer.ReadUInt32();
|
||||
packageBundle.FileHash = buffer.ReadUTF8();
|
||||
packageBundle.FileCRC = buffer.ReadUInt32();
|
||||
packageBundle.FileSize = buffer.ReadInt64();
|
||||
packageBundle.Encrypted = buffer.ReadBool();
|
||||
packageBundle.Tags = buffer.ReadUTF8Array();
|
||||
packageBundle.DependBundleIDs = buffer.ReadInt32Array();
|
||||
FillBundleCollection(manifest, packageBundle);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化资源清单
|
||||
InitManifest(manifest);
|
||||
return manifest;
|
||||
DeserializeManifestOperation operation = new DeserializeManifestOperation(services, binaryData);
|
||||
operation.StartOperation();
|
||||
operation.WaitForAsyncComplete();
|
||||
return operation.Manifest;
|
||||
}
|
||||
|
||||
|
||||
#region 解析资源清单辅助方法
|
||||
public static void InitManifest(PackageManifest manifest)
|
||||
{
|
||||
// 填充资源包内包含的主资源列表
|
||||
foreach (var packageAsset in manifest.AssetList)
|
||||
{
|
||||
int bundleID = packageAsset.BundleID;
|
||||
if (bundleID >= 0 && bundleID < manifest.BundleList.Count)
|
||||
{
|
||||
var packageBundle = manifest.BundleList[bundleID];
|
||||
packageBundle.IncludeMainAssets.Add(packageAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {packageAsset.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// 填充资源包引用关系
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
var sourceBundle = manifest.BundleList[index];
|
||||
foreach (int dependIndex in sourceBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = manifest.BundleList[dependIndex];
|
||||
dependBundle.AddReferenceBundleID(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateAssetCollection(PackageManifest manifest, int assetCount)
|
||||
{
|
||||
manifest.AssetList = new List<PackageAsset>(assetCount);
|
||||
manifest.AssetDic = new Dictionary<string, PackageAsset>(assetCount);
|
||||
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (manifest.LocationToLower)
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2, StringComparer.OrdinalIgnoreCase);
|
||||
else
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
|
||||
}
|
||||
|
||||
if (manifest.IncludeAssetGUID)
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>(assetCount);
|
||||
else
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>();
|
||||
}
|
||||
public static void FillAssetCollection(PackageManifest manifest, PackageAsset packageAsset)
|
||||
{
|
||||
// 添加到列表集合
|
||||
manifest.AssetList.Add(packageAsset);
|
||||
|
||||
// 注意:我们不允许原始路径存在重名
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
if (manifest.AssetDic.ContainsKey(assetPath))
|
||||
throw new System.Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
|
||||
// 填充AssetPathMapping1
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (manifest.SupportExtensionless)
|
||||
{
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (ReferenceEquals(location, locationWithoutExtension) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加可寻址地址
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 填充AssetPathMapping2
|
||||
if (manifest.IncludeAssetGUID)
|
||||
{
|
||||
if (manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
|
||||
throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
|
||||
else
|
||||
manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateBundleCollection(PackageManifest manifest, int bundleCount)
|
||||
{
|
||||
manifest.BundleList = new List<PackageBundle>(bundleCount);
|
||||
manifest.BundleDic1 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic3 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
}
|
||||
public static void FillBundleCollection(PackageManifest manifest, PackageBundle packageBundle)
|
||||
{
|
||||
// 初始化资源包
|
||||
packageBundle.InitBundle(manifest);
|
||||
|
||||
// 添加到列表集合
|
||||
manifest.BundleList.Add(packageBundle);
|
||||
|
||||
manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
manifest.BundleDic3.Add(packageBundle.BundleGUID, packageBundle);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源文件的后缀名
|
||||
/// </summary>
|
||||
|
||||
@@ -84,7 +84,10 @@ namespace YooAsset
|
||||
|
||||
// 读取文件版本
|
||||
string fileVersion = _buffer.ReadUTF8();
|
||||
if (fileVersion != ManifestDefine.FileVersion)
|
||||
Version fileVer = new Version(fileVersion);
|
||||
Version ver2025_8_28 = new Version(ManifestDefine.VERSION_2025_8_28);
|
||||
Version ver2025_9_30 = new Version(ManifestDefine.VERSION_2025_9_30);
|
||||
if (fileVer < ver2025_8_28)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
@@ -99,6 +102,10 @@ namespace YooAsset
|
||||
Manifest.SupportExtensionless = _buffer.ReadBool();
|
||||
Manifest.LocationToLower = _buffer.ReadBool();
|
||||
Manifest.IncludeAssetGUID = _buffer.ReadBool();
|
||||
if (fileVer >= ver2025_9_30)
|
||||
Manifest.ReplaceAssetPathWithAddress = _buffer.ReadBool();
|
||||
else
|
||||
Manifest.ReplaceAssetPathWithAddress = false;
|
||||
Manifest.OutputNameStyle = _buffer.ReadInt32();
|
||||
Manifest.BuildBundleType = _buffer.ReadInt32();
|
||||
Manifest.BuildPipeline = _buffer.ReadUTF8();
|
||||
@@ -109,6 +116,8 @@ namespace YooAsset
|
||||
// 检测配置
|
||||
if (Manifest.EnableAddressable && Manifest.LocationToLower)
|
||||
throw new System.Exception("Addressable not support location to lower !");
|
||||
if (Manifest.EnableAddressable == false && Manifest.ReplaceAssetPathWithAddress)
|
||||
throw new System.Exception("Replace asset path with address need enable Addressable !");
|
||||
|
||||
_steps = ESteps.PrepareAssetList;
|
||||
}
|
||||
@@ -117,26 +126,44 @@ namespace YooAsset
|
||||
{
|
||||
_packageAssetCount = _buffer.ReadInt32();
|
||||
_progressTotalValue = _packageAssetCount;
|
||||
ManifestTools.CreateAssetCollection(Manifest, _packageAssetCount);
|
||||
CreateAssetCollection(Manifest, _packageAssetCount);
|
||||
_steps = ESteps.DeserializeAssetList;
|
||||
}
|
||||
if (_steps == ESteps.DeserializeAssetList)
|
||||
{
|
||||
bool replaceAssetPath = false;
|
||||
if (UnityEngine.Application.isPlaying)
|
||||
{
|
||||
if (Manifest.EnableAddressable && Manifest.ReplaceAssetPathWithAddress)
|
||||
replaceAssetPath = true;
|
||||
}
|
||||
|
||||
while (_packageAssetCount > 0)
|
||||
{
|
||||
var packageAsset = new PackageAsset();
|
||||
packageAsset.Address = _buffer.ReadUTF8();
|
||||
packageAsset.AssetPath = _buffer.ReadUTF8();
|
||||
if (replaceAssetPath)
|
||||
{
|
||||
packageAsset.AssetPath = packageAsset.Address;
|
||||
_buffer.SkipUTF8(); //跳过解析AssetPath
|
||||
}
|
||||
else
|
||||
{
|
||||
packageAsset.AssetPath = _buffer.ReadUTF8();
|
||||
}
|
||||
packageAsset.AssetGUID = _buffer.ReadUTF8();
|
||||
packageAsset.AssetTags = _buffer.ReadUTF8Array();
|
||||
packageAsset.BundleID = _buffer.ReadInt32();
|
||||
packageAsset.DependBundleIDs = _buffer.ReadInt32Array();
|
||||
ManifestTools.FillAssetCollection(Manifest, packageAsset);
|
||||
FillAssetCollection(Manifest, packageAsset, replaceAssetPath);
|
||||
|
||||
_packageAssetCount--;
|
||||
Progress = 1f - _packageAssetCount / _progressTotalValue;
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_packageAssetCount <= 0)
|
||||
@@ -149,7 +176,7 @@ namespace YooAsset
|
||||
{
|
||||
_packageBundleCount = _buffer.ReadInt32();
|
||||
_progressTotalValue = _packageBundleCount;
|
||||
ManifestTools.CreateBundleCollection(Manifest, _packageBundleCount);
|
||||
CreateBundleCollection(Manifest, _packageBundleCount);
|
||||
_steps = ESteps.DeserializeBundleList;
|
||||
}
|
||||
if (_steps == ESteps.DeserializeBundleList)
|
||||
@@ -165,12 +192,15 @@ namespace YooAsset
|
||||
packageBundle.Encrypted = _buffer.ReadBool();
|
||||
packageBundle.Tags = _buffer.ReadUTF8Array();
|
||||
packageBundle.DependBundleIDs = _buffer.ReadInt32Array();
|
||||
ManifestTools.FillBundleCollection(Manifest, packageBundle);
|
||||
FillBundleCollection(Manifest, packageBundle);
|
||||
|
||||
_packageBundleCount--;
|
||||
Progress = 1f - _packageBundleCount / _progressTotalValue;
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_packageBundleCount <= 0)
|
||||
@@ -181,7 +211,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.InitManifest)
|
||||
{
|
||||
ManifestTools.InitManifest(Manifest);
|
||||
Manifest.Initialize();
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
@@ -194,5 +224,117 @@ namespace YooAsset
|
||||
Error = e.Message;
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateAssetCollection(PackageManifest manifest, int assetCount)
|
||||
{
|
||||
manifest.AssetList = new List<PackageAsset>(assetCount);
|
||||
manifest.AssetDic = new Dictionary<string, PackageAsset>(assetCount);
|
||||
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (manifest.LocationToLower)
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2, StringComparer.OrdinalIgnoreCase);
|
||||
else
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
|
||||
}
|
||||
|
||||
if (manifest.IncludeAssetGUID)
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>(assetCount);
|
||||
else
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>();
|
||||
}
|
||||
private void FillAssetCollection(PackageManifest manifest, PackageAsset packageAsset, bool replaceAssetPath)
|
||||
{
|
||||
// 添加到列表集合
|
||||
manifest.AssetList.Add(packageAsset);
|
||||
|
||||
// 注意:我们不允许原始路径存在重名
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
if (manifest.AssetDic.ContainsKey(assetPath))
|
||||
throw new System.Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
|
||||
// 填充AssetPathMapping1
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (manifest.SupportExtensionless)
|
||||
{
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (ReferenceEquals(location, locationWithoutExtension) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 填充AssetPathMapping2
|
||||
if (manifest.IncludeAssetGUID)
|
||||
{
|
||||
if (manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
|
||||
throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
|
||||
else
|
||||
manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
|
||||
}
|
||||
|
||||
// 添加可寻址地址
|
||||
if (manifest.EnableAddressable && replaceAssetPath == false)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateBundleCollection(PackageManifest manifest, int bundleCount)
|
||||
{
|
||||
manifest.BundleList = new List<PackageBundle>(bundleCount);
|
||||
manifest.BundleDic1 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic3 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
}
|
||||
private void FillBundleCollection(PackageManifest manifest, PackageBundle packageBundle)
|
||||
{
|
||||
// 初始化资源包
|
||||
packageBundle.InitBundle(manifest);
|
||||
|
||||
// 添加到列表集合
|
||||
manifest.BundleList.Add(packageBundle);
|
||||
|
||||
manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
manifest.BundleDic3.Add(packageBundle.BundleGUID, packageBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称样式
|
||||
/// </summary>
|
||||
|
||||
@@ -36,6 +36,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称样式
|
||||
/// </summary>
|
||||
@@ -113,6 +118,38 @@ namespace YooAsset
|
||||
public Dictionary<string, PackageBundle> BundleDic3;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化资源清单
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
// 填充资源包内包含的主资源列表
|
||||
foreach (var packageAsset in AssetList)
|
||||
{
|
||||
int bundleID = packageAsset.BundleID;
|
||||
if (bundleID >= 0 && bundleID < BundleList.Count)
|
||||
{
|
||||
var packageBundle = BundleList[bundleID];
|
||||
packageBundle.IncludeMainAssets.Add(packageAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {packageAsset.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// 填充资源包引用关系
|
||||
for (int index = 0; index < BundleList.Count; index++)
|
||||
{
|
||||
var sourceBundle = BundleList[index];
|
||||
foreach (int dependIndex in sourceBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = BundleList[dependIndex];
|
||||
dependBundle.AddReferenceBundleID(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹的详细信息
|
||||
/// </summary>
|
||||
@@ -124,6 +161,7 @@ namespace YooAsset
|
||||
details.SupportExtensionless = SupportExtensionless;
|
||||
details.LocationToLower = LocationToLower;
|
||||
details.IncludeAssetGUID = IncludeAssetGUID;
|
||||
details.ReplaceAssetPathWithAddress = ReplaceAssetPathWithAddress;
|
||||
details.OutputNameStyle = OutputNameStyle;
|
||||
details.BuildBundleType = BuildBundleType;
|
||||
details.BuildPipeline = BuildPipeline;
|
||||
|
||||
@@ -120,6 +120,15 @@ namespace YooAsset
|
||||
return (ulong)ReadInt64();
|
||||
}
|
||||
|
||||
public void SkipUTF8()
|
||||
{
|
||||
ushort count = ReadUInt16();
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
CheckReaderIndex(count);
|
||||
_index += count;
|
||||
}
|
||||
public string ReadUTF8()
|
||||
{
|
||||
ushort count = ReadUInt16();
|
||||
|
||||
@@ -106,6 +106,9 @@ public static class ShaderVariantCollector
|
||||
|
||||
if (_steps == ESteps.CollectSleeping)
|
||||
{
|
||||
if (ShaderUtil.anythingCompiling)
|
||||
return;
|
||||
|
||||
if (_elapsedTime.ElapsedMilliseconds > SleepMilliseconds)
|
||||
{
|
||||
DestroyAllSpheres();
|
||||
|
||||
@@ -8,10 +8,20 @@ using TapTapMiniGame;
|
||||
|
||||
public static class TaptapFileSystemCreater
|
||||
{
|
||||
public static FileSystemParameters CreateFileSystemParameters(string packageRoot)
|
||||
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices)
|
||||
{
|
||||
string fileSystemClass = $"{nameof(TaptapFileSystem)},YooAsset.MiniGame";
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices, IWebDecryptionServices decryptionServices)
|
||||
{
|
||||
string fileSystemClass = $"{nameof(TaptapFileSystem)},YooAsset.MiniGame";
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user