Exemplo n.º 1
0
        private void OnPlayerLeaveScene(GenericClientData data)
        {
            // Destroy corresponding player
            _playerManager.DestroyPlayer(data.Id);

            Logger.Get().Info(this, $"Player {data.Id} left scene, destroying player");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Callback method for when a player leaves our scene.
        /// </summary>
        /// <param name="data">The generic client packet data.</param>
        private void OnPlayerLeaveScene(GenericClientData data)
        {
            var id = data.Id;

            Logger.Get().Info(this, $"Player {id} left scene");

            if (!_playerData.TryGetValue(id, out var playerData))
            {
                Logger.Get().Warn(this, $"Could not find player data for player with ID {id}");
                return;
            }

            // Recycle corresponding player
            _playerManager.RecyclePlayer(id);

            playerData.IsInLocalScene = false;
            foreach (Transform child in playerData.PlayerObject.transform)
            {
                foreach (Transform grandChild in child)
                {
                    Object.Destroy(grandChild.gameObject);
                }
            }

            try {
                PlayerLeaveSceneEvent?.Invoke(playerData);
            } catch (Exception e) {
                Logger.Get().Warn(this,
                                  $"Exception thrown while invoking PlayerLeaveScene event, {e.GetType()}, {e.Message}, {e.StackTrace}");
            }
        }