/// <summary> /// Outs a player controller, given an identifier. Returns true if one was found. /// </summary> /// <param name="playerControllerId">The player controller identifier.</param> /// <param name="playerController">The player controller found.</param> /// <returns> /// <c>true</c> if a player controller was found; otherwise, <c>false</c>. /// </returns> public bool GetPlayerController(short playerControllerId, out TinyNetPlayerController playerController) { playerController = null; /*if (_playerControllers.Count > playerControllerId) { * for (int i = 0; i < playerControllers.Count; i++) { * if (playerControllers[i].IsValid && playerControllers[i].playerControllerId == playerControllerId) { * playerController = playerControllers[i]; * * return true; * } * } * * return false; * }*/ for (int i = 0; i < _playerControllers.Count; i++) { if (_playerControllers[i].IsValid && _playerControllers[i].playerControllerId == playerControllerId) { playerController = _playerControllers[i]; return(true); } } return(false); }
//============ Player Controllers ===================// /// <summary> /// Adds a <see cref="TinyNetPlayerController"/> to the list of player controllers of this connection. /// </summary> /// <typeparam name="T">A type derived from <see cref="TinyNetPlayerController"/>.</typeparam> /// <param name="player">The player controller to add.</param> public void SetPlayerController <T>(TinyNetPlayerController player) where T : TinyNetPlayerController, new() { /*while (player.playerControllerId >= _playerControllers.Count) { * _playerControllers.Add(new T()); * } * * _playerControllers[player.playerControllerId] = player;*/ _playerControllers.Add(player); }
/// <summary> /// Redirects an <see cref="TinyNetInputMessage"/> to the correct player controller. /// </summary> /// <param name="netMsg">The <see cref="TinyNetInputMessage"/>.</param> public void GetPlayerInputMessage(TinyNetMessageReader netMsg) { TinyNetPlayerController netPlayerController = GetPlayerController(TinyNetInputMessage.PeekAtPlayerControllerId(netMsg)); if (netPlayerController != null) { netPlayerController.GetInputMessage(netMsg); } }
/// <summary> /// Gets the player controller that have the given identifier. /// </summary> /// <param name="playerControllerId">The player controller identifier.</param> /// <returns></returns> public TinyNetPlayerController GetPlayerController(int playerControllerId) { TinyNetPlayerController tPC = null; for (int i = 0; i < tinyNetConns.Count; i++) { if (tinyNetConns[i].GetPlayerController((short)playerControllerId, out tPC)) { break; } } return(tPC); }