add debug log in mobile

This commit is contained in:
CuongNV
2026-05-20 17:23:08 +07:00
parent ba8d720ef0
commit 8f45a7f3ae
3 changed files with 48 additions and 0 deletions
@@ -61,7 +61,9 @@ namespace BrewMonster.Scripts
/// </summary>
async UniTaskVoid StartAddressablesInitAfterBootstrapGate()
{
Debug.Log("[Cuong] AddressableManager: Đang chờ GameContentBootstrap (version / URL rewrite)...");
await GameContentBootstrap.WaitForPreAddressablesSetupIfAnyAsync();
Debug.Log("[Cuong] AddressableManager: Bootstrap gate xong — đang InitializeAsync Addressables...");
Addressables.InitializeAsync().Completed += OnInitializeComplete;
}
@@ -97,11 +99,13 @@ namespace BrewMonster.Scripts
_isInitialized = true;
_initializationTcs.TrySetResult();
BMLogger.Log($"AddressableManager: Initialized");
Debug.Log("[Cuong] AddressableManager: InitializeAsync xong — sẵn sàng load asset.");
}
else
{
// print out the error
BMLogger.LogError($"AddressableManager: Failed to initialize: {handle.OperationException?.Message} {handle.OperationException?.StackTrace}");
Debug.LogError($"[Cuong] AddressableManager: InitializeAsync thất bại — {handle.OperationException?.Message}");
}
}
@@ -171,18 +171,37 @@ namespace BrewMonster.Scripts
try
{
await EnsureInitializedAsync();
var keyLabel = key?.ToString() ?? "(null)";
Debug.Log($"[Cuong] AddressablesCatalogUpdater: Đang tải dependencies (key={keyLabel})...");
var handle = Addressables.DownloadDependenciesAsync(key, autoReleaseHandle);
var lastLoggedMilestone = -1;
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}%");
}
await UniTask.Yield();
}
await handle.ToUniTask();
if (handle.Status != AsyncOperationStatus.Succeeded)
{
BMLogger.LogError($"AddressablesCatalogUpdater: DownloadDependenciesAsync failed: {handle.OperationException?.Message}");
Debug.LogError($"[Cuong] AddressablesCatalogUpdater: Tải thất bại '{keyLabel}' — {handle.OperationException?.Message}");
return false;
}
Debug.Log($"[Cuong] AddressablesCatalogUpdater: Tải xong dependencies (key={keyLabel}).");
return true;
}
catch (Exception e)
{
BMLogger.LogError($"AddressablesCatalogUpdater: DownloadDependenciesAsync exception: {e.Message}");
Debug.LogError($"[Cuong] AddressablesCatalogUpdater: Exception khi tải — {e.Message}");
return false;
}
}
@@ -123,24 +123,34 @@ namespace BrewMonster.Scripts
{
try
{
Debug.Log("[Cuong] GameContentBootstrap: Bắt đầu bootstrap Addressables...");
Debug.Log("[Cuong] GameContentBootstrap: Đang lấy contentVersion / assetsBaseUrl...");
var fetch = await ResolveVersionFetchAsync();
if (!fetch.Ok)
{
Debug.LogError($"[Cuong] GameContentBootstrap: Lỗi lấy version — {fetch.Error}");
AllowAddressablesInit();
return new BootstrapResult(false, false, fetch.Error, null);
}
Debug.Log($"[Cuong] GameContentBootstrap: Đã có contentVersion={fetch.ContentVersion}" +
(string.IsNullOrWhiteSpace(fetch.AssetsBaseUrl) ? "" : $", assetsBaseUrl={fetch.AssetsBaseUrl}"));
if (!string.IsNullOrWhiteSpace(fetch.AssetsBaseUrl) &&
!string.IsNullOrWhiteSpace(_bakedRemoteUrlPrefixForRewrite))
{
AddressablesRuntimeUrlRewriter.InstallPrefixRewrite(
_bakedRemoteUrlPrefixForRewrite,
fetch.AssetsBaseUrl);
Debug.Log("[Cuong] GameContentBootstrap: Đã gắn URL rewrite cho remote CDN.");
}
AllowAddressablesInit();
Debug.Log("[Cuong] GameContentBootstrap: Đang khởi tạo Addressables...");
await AddressablesCatalogUpdater.EnsureInitializedAsync();
Debug.Log("[Cuong] GameContentBootstrap: Addressables đã khởi tạo.");
bool firstRun = PlayerPrefs.GetInt(PrefsFirstSyncDone, 0) == 0;
string localVersion = PlayerPrefs.GetString(PrefsLastContentVersion, string.Empty);
@@ -151,33 +161,48 @@ namespace BrewMonster.Scripts
if (!needContentWork)
{
BMLogger.Log("[Cuong] GameContentBootstrap: contentVersion unchanged, skip catalog/bulk download.");
Debug.Log("[Cuong] GameContentBootstrap: Hoàn tất — không cần tải catalog/bulk (version không đổi).");
return new BootstrapResult(true, false, null, fetch.ContentVersion);
}
Debug.Log($"[Cuong] GameContentBootstrap: Cần sync nội dung (firstRun={firstRun}, localVersion='{localVersion}', serverVersion='{fetch.ContentVersion}').");
Debug.Log("[Cuong] GameContentBootstrap: Đang kiểm tra / cập nhật catalog...");
var catalog = await AddressablesCatalogUpdater.CheckAndUpdateCatalogsIfNeededAsync(false);
if (!catalog.Success)
{
Debug.LogError($"[Cuong] GameContentBootstrap: Catalog update thất bại — {catalog.Error?.Message}");
return new BootstrapResult(false, true, catalog.Error?.Message ?? "Catalog update failed", fetch.ContentVersion);
}
Debug.Log("[Cuong] GameContentBootstrap: Catalog OK.");
if (string.IsNullOrWhiteSpace(_remoteBulkDownloadLabel))
{
BMLogger.LogError("[Cuong] GameContentBootstrap: _remoteBulkDownloadLabel is empty; skipping bulk download.");
Debug.LogError("[Cuong] GameContentBootstrap: _remoteBulkDownloadLabel trống — bỏ bulk download.");
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);
if (!dl)
{
Debug.LogError("[Cuong] GameContentBootstrap: Tải remote content thất bại.");
return new BootstrapResult(false, true, "DownloadDependencies failed", fetch.ContentVersion);
}
PlayerPrefs.SetString(PrefsLastContentVersion, fetch.ContentVersion);
PlayerPrefs.SetInt(PrefsFirstSyncDone, 1);
PlayerPrefs.Save();
BMLogger.Log($"[Cuong] GameContentBootstrap: content sync OK, version={fetch.ContentVersion}");
Debug.Log($"[Cuong] GameContentBootstrap: Bootstrap hoàn tất — đã tải xong hết nội dung (version={fetch.ContentVersion}).");
return new BootstrapResult(true, true, null, fetch.ContentVersion);
}
catch (Exception e)
{
BMLogger.LogError($"[Cuong] GameContentBootstrap: {e.Message}");
Debug.LogError($"[Cuong] GameContentBootstrap: Exception — {e.Message}");
AllowAddressablesInit();
return new BootstrapResult(false, true, e.Message, null);
}