diff --git a/HKMP/Game/Client/ClientManager.cs b/HKMP/Game/Client/ClientManager.cs index ce5d5f4..6704d69 100644 --- a/HKMP/Game/Client/ClientManager.cs +++ b/HKMP/Game/Client/ClientManager.cs @@ -96,6 +96,31 @@ internal class ClientManager : IClientManager { /// private bool _autoConnect; + /// + /// The username that was last used to connect with. + /// + private string _username; + + /// + /// Keeps track of the last updated location of the local player object. + /// + private Vector3 _lastPosition; + + /// + /// Keeps track of the last updated scale of the local player object. + /// + private Vector3 _lastScale; + + /// + /// The last scene that the player was in, to check whether we should be sending that we left a certain scene. + /// + private string _lastScene; + + /// + /// Whether we have already determined whether we are scene host or not for the entity system. + /// + private bool _sceneHostDetermined; + #endregion #region IClientManager properties @@ -140,26 +165,6 @@ public string Username { #endregion - /// - /// The username that was last used to connect with. - /// - private string _username; - - /// - /// Keeps track of the last updated location of the local player object. - /// - private Vector3 _lastPosition; - - /// - /// Keeps track of the last updated scale of the local player object. - /// - private Vector3 _lastScale; - - /// - /// Whether we have already determined whether we are scene host or not for the entity system. - /// - private bool _sceneHostDetermined; - public ClientManager( NetClient netClient, ServerManager serverManager, @@ -857,6 +862,7 @@ private void OnServerSettingsUpdated(ServerSettingsUpdate update) { /// The new scene instance. private void OnSceneChange(Scene oldScene, Scene newScene) { Logger.Info($"Scene changed from {oldScene.name} to {newScene.name}"); + Logger.Debug($" Current scene: {UnityEngine.SceneManagement.SceneManager.GetActiveScene().name}"); // Always recycle existing players, because we changed scenes _playerManager.RecycleAllPlayers(); @@ -875,7 +881,7 @@ private void OnSceneChange(Scene oldScene, Scene newScene) { _sceneHostDetermined = false; // If the old scene is a gameplay scene, we need to notify the server that we left - if (!SceneUtil.IsNonGameplayScene(oldScene.name)) { + if (!SceneUtil.IsNonGameplayScene(oldScene.name) && oldScene.name == _lastScene) { _netClient.UpdateManager.SetLeftScene(); } } @@ -925,6 +931,12 @@ private void OnPlayerUpdate(On.HeroController.orig_Update orig, HeroController s /// Callback method for the local player enters a scene. Used to network to the server that a scene is entered. /// private void OnEnterScene() { + var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; + + Logger.Debug($"OnEnterScene, scene: {sceneName}"); + + _lastScene = sceneName; + // Set some default values for the packet variables in case we don't have a HeroController instance // This might happen when we are in a non-gameplay scene without the knight var position = Vector2.Zero;