Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent width / height in FScreen when resizing window in Unity Editor #205

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions FutileProject/Assets/Futile/Core/FScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class FScreen

private float _screenLongLength;
private float _screenShortLength;

//if true, the fscreen (pixel) width is unity Screen width, if false fscreen width is Screen height
private bool _fscreenWidthIsScreenWidth;

private bool _didJustResize;
private float _oldWidth;
Expand Down Expand Up @@ -127,6 +130,7 @@ public FScreen (FutileParams futileParams)
pixelHeight = _screenShortLength;
}

_fscreenWidthIsScreenWidth=(pixelWidth==Screen.width);

//get the resolution level - the one we're closest to WITHOUT going over, price is right rules :)
_resLevel = null;
Expand Down Expand Up @@ -252,7 +256,7 @@ public void SwitchOrientation (ScreenOrientation newOrientation)
Screen.orientation = newOrientation;
_currentOrientation = newOrientation;

UpdateScreenDimensions();
UpdateScreenDimensions(true);

Debug.Log ("Orientation switched to " + _currentOrientation + " screen is now: " + pixelWidth+"x"+pixelHeight+"px");

Expand All @@ -263,20 +267,34 @@ public void SwitchOrientation (ScreenOrientation newOrientation)
}
}

private void UpdateScreenDimensions()
private void UpdateScreenDimensions(bool orientationChange=false)
{
_screenLongLength = Math.Max (Screen.width, Screen.height);
_screenShortLength = Math.Min (Screen.width, Screen.height);

if(_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown)
{
pixelWidth = _screenShortLength;
pixelHeight = _screenLongLength;
}
else //landscape
{
pixelWidth = _screenLongLength;
pixelHeight = _screenShortLength;
if (orientationChange) {
_screenLongLength = Math.Max (Screen.width, Screen.height);
_screenShortLength = Math.Min (Screen.width, Screen.height);

if(_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown)
{
pixelWidth = _screenShortLength;
pixelHeight = _screenLongLength;
}
else //landscape
{
pixelWidth = _screenLongLength;
pixelHeight = _screenShortLength;
}
_fscreenWidthIsScreenWidth=(pixelWidth==Screen.width);
} else {
if (_fscreenWidthIsScreenWidth) {
pixelWidth=Screen.width;
pixelHeight=Screen.height;
} else {
pixelWidth=Screen.height;
pixelHeight=Screen.width;
}

//Check for an orientation change? Not sure it's appropriate to do so
//...
}

width = pixelWidth*Futile.displayScaleInverse;
Expand Down