Exemple #1
0
        private void FindPlayerSpawnPositionsInScene()
        {
            PlayersSpawnPositions.Clear();

            // Try to find already placed player spawn positions in the scene
            AbstractPlayerSpawnPosition[] spawnPositions = FindObjectsOfType <AbstractPlayerSpawnPosition>();
            foreach (AbstractPlayerSpawnPosition spawnPosition in spawnPositions)
            {
                PlayersSpawnPositions.Add(spawnPosition.PayerID, spawnPosition);
            }

            // Determine spawn positions relative to this transform if no PlayerSpawnPosition found in scene
            if (MotherOfManagers.Instance.IsSpawnGhostPlayerPositionsIfNotFound == true)
            {
                int angle;
                for (int i = 1; i < 5; i++)
                {
                    angle = 90 * i;
                    EPlayerID playerID = BUtils.GetPlayerIDFrom(i);
                    if (PlayersSpawnPositions.ContainsKey(playerID) == false)
                    {
                        AbstractPlayerSpawnPosition spawnGhost = Instantiate(playerSpawnPositionPrefab);
                        spawnGhost.PayerID  = playerID;
                        spawnGhost.Position = transform.position + Vector3.forward * 3.0f + Vector3.left * 3.0f;
                        spawnGhost.transform.RotateAround(transform.position, Vector3.up, angle);
                        spawnGhost.Rotation = transform.rotation;
                        PlayersSpawnPositions.Add(playerID, spawnGhost);
                    }
                }
            }
        }
Exemple #2
0
        /* Player Management */
        public AbstractPlayer SpawnPlayer(EPlayerID playerID)
        {
            AbstractPlayer spawnedPlayer = null;

            if (IS_TRUE(HasPlayerJoined(playerID)) &&
                IS_KEY_NOT_CONTAINED(ActivePlayers, playerID) &&
                IS_KEY_CONTAINED(playersPrefabsMap, playerID))
            {
                AbstractPlayer playerPrefab = playersPrefabsMap[playerID];

                Vector3    playerPosition = Vector3.zero;
                Quaternion playerRotation = Quaternion.identity;
                AbstractPlayerSpawnPosition playerSpawnPosition = null;
                if (PlayersSpawnPositions.ContainsKey(playerID))
                {
                    playerSpawnPosition = PlayersSpawnPositions[playerID];
                    playerPosition      = playerSpawnPosition.Position;
                    playerRotation      = playerSpawnPosition.Rotation;
                }
                else
                {
                    LogConsoleWarning("No spawn position defined for : " + playerID + ". Spawning at root");
                }

                spawnedPlayer          = Instantiate(playerPrefab, playerPosition, playerRotation);
                spawnedPlayer.PlayerID = playerID;
                spawnedPlayer.TeamID   = PlayersTeam[playerID];

                ActivePlayers.Add(playerID, spawnedPlayer);

                // Place player under parent of SpawnPosition
                if (playerSpawnPosition &&
                    MotherOfManagers.Instance.SpawnPlayersUnderSameTransformAsSpawnPositions == true &&
                    playerSpawnPosition.transform.parent != null)
                {
                    spawnedPlayer.transform.parent = playerSpawnPosition.transform.parent;
                }

                BEventsCollection.PLAYERS_PlayerSpawned.Invoke(new BEHandle <EPlayerID, IPlayer>(playerID, spawnedPlayer));
            }
            return(spawnedPlayer);
        }