What is my problem?
I have started a new 2d game project in Unity and would like to allow for resizing of the window by the player. When resizing, I don't want black bars at any of the 4 sides (I think that's called letterboxing?) in windowed mode. Instead I would like that height or width of the window (it depends what the user input is) is adjusted to the other metric, so that one aspect ratio is always kept when resizing. If possible I'd like to use built-in functionality of Unity and not external code packages.
What solutions have I considered so far and why they don't work (for me):
The first animated image of the readme of this github project explains what I would like to accomplish:
As stated in the readme however, this code only works for windows.
In this stackoverflow post and this gamedev stackexchange post the advised solution is to constantly use Screen.SetResolution() in the Update() method. This solution however seems very resource intensive, so if there's a way to only update this when the screen is actually resized, please tell me.
In a lot of gamedev stackexchange and stackoverflow posts the recommended solution is often to use a canvas or something like that. As my problem is not the UI itself but the whole game, I think this solution wouldn't suit my needs.