public void TryRegisterDevice(InputDevice device) { if (IsDeviceAdded(device)) { return; } int playerId = -1; if (isXInputDevice(device)) { XInputDevice xInputDevice = device as XInputDevice; playerId = xInputDevice.DeviceIndex; } else { playerId = NextId; } if (playerId >= 0) { PlayerDevice newPlayer = new PlayerDevice() { id = playerId, InControlDevice = device }; AddPlayer(newPlayer); } }
public void OnPlayerLeft(PlayerDevice playerDevice) { if (playerDevice.id == SlotNumber) { _playerDevice = null; Status = PlayerStatus.Disconnected; } }
public void OnPlayerJoined(PlayerDevice playerDevice) { if (playerDevice.id == SlotNumber) { _playerDevice = playerDevice; Status = PlayerStatus.Connected; } }
public void OnPlayerLeft(PlayerDevice playerData) { if (playerData.id == SlotNumber) { _playerData = null; gameObject.SetActive(false); } }
public void OnPlayerJoined(PlayerDevice playerData) { if (playerData.id == SlotNumber) { _playerData = playerData; gameObject.SetActive(true); } }
private void Spawn(PlayerDevice player) { int spawnPoint = Random.Range(0, SpawnPoints.Count); GameObject newPigeon = (GameObject) Instantiate(PigeonPrefab, SpawnPoints[spawnPoint].position, Quaternion.identity); SpawnPoints.RemoveAt(spawnPoint); newPigeon.transform.parent = transform; PigeonController controller = newPigeon.GetComponent<PigeonController>(); if(controller != null) { newPigeon.name = "Pigeon " + player.id; controller.Player = player; } else { Debug.LogError("Prefab does not have a pigeon controller"); } }
private void Spawn(PlayerDevice player) { int spawnPoint = Random.Range(0, SpawnPoints.Count); GameObject newPlayer = (GameObject)Instantiate(CharacterPrefab, SpawnPoints[spawnPoint].position, Quaternion.identity); if (!AllowDebugSpawning) { SpawnPoints.RemoveAt(spawnPoint); } newPlayer.transform.parent = transform; CharacterController controller = newPlayer.GetComponent<CharacterController>(); if (controller != null) { newPlayer.name = "Player " + player.id; controller.Player = player; } else { Debug.LogError("Prefab does not have a character controller"); } }
private void EndGame(PlayerDevice player) { _image.color = Colors[player.id]; StartCoroutine(PlayAnim()); }
public void TryRemovePlayer(PlayerDevice player) { if (Players.Contains(player)) { Players.Remove(player); InputSignals.PlayerRemoved.Dispatch(player); } }
private void AddPlayer(PlayerDevice newPlayer) { Players.Add(newPlayer); InputSignals.PlayerJoined.Dispatch(newPlayer); }
private void TryConnectXInputPlayer(PlayerDevice device) { foreach (var xinput in XInputDevices) { if (xinput.id == device.id) { if (!xinput.InControlDevice.Equals(device.InControlDevice)) { xinput.InControlDevice = device.InControlDevice; InputSignals.PlayerDeviceChanged.Dispatch(xinput); } else { return; } } } //Remove player if not found in XInputDevices as that player has lost connection to its device TryRemovePlayer(device); }
void RefreshXinputDevices() { XInputDevices.Clear(); foreach (var xInputDevice in GetXInputDevices()) { PlayerDevice newPlayer = new PlayerDevice() { id = xInputDevice.DeviceIndex, InControlDevice = xInputDevice }; XInputDevices.Add(newPlayer); } }