From 84b84567c6adf7a27466714e1046cc7e9480cd3a Mon Sep 17 00:00:00 2001
From: CuongNV <>
Date: Thu, 21 May 2026 10:42:51 +0700
Subject: [PATCH] add log percent
---
.../Addressable/AddressablesCatalogUpdater.cs | 55 ++++++++++++++++---
.../Addressable/GameContentBootstrap.cs | 21 ++++++-
2 files changed, 65 insertions(+), 11 deletions(-)
diff --git a/Assets/PerfectWorld/Scripts/Addressable/AddressablesCatalogUpdater.cs b/Assets/PerfectWorld/Scripts/Addressable/AddressablesCatalogUpdater.cs
index eb5be453eb..bca4ebaf8f 100644
--- a/Assets/PerfectWorld/Scripts/Addressable/AddressablesCatalogUpdater.cs
+++ b/Assets/PerfectWorld/Scripts/Addressable/AddressablesCatalogUpdater.cs
@@ -165,28 +165,32 @@ namespace BrewMonster.Scripts
///
/// Ensures dependencies for exist on disk; uses cache when CRC/catalog match (no redundant full download).
+ /// Logs download percent (and MB when known) every percent via [Cuong].
///
- public static async UniTask DownloadDependenciesAsync(object key, bool autoReleaseHandle = true)
+ /// Log when percent crosses each step (1–100). Default 5.
+ public static async UniTask DownloadDependenciesAsync(
+ object key,
+ bool autoReleaseHandle = true,
+ int progressLogStepPercent = 5)
{
try
{
await EnsureInitializedAsync();
var keyLabel = key?.ToString() ?? "(null)";
- Debug.Log($"[Cuong] AddressablesCatalogUpdater: Đang tải dependencies (key={keyLabel})...");
+ var step = Mathf.Clamp(progressLogStepPercent, 1, 100);
+ Debug.Log($"[Cuong] AddressablesCatalogUpdater: Bắt đầu tải dependencies (key={keyLabel})...");
var handle = Addressables.DownloadDependenciesAsync(key, autoReleaseHandle);
- var lastLoggedMilestone = -1;
+ var lastLoggedPercent = -1;
+ LogDownloadProgress(keyLabel, handle, ref lastLoggedPercent, step, force: true);
+
while (!handle.IsDone)
{
- var milestone = (int)(handle.PercentComplete * 10f);
- if (milestone > lastLoggedMilestone)
- {
- lastLoggedMilestone = milestone;
- Debug.Log($"[Cuong] AddressablesCatalogUpdater: Đang tải '{keyLabel}'... {handle.PercentComplete * 100f:F0}%");
- }
+ LogDownloadProgress(keyLabel, handle, ref lastLoggedPercent, step);
await UniTask.Yield();
}
+ LogDownloadProgress(keyLabel, handle, ref lastLoggedPercent, step, force: true);
await handle.ToUniTask();
if (handle.Status != AsyncOperationStatus.Succeeded)
{
@@ -206,6 +210,39 @@ namespace BrewMonster.Scripts
}
}
+ static void LogDownloadProgress(
+ string keyLabel,
+ AsyncOperationHandle handle,
+ ref int lastLoggedPercent,
+ int stepPercent,
+ bool force = false)
+ {
+ var status = handle.GetDownloadStatus();
+ var percent = Mathf.Clamp(status.Percent * 100f, 0f, 100f);
+ var percentRounded = Mathf.RoundToInt(percent);
+
+ if (!force)
+ {
+ if (percentRounded <= lastLoggedPercent)
+ return;
+ if (percentRounded < 100 && percentRounded - lastLoggedPercent < stepPercent)
+ return;
+ }
+
+ lastLoggedPercent = percentRounded;
+ if (status.TotalBytes > 0)
+ {
+ var downloadedMb = status.DownloadedBytes / (1024f * 1024f);
+ var totalMb = status.TotalBytes / (1024f * 1024f);
+ Debug.Log(
+ $"[Cuong] AddressablesCatalogUpdater: {percent:F0}% ({downloadedMb:F1}/{totalMb:F1} MB) — key={keyLabel}");
+ }
+ else
+ {
+ Debug.Log($"[Cuong] AddressablesCatalogUpdater: {percent:F0}% — key={keyLabel}");
+ }
+ }
+
///
/// Removes bundles not referenced by the given catalogs (optional maintenance / “clear old cache”).
///
diff --git a/Assets/PerfectWorld/Scripts/Addressable/GameContentBootstrap.cs b/Assets/PerfectWorld/Scripts/Addressable/GameContentBootstrap.cs
index 629cb81c9e..47549e6318 100644
--- a/Assets/PerfectWorld/Scripts/Addressable/GameContentBootstrap.cs
+++ b/Assets/PerfectWorld/Scripts/Addressable/GameContentBootstrap.cs
@@ -183,8 +183,25 @@ namespace BrewMonster.Scripts
return new BootstrapResult(false, true, "remoteBulkDownloadLabel empty", fetch.ContentVersion);
}
- Debug.Log($"[Cuong] GameContentBootstrap: Đang tải toàn bộ remote content (label={_remoteBulkDownloadLabel})...");
- bool dl = await AddressablesCatalogUpdater.DownloadDependenciesAsync(_remoteBulkDownloadLabel.Trim(), true);
+ var bulkLabel = _remoteBulkDownloadLabel.Trim();
+ var downloadBytes = await AddressablesCatalogUpdater.GetDownloadSizeBytesAsync(bulkLabel);
+ if (downloadBytes > 0)
+ {
+ Debug.Log(
+ $"[Cuong] GameContentBootstrap: Đang tải remote content (label={bulkLabel}), dung lượng cần tải ~{downloadBytes / (1024f * 1024f):F1} MB...");
+ }
+ else if (downloadBytes == 0)
+ {
+ Debug.Log(
+ $"[Cuong] GameContentBootstrap: Remote content (label={bulkLabel}) đã có trong cache — vẫn chạy DownloadDependencies để đồng bộ.");
+ }
+ else
+ {
+ Debug.Log(
+ $"[Cuong] GameContentBootstrap: Đang tải remote content (label={bulkLabel}) — không lấy được dung lượng trước khi tải.");
+ }
+
+ bool dl = await AddressablesCatalogUpdater.DownloadDependenciesAsync(bulkLabel, true);
if (!dl)
{
Debug.LogError("[Cuong] GameContentBootstrap: Tải remote content thất bại.");