unload world scene when logout

This commit is contained in:
Le Duc Anh
2026-02-27 20:46:21 +07:00
parent 7abe98a4b1
commit 76183faa47
8 changed files with 41 additions and 51 deletions
@@ -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
@@ -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<T>();
}
@@ -551,11 +551,11 @@ namespace BrewMonster
/// Load composer from file
/// 从文件加载组合器
/// </summary>
#if UNITY_EDITOR
// #if UNITY_EDITOR
string hitGfxName;
string flyGfxName;
string hitGrdGfxName;
#endif
// #endif
public async UniTask<bool> 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)
@@ -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)
@@ -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();
}
}
@@ -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;
}
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2099d0c0fdfc641509729652b0ed485f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+2
View File
@@ -532,7 +532,9 @@ public class CECUIManager : MonoSingleton<CECUIManager>
CECHostPlayer hostPlayer = EC_Game.GetGameRun()?.GetHostPlayer();
if (hostPlayer != null)
{
#if UNITY_EDITOR
hostPlayer.CycleSkillShortcuts();
#endif
}
}