public void OnPlayerJoined(PlayerInput playerInput) { Debug.Log("Player " + playerInput.user.id + " Joined"); // If not existing player, add new bool isNewPlayer = true; InputDevice inputDevice = playerInput.user.pairedDevices.First(); if (inputDevice == null) { Debug.LogError("No input device detected for Player " + playerInput.user.id); return; } foreach (Player p in _playerSlots) { if (p != null) { if (p.deviceId == inputDevice.deviceId) { isNewPlayer = false; break; } } } if (isNewPlayer) { Player newPlayer = new Player(playerInput, CharacterColour.None, characterOptions[0], inputDevice.deviceId); // Assign the new player a colour int playerNumber = 0; for (int i = 0; i < _playerSlots.Length; i++) { if (_playerSlots[i] == null) { playerNumber = i; break; } } newPlayer.characterColour = PlayerColours[playerNumber]; _playerSlots[playerNumber] = newPlayer; if (inputDevice is Gamepad) { Gamepad gamepad = inputDevice as Gamepad; // If the device is a DualShock4, color the light bar as the player colour :) if (gamepad is DualShockGamepad) { DualShockGamepad ds = gamepad as DualShockGamepad; ds.SetLightBarColor(colours.GetColour(newPlayer.characterColour)); } } if (MenuCanvas == null) { MainMenuController mainMenu = FindObjectOfType <MainMenuController>(); if (mainMenu != null) { MenuCanvas = mainMenu.gameObject; } } // i.e. If we're on the menu if (MenuCanvas != null) { // MenuCanvas.BroadcastMessage("PlayerJoined", playerNumber); } // If not in menu we must be in a level (right???) else { SwitchActionMap(playerNumber, "Player"); } } }
static public void SetDS4LightColor(Color color) { DualShockGamepad ds4 = Gamepad.current as DualShockGamepad; ds4.SetLightBarColor(color); }