Ejemplo n.º 1
0
        /// <summary>
        /// We use this callback to instantiate player vehicle for the game scene.
        /// This instantiated object is then positionned on the track scene
        /// </summary>
        /// <param name="conn">Conn.</param>
        /// <param name="playerControllerId">Player controller identifier.</param>
        public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
        {
            GameObject vehicle = null;

            // we look for a reference to generic interface of the racing manager class
            RaceManager manager = FindObjectOfType <RaceManager>();

            // we get the associated lobby player object
            GameObject        newPlayer   = conn.playerControllers[playerControllerId].gameObject;
            OnlineLobbyPlayer lobbyplayer = newPlayer.GetComponent <OnlineLobbyPlayer>();

            // we determine the start position
            Vector3    startPosition = manager.StartPositions[_currentStartPosition];
            Quaternion startRotation = Quaternion.Euler(new Vector3(0, manager.StartAngleDegree, 0));

            // we increment start position for next player
            _currentStartPosition++;

            // we instantiate the player vehicle
            vehicle = (GameObject)Object.Instantiate(
                AvailableVehiclesPrefab[lobbyplayer.VehicleSelectedIndex],
                startPosition,
                startRotation
                );

            return(vehicle);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the player.
 /// </summary>
 /// <returns>The player.</returns>
 /// <param name="position">Position.</param>
 public virtual ILobbyPlayerInfo GetPlayer(int position)
 {
     foreach (var lobbySlot in lobbySlots)
     {
         OnlineLobbyPlayer lobbyPlayer = (OnlineLobbyPlayer)lobbySlot;
         if (lobbyPlayer.Position == position)
         {
             return(lobbyPlayer);
         }
     }
     return(null);
 }
        /// <summary>
        /// Shows the track selection canvas
        /// </summary>
        /// <param name="player">Reference to the Player 1 (owner of track selection)</param>
        public virtual void ShowTrackSelection(OnlineLobbyPlayer player)
        {
            LeftTrackButton.gameObject.SetActive(true);
            RightTrackButton.gameObject.SetActive(true);

            LeftTrackButton.onClick.RemoveAllListeners();
            LeftTrackButton.onClick.AddListener(
                delegate { player.OnTrackChange(-1); });

            RightTrackButton.onClick.RemoveAllListeners();
            RightTrackButton.onClick.AddListener(
                delegate { player.OnTrackChange(1); });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns Players
        /// </summary>
        public virtual Dictionary <int, ILobbyPlayerInfo> Players()
        {
            Dictionary <int, ILobbyPlayerInfo> players = new Dictionary <int, ILobbyPlayerInfo>();

            foreach (var lobbySlot in lobbySlots)
            {
                if (lobbySlot != null)
                {
                    OnlineLobbyPlayer lobbyPlayer = (OnlineLobbyPlayer)lobbySlot;
                    players.Add(lobbyPlayer.Position, lobbyPlayer);
                }
            }

            return(players);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This event allow us to attribute lobby player values to the game player object.
        /// We also count the number of players ready at this stage.
        /// </summary>
        /// <param name="lobbyPlayer">Lobby player.</param>
        /// <param name="gamePlayer">Game player.</param>
        public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
        {
            OnlineLobbyPlayer onlinelobbyplayer = lobbyPlayer.GetComponent <OnlineLobbyPlayer>();
            INetworkVehicle   vehicleController = gamePlayer.GetComponent <INetworkVehicle>();

            vehicleController.SetPlayerName(onlinelobbyplayer.PlayerName.text);
            gamePlayer.name = onlinelobbyplayer.PlayerName.text;

            _playersReadyToPlayCount++;

            // When all players are at this stage, game can start
            if (_playersReadyToPlayCount == numPlayers)
            {
                PlayersReadyToPlay = true;
            }

            return(true);
        }