/// <summary> /// Sets the root of a multiplayer event system to a submenu that can only be controlled by that player /// </summary> /// <param name="eventSystem">A multiplayer event system that corresponds to `playerNumber`</param> /// <param name="playerNumber">Number of the player (0-3)</param> protected void SetPlayerRoot(MultiplayerEventSystem eventSystem, int playerNumber) { GameObject playerRoot = null; RectTransform[] rectTransforms = activeMenu.GetComponentsInChildren <RectTransform>(true); foreach (RectTransform rectTransform in rectTransforms) { // Tags are used to distinguish which submenus can be controlled by which player if (rectTransform.gameObject.CompareTag("Player" + (playerNumber + 1) + "Choice")) { playerRoot = rectTransform.gameObject; break; } } if (playerRoot == null) { //playerRoot = activeMenu; return; } eventSystem.playerRoot = playerRoot; GameObject defaultButton = GetDefaultButton(playerRoot); eventSystem.firstSelectedGameObject = defaultButton; eventSystem.SetSelectedGameObject(defaultButton); }
/// <summary> /// Pause the game /// </summary> /// <param name="playerObject">Game object of the player that paused the game</param> public void PauseGame(GameObject playerObject) { if (IsPaused) { Debug.LogWarning("Game is already paused"); return; } Time.timeScale = 0; // Set pause menu active IsPaused = true; playerEventSystem = playerObject.GetComponent <MultiplayerEventSystem>(); if (playerEventSystem == null) { Debug.LogError("Player object does not have an Multiplayer Event System component attached to it."); return; } playerInput = playerObject.GetComponent <PlayerInput>(); if (playerInput == null) { Debug.LogError("Player object does not have an Player Input component attached to it."); return; } uIInputModule = playerObject.GetComponent <InputSystemUIInputModule>(); if (uIInputModule == null) { Debug.LogError("Player object does not have an Input System UI Input Module component attached to it."); return; } PushMenu(activeMenu); SwitchCurrentActionMap("UI"); }
/// <summary> /// Assign a Player UI Control game object to a default button /// </summary> /// <param name="playerNumber">Number of the player</param> /// <param name="uiControl">UI Control prefab</param> public void AssignMultiplayerUIControl(GameObject uiControl, int playerNumber) { MultiplayerEventSystem eventSystem = uiControl.GetComponentInChildren <MultiplayerEventSystem>(); SetPlayerRoot(eventSystem, playerNumber); multiplayerEventSystems.Add(eventSystem); }
/// <summary> /// Sets the root of a multiplayer event system to a submenu that can only be controlled by that player /// </summary> /// <param name="eventSystem">A multiplayer event system that corresponds to `playerNumber`</param> protected virtual void SetPlayerRoot(MultiplayerEventSystem eventSystem) { eventSystem.playerRoot = activeMenu; GameObject defaultButton = GetDefaultButton(activeMenu); eventSystem.firstSelectedGameObject = defaultButton; eventSystem.SetSelectedGameObject(defaultButton); }
public void ShowGameOverMenu() { GameObject playerObject = PlayerManager.Instance.Players[0]; Time.timeScale = 0; playerEventSystem = playerObject.GetComponent <MultiplayerEventSystem>(); playerInput = playerObject.GetComponent <PlayerInput>(); uIInputModule = playerObject.GetComponent <InputSystemUIInputModule>(); PushMenu(gameOverMenu); SwitchCurrentActionMap("UI"); GameManager.Instance.SetPausedState(); }
private void Start() { mpEventSystem = GameManager.Instance.playerConfigs[playerIndex].mpEventSystem; //uiInputModule.cancel.action.actionMap.AddAction(() => PastMenu()) GenerateColorSelectField(); GenerateMercSelectField(); playerSetupMenus[0].SetActive(true); //generate a list of buttons in the first menu, then select the first one; Button[] buttonsInNextMenu = playerSetupMenus[currentMenu].GetComponentsInChildren <Button>(); mpEventSystem.SetSelectedGameObject(null); mpEventSystem.SetSelectedGameObject(buttonsInNextMenu[0].gameObject); }
/// <summary> /// Description: Pause the game /// Rationale: Players should be able to pause the game and navigate menu options /// </summary> /// <param name="playerObject">Game object of the player that paused the game</param> public void PauseGame(GameObject playerObject) { if (IsPaused) { return; } Time.timeScale = 0; IsPaused = true; playerEventSystem = playerObject.GetComponent <MultiplayerEventSystem>(); playerInput = playerObject.GetComponent <PlayerInput>(); uIInputModule = playerObject.GetComponent <InputSystemUIInputModule>(); PushMenu(activeMenu); SwitchCurrentActionMap("UI"); GameManager.Instance.SetPausedState(); }
/// <summary> /// sets up /// </summary> /// <param name="index">Player's list index</param> public void ReadyPlayer(int index) { playerConfigs[index].isReady = true; if (playerConfigs.All(p => p.isReady == true)) { LevelMenu.SetActive(true); //assigns Player 1 to the level select menu MultiplayerEventSystem P1Event = GameObject.Find("SetupPanel").GetComponent <MultiplayerEventSystem>(); P1Event.playerRoot = LevelMenu; P1Event.SetSelectedGameObject(LevelMenu.GetComponentInChildren <Button>().gameObject); foreach (MultiplayerEventSystem player in GameObject.FindObjectsOfType <MultiplayerEventSystem>()) { if (player.playerRoot == LevelMenu) { continue; //skips Player 1 } player.SetSelectedGameObject(null); //makes it so that other players can't disconnect during Level Selection } } }
/// <summary> /// Get the button that a player's event system has selected /// </summary> /// <param name="eventSystem">Event system of the player</param> /// <returns>The button that the player selected</returns> protected virtual GameObject GetSelectedButton(MultiplayerEventSystem eventSystem) { return(eventSystem.currentSelectedGameObject); }
public void SetUp(PlayerController player, MultiplayerEventSystem eventSystem) { this.player = player; this.eventSystem = eventSystem; eventSystem.playerRoot = gameObject; }
/// <summary> /// Assign a Player UI Control game object to a default button /// </summary> /// <param name="uiControl">UI Control prefab</param> public void AssignMultiplayerUIControl(GameObject uiControl) { playerEventSystem = uiControl.GetComponent <MultiplayerEventSystem>(); }