private void InternalUpdate() { foreach (PlayerInput pI in _playersByPadIndex.Values) { pI.CustomPreUpdate(); } var validInputIndexes = PlayerInputUtils.GetValidInputIndexes(); if (EnableCheckPlayersActions) { foreach (int i in validInputIndexes) { HandleStart(i); CheckPlayerActions(i); } } var indexLeft = _activeIndex.Where(ai => !validInputIndexes.Contains(ai)).ToArray(); foreach (var i in indexLeft) { LeaveAllForIndex(i); } }
public void ForceCreateMainPlayer() { var indexes = PlayerInputUtils.GetValidInputIndexes(); if (_mainPlayerInput == null && indexes.Count > 0) { CreatePlayer(indexes.First(), PadUsedType.SINGLE); } }
private void LeaveAllForIndex(int index) { foreach (PadUsedType type in Enum.GetValues(typeof(PadUsedType))) { var name = PlayerInputUtils.NameByIndexAndPadUsedType(index, type); if (_playersByPadIndex.ContainsKey(name)) { Leave(_playersByPadIndex[name], index); } } }
private void CreatePlayer(int padIndex, PadUsedType type) { _activeIndex.Add(padIndex); var playerInput = new PlayerInput(padIndex, type); _playersByPadIndex.Add(PlayerInputUtils.NameByIndexAndPadUsedType(padIndex, type), playerInput); OnNewPlayer.SafeInvoke(playerInput); if (_mainPlayerInput == null) { _mainPlayerInput = playerInput; } }
private void HandleStart(int index) { if (PlayerInputUtils.GetButtonDown(PlayerInput._START, index)) { if (!_activeIndex.Contains(index)) { CreatePlayer(index, PadUsedType.SINGLE); } else { if (!_padIndexInProcedure.ContainsKey(index)) { _padIndexInProcedure.Add(index, Time.time); _notification.Add(index, (GameObject)Instantiate(LeaveNotificationPrefab, NotificationContainer)); } } } }
private void Leave(PlayerInput playerInput, int index) { _playersByPadIndex.Remove(playerInput.Name); if (playerInput.PadUsedType != PadUsedType.SINGLE) { var otherName = PlayerInputUtils.NameByIndexAndPadUsedType(index, PadUsedTypeUtils.GetOtherSide(playerInput.PadUsedType)); var other = _playersByPadIndex[otherName]; ChangePadUsedTypeForPlayerInput(other, PadUsedType.SINGLE); } else { _activeIndex.Remove(index); } _padIndexInProcedure.Remove(index); if (_notification.ContainsKey(index)) { Destroy(_notification[index]); _notification.Remove(index); } if (_mainPlayerInput == playerInput) { if (_activeIndex.Count > 0) { _mainPlayerInput = _playersByPadIndex.Values.First(); } else { _mainPlayerInput = null; } } OnPlayerLeave.SafeInvoke(playerInput); }