From 76183faa47f9e17673b64e2f2a7e895da02fe961 Mon Sep 17 00:00:00 2001 From: Le Duc Anh Date: Fri, 27 Feb 2026 20:46:21 +0700 Subject: [PATCH] unload world scene when logout --- .../Prefab/Task/TaskTrace/DlgTaskTrace.prefab | 30 +++++-------------- .../Scripts/Common/MonoSingleton.cs | 1 + .../Scripts/Managers/CECAttacksMan.cs | 7 +++-- .../Scripts/Network/UnityGameSession.cs | 26 +++++----------- .../Scripts/UI/Login/BtnBackToSelectRole.cs | 7 +++-- .../Scripts/World/TerrainHolder.cs | 12 ++++---- Assets/Scenes/a61.unity.meta | 7 +++++ Assets/Scripts/CECUIManager.cs | 2 ++ 8 files changed, 41 insertions(+), 51 deletions(-) create mode 100644 Assets/Scenes/a61.unity.meta diff --git a/Assets/PerfectWorld/Prefab/Task/TaskTrace/DlgTaskTrace.prefab b/Assets/PerfectWorld/Prefab/Task/TaskTrace/DlgTaskTrace.prefab index 82e651990d..f87982d5b0 100644 --- a/Assets/PerfectWorld/Prefab/Task/TaskTrace/DlgTaskTrace.prefab +++ b/Assets/PerfectWorld/Prefab/Task/TaskTrace/DlgTaskTrace.prefab @@ -37,8 +37,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 272, y: 0} - m_SizeDelta: {x: 544, y: 0} + m_AnchoredPosition: {x: 262, y: 0} + m_SizeDelta: {x: 524, y: 300} m_Pivot: {x: 0.5, y: 1} --- !u!222 &9154858122360570458 CanvasRenderer: @@ -68,21 +68,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: 'asfasf - - asfasf - - asfasf - - asfasf - - asfasf - - asfasf - - asfasf - -' + m_text: m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -109,8 +95,8 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 24 - m_fontSizeBase: 24 + m_fontSize: 30 + m_fontSizeBase: 30 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 18 @@ -1379,8 +1365,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -17.500013} - m_SizeDelta: {x: 0, y: -34.99997} + m_AnchoredPosition: {x: 0, y: -20.000013} + m_SizeDelta: {x: -20, y: -39.99997} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &1838645981218325918 CanvasRenderer: @@ -1403,7 +1389,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0, g: 0, b: 0, a: 0.34901962} + m_Color: {r: 0, g: 0, b: 0, a: 0.8} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 diff --git a/Assets/PerfectWorld/Scripts/Common/MonoSingleton.cs b/Assets/PerfectWorld/Scripts/Common/MonoSingleton.cs index 59b24a30fc..b5c3d61057 100644 --- a/Assets/PerfectWorld/Scripts/Common/MonoSingleton.cs +++ b/Assets/PerfectWorld/Scripts/Common/MonoSingleton.cs @@ -15,6 +15,7 @@ namespace BrewMonster if (_instance == null) { + BMLogger.LogError($"MonoSingleton<{typeof(T).Name}>: No instance found, creating new one"); GameObject obj = new GameObject(typeof(T).Name); _instance = obj.AddComponent(); } diff --git a/Assets/PerfectWorld/Scripts/Managers/CECAttacksMan.cs b/Assets/PerfectWorld/Scripts/Managers/CECAttacksMan.cs index 4315d3288d..6d782078be 100644 --- a/Assets/PerfectWorld/Scripts/Managers/CECAttacksMan.cs +++ b/Assets/PerfectWorld/Scripts/Managers/CECAttacksMan.cs @@ -551,11 +551,11 @@ namespace BrewMonster /// Load composer from file /// 从文件加载组合器 /// -#if UNITY_EDITOR +// #if UNITY_EDITOR string hitGfxName; string flyGfxName; string hitGrdGfxName; -#endif +// #endif public async UniTask Load(SkillStub skillStub, string flyGFXPath, string hitGrdGFXPath, string hitGFXPath) { flyGfxName = flyGFXPath; @@ -865,8 +865,9 @@ public class CECAttackEvent m_timeToBeFired = (uint)nTimeToBeFired; m_timeToDoDamage = (uint)nTimeToDoDamage; m_bFinished = false; +#if UNITY_EDITOR debugCounter = UnityEngine.Random.Range(0, 1000); - +#endif AddTarget(idTarget, dwModifier, nDamage); } public bool Tick(uint dwDeltaTime) diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 2ea519aff2..bc97f42010 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -222,9 +222,8 @@ namespace BrewMonster.Network await Task.Yield(); // Requirement: even on account logout, keep a61 loaded (do not delete the world scene), // just clean runtime objects and show LoginScene UI. - CleanRuntimeObjectsKeepWorld(); - await EnsureSceneLoadedAdditiveAsync(WorldSceneName); - await EnsureLoginSceneAdditiveAndActivateAsync(keepSceneName: WorldSceneName); + CleanRuntimeObjects(); + await EnsureLoginSceneAdditiveAndActivateAsync(); // When LoginScene is already loaded additively, Start() won't re-run. // Force the login UI to refresh to the correct entry state immediately. @@ -256,7 +255,7 @@ namespace BrewMonster.Network } } - private static void CleanRuntimeObjectsKeepWorld() + private static void CleanRuntimeObjects() { // Spawned runtime objects (player/monsters/vfx) are parented under ObjectSpawner. // Destroying them "cleans" the world without unloading the scene (a61 remains loaded). @@ -290,8 +289,10 @@ namespace BrewMonster.Network await Task.Yield(); } - private static async Task EnsureLoginSceneAdditiveAndActivateAsync(string keepSceneName) + private static async Task EnsureLoginSceneAdditiveAndActivateAsync() { + // get current active scene + var currentScene = SceneManager.GetActiveScene(); // Load LoginScene additively if needed (do not unload keepSceneName, e.g., a61). var loginScene = SceneManager.GetSceneByName(LoginSceneName); if (!loginScene.IsValid() || !loginScene.isLoaded) @@ -307,19 +308,8 @@ namespace BrewMonster.Network SceneManager.SetActiveScene(loginScene); } - // Optionally unload other non-world scenes (keep a61 + LoginScene). - // This prevents extra scenes like NPCRender staying around. - for (int i = 0; i < SceneManager.sceneCount; i++) - { - var s = SceneManager.GetSceneAt(i); - if (!s.IsValid() || !s.isLoaded) continue; - if (s.name == LoginSceneName) continue; - if (!string.IsNullOrEmpty(keepSceneName) && s.name == keepSceneName) continue; - - // Only unload if it's not the active scene (we already switched active to LoginScene above). - if (SceneManager.GetActiveScene() == s) continue; - _ = SceneManager.UnloadSceneAsync(s); - } + // unload the world scene + SceneManager.UnloadSceneAsync(currentScene); } private Task WaitForDisconnectAsync(int timeoutMs) diff --git a/Assets/PerfectWorld/Scripts/UI/Login/BtnBackToSelectRole.cs b/Assets/PerfectWorld/Scripts/UI/Login/BtnBackToSelectRole.cs index 8468a0a5e7..aa9744a94d 100644 --- a/Assets/PerfectWorld/Scripts/UI/Login/BtnBackToSelectRole.cs +++ b/Assets/PerfectWorld/Scripts/UI/Login/BtnBackToSelectRole.cs @@ -10,9 +10,12 @@ namespace BrewMonster.UI { public void OnClick() { - CECUIManager.Instance.ShowUI( "Win_Message2" ); + CECUIManager.Instance.ShowMessageBox( + title: "Thoát", + message: "Đang rời khỏi Thế Giới Hoàn Mỹ", + messageBoxType: MessageBoxType.YesButton + ); - return; UnityGameSession.ReturnToSelectRole(); } } diff --git a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs index 84b551dab8..86e53a49c7 100644 --- a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs @@ -55,11 +55,11 @@ namespace BrewMonster private void OnDisable() { // unload all the addressable objects. - foreach (var addressableObject in _addressableObjects) - { - if (addressableObject == null) continue; - addressableObject.UnloadAsset(); - } + // foreach (var addressableObject in _addressableObjects) + // { + // if (addressableObject == null) continue; + // addressableObject.UnloadAsset(); + // } } private void OnDestroy() @@ -204,7 +204,7 @@ namespace BrewMonster } if (_hostPlayer == null) return; - _currentHostPosOxz = CECGameRun.Instance.GetHostPlayer().GetPosVector3(); + _currentHostPosOxz = _hostPlayer.GetPosVector3(); _currentHostPosOxz.y = 0f; _hostPosReady = true; } diff --git a/Assets/Scenes/a61.unity.meta b/Assets/Scenes/a61.unity.meta new file mode 100644 index 0000000000..9897459ab1 --- /dev/null +++ b/Assets/Scenes/a61.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2099d0c0fdfc641509729652b0ed485f +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CECUIManager.cs b/Assets/Scripts/CECUIManager.cs index 0329ed0c94..fb8068b6ff 100644 --- a/Assets/Scripts/CECUIManager.cs +++ b/Assets/Scripts/CECUIManager.cs @@ -532,7 +532,9 @@ public class CECUIManager : MonoSingleton CECHostPlayer hostPlayer = EC_Game.GetGameRun()?.GetHostPlayer(); if (hostPlayer != null) { +#if UNITY_EDITOR hostPlayer.CycleSkillShortcuts(); +#endif } }