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); }