Пример #1
0
    /// <summary>
    /// Adds a NetworkPlayer to the networks manager pool of clients and sets the ID, also the manager will hook to some player events to be able to manage it on state changes.
    /// </summary>
    /// <param name="player">The NetworkPlayer in cuestion</param>
    public void AddNetPlayer(NetworkPlayer player)
    {
        //Add the player to the list and hook the ready event so we can check to start the game
        PlayersConnected.Add(player);
        player.PlayerBecameReady += NetPlayerGotReady;

        //If we are the server update the ID of the players so they are unique
        if (Is_Server)
        {
            UpdatePlayers_ID();
        }

        string currentSceneName = SceneManager.GetActiveScene().name;

        //Check where the player is to instanciate the correct object to play
        if (MatchSettings._instance != null && MatchSettings._instance.MapID == currentSceneName)
        {
            player.GameSceneLoaded();
        }
        else if (MainMenuUIHandler._instance != null)
        {
            player.LobbyLoaded();
        }

        //Fire event
        if (NetworkPlayerAdded != null)
        {
            NetworkPlayerAdded.Invoke(player);
        }
    }
Пример #2
0
 public void UpdatePlayer(PlayerInfo infos)
 {
     if (PlayersConnected.ContainsKey(infos.UserId))
     {
         PlayersConnected[infos.UserId] = infos;
     }
     else
     {
         PlayersConnected.Add(infos.UserId, infos);
     }
 }