예제 #1
0
        /// <summary>
        /// Adding player for the first time
        /// </summary>
        /// <param name="playerPrefab">Reference to player's prefab</param>
        /// <returns>button events reference</returns>
        private ButtonEvents addFirstTimePlayer(GameObject playerPrefab)
        {
            // adding reference to playersPrefab to game manager's data
            playersData[currentPlayerCount].PlayersPrefabReference = playerPrefab;

            // Creating a mini game
            var randomGame = createNewMinigame(true);

            // set new game as player instance's child
            randomGame.transform.SetParent(playerPrefab.transform);

            // adding button events to player's prefab
            var buttonEventsReference = playerPrefab.AddComponent <ButtonEvents>();

            // adding interface for communication between mini game and singleton game manager
            var communicationBusReference = playerPrefab.AddComponent <PlayerToManagerCommunicationBus>();

            playersData[currentPlayerCount].PlayerToManagerCommunicationBusReference = communicationBusReference;

            communicationBusReference.PlayerId = currentPlayerCount;
            var color = colors.Dequeue();

            communicationBusReference.PlayerColor       = color;
            playersData[currentPlayerCount].PlayerColor = color;

            // sub to events
            communicationBusReference.OnPlayerScored += OnPlayerScored;
            communicationBusReference.OnPlayerDeath  += OnPlayerDeath;
            communicationBusReference.OnPlayerVoted  += OnPlayerVoted;

            // offsetting scene for player
            playerPrefab.transform.position = new Vector3(0, -300 * currentPlayerCount, 0);
            randomGame.transform.position   = playerPrefab.transform.position;

            // adding reference to mini game manager
            var comp = randomGame.GetComponentInChildren(gameList[CurrentRandomGame].MinigameManagerType);

            playersData[currentPlayerCount].InjectionInstance
            .Add(gameList[CurrentRandomGame].MinigameManagerType, comp);

            playersData[currentPlayerCount].CurrentGamePrefab = randomGame;

            // setting game state
            resetGameState(currentPlayerCount);

            // getting static viewports
            var viewPorts = Viewports.GetViewports(currentPlayerCount + 1);

            // setting cameras for each player
            for (var i = 0; i < currentPlayerCount + 1; i++)
            {
                playersData[i].CurrentGamePrefab.GetComponentInChildren <Camera>().rect = viewPorts[i];
            }

            currentPlayerCount++;

            // returning button events reference for each player
            return(buttonEventsReference);
        }
예제 #2
0
        private void setNewGameForEveryPlayer()
        {
            // create new game for each player
            for (var i = 0; i < currentPlayerCount; i++)
            {
                var randomGame = createNewMinigame();
                randomGame.transform.SetParent(playersData[i].PlayersPrefabReference.transform);
                randomGame.transform.position = playersData[i].PlayersPrefabReference.transform.position;

                var comp = randomGame
                           .GetComponentInChildren(gameList[CurrentRandomGame].MinigameManagerType);

                // check if type already exists
                if (!playersData[i].InjectionInstance
                    .ContainsKey(gameList[CurrentRandomGame].MinigameManagerType))
                {
                    playersData[i].InjectionInstance
                    .Add(gameList[CurrentRandomGame].MinigameManagerType, comp);
                }

                // reset game state for each player

                playersData[i].GameStateData.Alive = true;

                playersData[i].CurrentGamePrefab = randomGame;
            }

            // getting static viewports
            var viewPorts = Viewports.GetViewports(currentPlayerCount);

            // set active new game for each player
            for (var i = 0; i < currentPlayerCount; i++)
            {
                playersData[i].CurrentGamePrefab.SetActive(true);

                // setting cameras for each player
                playersData[i].CurrentGamePrefab.GetComponentInChildren <Camera>().rect = viewPorts[i];
            }

            Intermission = false;
        }