public FResolutionLevel AddResolutionLevel(float maxLength, float displayScale, float resourceScale, string resourceSuffix) { FResolutionLevel resLevel = new FResolutionLevel(); resLevel.maxLength = maxLength; resLevel.displayScale = displayScale; resLevel.resourceScale = resourceScale; resLevel.resourceSuffix = resourceSuffix; bool wasAdded = false; //we've gotta have the resLevels sorted low to high by maxLength for (int r = 0; r < resLevels.Count; ++r) { if (resLevel.maxLength < resLevels[r].maxLength) { resLevels.Insert(r, resLevel); wasAdded = true; break; } } if (!wasAdded) { resLevels.Add(resLevel); } return(resLevel); }
public FResolutionLevel AddResolutionLevel(float maxLength, float displayScale, float resourceScale, string resourceSuffix) { FResolutionLevel resLevel = new FResolutionLevel(); resLevel.maxLength = maxLength; resLevel.displayScale = displayScale; resLevel.resourceScale = resourceScale; resLevel.resourceSuffix = resourceSuffix; bool wasAdded = false; //we've gotta have the resLevels sorted low to high by maxLength for(int r = 0; r<resLevels.Count; ++r) { if(resLevel.maxLength < resLevels[r].maxLength) { resLevels.Insert(r,resLevel); wasAdded = true; break; } } if(!wasAdded) { resLevels.Add(resLevel); } return resLevel; }
public FScreen(FutileParams futileParams) { _futileParams = futileParams; #if UNITY_IPHONE || UNITY_ANDROID TouchScreenKeyboard.autorotateToLandscapeLeft = false; TouchScreenKeyboard.autorotateToLandscapeRight = false; TouchScreenKeyboard.autorotateToPortrait = false; TouchScreenKeyboard.autorotateToPortraitUpsideDown = false; #endif //Non-mobile unity always defaults to portrait for some reason, so fix this manually if (Screen.height > Screen.width) { _currentOrientation = ScreenOrientation.Portrait; } else { _currentOrientation = ScreenOrientation.LandscapeLeft; } //get the correct orientation if we're on a mobile platform #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID) _currentOrientation = Screen.orientation; #endif //special "single orientation" mode if (_futileParams.singleOrientation != ScreenOrientation.Unknown) { _currentOrientation = _futileParams.singleOrientation; } else //if we're not in a supported orientation, put us in one! { if (_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft) { if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } else if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } } else if (_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight) { if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } } else if (_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait) { if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } } else if (_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown) { if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } } } Screen.orientation = _currentOrientation; _screenLongLength = Math.Max(Screen.height, Screen.width); _screenShortLength = Math.Min(Screen.height, Screen.width); if (_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown) { pixelWidth = _screenShortLength; pixelHeight = _screenLongLength; } else //landscape { pixelWidth = _screenLongLength; pixelHeight = _screenShortLength; } //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :) _resLevel = null; foreach (FResolutionLevel resLevel in _futileParams.resLevels) { if (_screenLongLength <= resLevel.maxLength) //we've found our resLevel { _resLevel = resLevel; break; } } //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose the biggest if (_resLevel == null) { _resLevel = _futileParams.resLevels.GetLastObject(); if (_resLevel == null) { throw new FutileException("You must add at least one FResolutionLevel!"); } } Futile.resourceSuffix = _resLevel.resourceSuffix; //this is what helps us figure out the display scale if we're not at a specific resolution level //it's relative to the next highest resolution level float displayScaleModifier = 1.0f; if (_futileParams.shouldLerpToNearestResolutionLevel) { displayScaleModifier = _screenLongLength / _resLevel.maxLength; } Futile.displayScale = _resLevel.displayScale * displayScaleModifier; Futile.displayScaleInverse = 1.0f / Futile.displayScale; Futile.resourceScale = _resLevel.resourceScale; Futile.resourceScaleInverse = 1.0f / Futile.resourceScale; width = pixelWidth * Futile.displayScaleInverse; height = pixelHeight * Futile.displayScaleInverse; halfWidth = width / 2.0f; halfHeight = height / 2.0f; _originX = _futileParams.origin.x; _originY = _futileParams.origin.y; Debug.Log("Futile: Display scale is " + Futile.displayScale); Debug.Log("Futile: Resource scale is " + Futile.resourceScale); Debug.Log("Futile: Resource suffix is " + _resLevel.resourceSuffix); Debug.Log("FScreen: Screen size in pixels is (" + pixelWidth + "px," + pixelHeight + "px)"); Debug.Log("FScreen: Screen size in points is (" + width + "," + height + ")"); Debug.Log("FScreen: Origin is at (" + _originX * width + "," + _originY * height + ")"); Debug.Log("FScreen: Initial orientation is " + _currentOrientation); _didJustResize = true; }
public FScreen(FutileParams futileParams) { _futileParams = futileParams; #if UNITY_IPHONE || UNITY_ANDROID TouchScreenKeyboard.autorotateToLandscapeLeft = false; TouchScreenKeyboard.autorotateToLandscapeRight = false; TouchScreenKeyboard.autorotateToPortrait = false; TouchScreenKeyboard.autorotateToPortraitUpsideDown = false; #endif //Non-mobile unity always defaults to portrait for some reason, so fix this manually if(Screen.height > Screen.width) { _currentOrientation = ScreenOrientation.Portrait; } else { _currentOrientation = ScreenOrientation.LandscapeLeft; } //get the correct orientation if we're on a mobile platform #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID) _currentOrientation = Screen.orientation; #endif //special "single orientation" mode if(_futileParams.singleOrientation != ScreenOrientation.Unknown) { _currentOrientation = _futileParams.singleOrientation; } else //if we're not in a supported orientation, put us in one! { if(_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft) { if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if(_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight) { if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if(_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait) { if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; } else if(_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown) { if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; } } Screen.orientation = _currentOrientation; _screenLongLength = Math.Max(Screen.height, Screen.width); _screenShortLength = Math.Min(Screen.height, Screen.width); if(_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown) { pixelWidth = _screenShortLength; pixelHeight = _screenLongLength; } else //landscape { pixelWidth = _screenLongLength; pixelHeight = _screenShortLength; } //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :) _resLevel = null; foreach(FResolutionLevel resLevel in _futileParams.resLevels) { if(_screenLongLength <= resLevel.maxLength) //we've found our resLevel { _resLevel = resLevel; break; } } //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose the biggest if(_resLevel == null) { _resLevel = _futileParams.resLevels.GetLastObject(); if(_resLevel == null) { throw new Exception("You must add at least one FResolutionLevel!"); } } Futile.resourceSuffix = _resLevel.resourceSuffix; //this is what helps us figure out the display scale if we're not at a specific resolution level //it's relative to the next highest resolution level float displayScaleModifier = 1.0f; if(_futileParams.shouldLerpToNearestResolutionLevel) { displayScaleModifier = _screenLongLength/_resLevel.maxLength; } Futile.displayScale = _resLevel.displayScale * displayScaleModifier; Futile.displayScaleInverse = 1.0f/Futile.displayScale; Futile.resourceScale = _resLevel.resourceScale; Futile.resourceScaleInverse = 1.0f/Futile.resourceScale; width = pixelWidth*Futile.displayScaleInverse; height = pixelHeight*Futile.displayScaleInverse; halfWidth = width/2.0f; halfHeight = height/2.0f; _originX = _futileParams.origin.x; _originY = _futileParams.origin.y; Debug.Log ("Futile: Display scale is " + Futile.displayScale); Debug.Log ("Futile: Resource scale is " + Futile.resourceScale); Debug.Log ("Futile: Resource suffix is " + _resLevel.resourceSuffix); Debug.Log ("FScreen: Screen size in pixels is (" + pixelWidth +"px," + pixelHeight+"px)"); Debug.Log ("FScreen: Screen size in points is (" + width + "," + height+")"); Debug.Log ("FScreen: Origin is at (" + _originX*width + "," + _originY*height+")"); Debug.Log ("FScreen: Initial orientation is " + _currentOrientation); _didJustResize = true; }
public void Init(FutileParams futileParams) { enabled = true; _futileParams = futileParams; Application.targetFrameRate = _futileParams.targetFrameRate; #if UNITY_IPHONE || UNITY_ANDROID TouchScreenKeyboard.autorotateToLandscapeLeft = false; TouchScreenKeyboard.autorotateToLandscapeRight = false; TouchScreenKeyboard.autorotateToPortrait = false; TouchScreenKeyboard.autorotateToPortraitUpsideDown = false; #endif //Non-mobile unity always defaults to portrait for some reason, so fix this manually if (Screen.height > Screen.width) { _currentOrientation = ScreenOrientation.Portrait; } else { _currentOrientation = ScreenOrientation.LandscapeLeft; } //get the correct orientation if we're on a mobile platform #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID) _currentOrientation = Screen.orientation; #endif //special "single orientation" mode if (_futileParams.singleOrientation != ScreenOrientation.Unknown) { _currentOrientation = _futileParams.singleOrientation; } else //if we're not in a supported orientation, put us in one! { if (_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft) { if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } else if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } } else if (_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight) { if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } } else if (_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait) { if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } } else if (_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown) { if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } } } Screen.orientation = _currentOrientation; Futile.startingQuadsPerLayer = _futileParams.startingQuadsPerLayer; Futile.quadsPerLayerExpansion = _futileParams.quadsPerLayerExpansion; Futile.maxEmptyQuadsPerLayer = _futileParams.maxEmptyQuadsPerLayer; _screenLongLength = Math.Max(Screen.height, Screen.width); _screenShortLength = Math.Min(Screen.height, Screen.width); if (_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown) { pixelWidth = _screenShortLength; pixelHeight = _screenLongLength; } else //landscape { pixelWidth = _screenLongLength; pixelHeight = _screenShortLength; } //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :) _resLevel = null; foreach (FResolutionLevel resLevel in _futileParams.resLevels) { if (_screenLongLength <= resLevel.maxLength) //we've found our resLevel { _resLevel = resLevel; break; } } //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose that one if (_resLevel == null) { _resLevel = _futileParams.resLevels.GetLastObject(); if (_resLevel == null) { throw new Exception("You must add at least one FResolutionLevel!"); } } Futile.resourceSuffix = _resLevel.resourceSuffix; //this is what helps us figure out the display scale if we're not at a specific resolution level //it's relative to the next highest resolution level float displayScaleModifier = 1.0f; if (_futileParams.shouldLerpToNearestResolutionLevel) { displayScaleModifier = _screenLongLength / _resLevel.maxLength; } displayScale = _resLevel.displayScale * displayScaleModifier; displayScaleInverse = 1.0f / displayScale; resourceScale = _resLevel.resourceScale; resourceScaleInverse = 1.0f / resourceScale; width = pixelWidth * displayScaleInverse; height = pixelHeight * displayScaleInverse; halfWidth = width / 2.0f; halfHeight = height / 2.0f; _originX = _futileParams.origin.x; _originY = _futileParams.origin.y; Debug.Log("Futile: Display scale is " + displayScale); Debug.Log("Futile: Resource scale is " + resourceScale); Debug.Log("Futile: Resource suffix is " + _resLevel.resourceSuffix); Debug.Log("Futile: Screen size in pixels is (" + pixelWidth + "px," + pixelHeight + "px)"); Debug.Log("Futile: Screen size in points is (" + width + "," + height + ")"); Debug.Log("Futile: Origin is at (" + _originX * width + "," + _originY * height + ")"); Debug.Log("Futile: Initial orientation is " + _currentOrientation); // //Camera setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs // name = "Futile"; _cameraHolder = new GameObject(); _cameraHolder.transform.parent = gameObject.transform; _cameraHolder.AddComponent <Camera>(); _camera = _cameraHolder.camera; _camera.name = "FCamera"; //_camera.clearFlags = CameraClearFlags.Depth; //TODO: check if this is faster or not? _camera.clearFlags = CameraClearFlags.SolidColor; _camera.nearClipPlane = -50.3f; _camera.farClipPlane = 50.0f; _camera.depth = 100; _camera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f); _camera.backgroundColor = _futileParams.backgroundColor; //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels _camera.orthographic = true; _camera.orthographicSize = pixelHeight / 2 * displayScaleInverse; UpdateCameraPosition(); _didJustResize = true; touchManager = new FTouchManager(); atlasManager = new FAtlasManager(); stage = new FStage(); }
public void UpdateResolutionScale() { // DZDebug.Log("---------- _currentOrientation = " + _currentOrientation); Screen.orientation = _currentOrientation; _screenLongLength = Math.Max(Screen.height, Screen.width); _screenShortLength = Math.Min(Screen.height, Screen.width); // // OwenG: NOTE - game defaults to Portrait if Unity returns ScreenOrientation.Unknown in the first frame of execution // if(_currentOrientation == ScreenOrientation.LandscapeLeft || _currentOrientation == ScreenOrientation.LandscapeRight) // { //// DZDebug.Log("------------- LANDSCAPE ----------------"); // pixelWidth = _screenLongLength; // pixelHeight = _screenShortLength; // } // else //portrait // { //// DZDebug.Log("------------- PORTRAIT ----------------"); // pixelWidth = _screenShortLength; // pixelHeight = _screenLongLength; // } // Don't need the orientation stuff above for a PC game. If we do a mobile build... maybe look at this more? For PC just match unity's screen size pixelWidth = Screen.width; pixelHeight = Screen.height; float displayScaleModifier = 1.0f; if (_futileParams.resolutionLevelPicker != null) { _resLevel = _futileParams.resolutionLevelPicker(Mathf.RoundToInt(pixelWidth), Mathf.RoundToInt(pixelHeight)); } else { //note: resolution levels have been sorted smallest to largest //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :) if (_futileParams.resLevels.Count == 0) { throw new FutileException("You must add at least one FResolutionLevel!"); } float checkLength; if (_futileParams.resolutionLevelPickDimension == FResolutionLevelPickDimension.Longest) { checkLength = _screenLongLength; } else { checkLength = _screenShortLength; } _resLevel = null; if (_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Upwards) //finds the smallest resolution level that is bigger than the screen { for (int r = 0; r < _futileParams.resLevels.Count; r++) //iterating from smallest to largest { FResolutionLevel checkResLevel = _futileParams.resLevels[r]; if (checkResLevel.maxLength >= checkLength) //we've found our resLevel { _resLevel = checkResLevel; break; } } } else if (_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Downwards) //finds the biggest resolution level that is smaller than screen { for (int r = _futileParams.resLevels.Count - 1; r >= 0; r--) //note reverse iteration (from largest to smallest) { FResolutionLevel checkResLevel = _futileParams.resLevels[r]; if (checkResLevel.maxLength <= checkLength) //we've found our resLevel { _resLevel = checkResLevel; break; } } } else if (_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Closest) //finds the closest resolution level to the screen size { float winningDist = float.MaxValue; for (int r = 0; r < _futileParams.resLevels.Count; r++) { FResolutionLevel resLevel = _futileParams.resLevels[r]; float dist = Mathf.Abs(resLevel.maxLength - checkLength); if (dist < winningDist) { _resLevel = resLevel; winningDist = dist; } } } //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose the biggest if (_resLevel == null) { _resLevel = _futileParams.resLevels.GetLastItem(); } if (_futileParams.shouldLerpToNearestResolutionLevel) { displayScaleModifier = checkLength / _resLevel.maxLength; } } Futile.resourceSuffix = _resLevel.resourceSuffix; //this is what helps us figure out the display scale if we're not at a specific resolution level //it's relative to the next highest resolution level Futile.displayScale = _resLevel.displayScale * displayScaleModifier; Futile.displayScaleInverse = 1.0f / Futile.displayScale; Futile.resourceScale = _resLevel.resourceScale; Futile.resourceScaleInverse = 1.0f / Futile.resourceScale; width = pixelWidth * Futile.displayScaleInverse; height = pixelHeight * Futile.displayScaleInverse; //ceil to multiple of 2 //width = Mathf.Ceil(width/2f)*2f; //height = Mathf.Ceil(height/2f)*2f; if (Futile.isOpenGL) { Futile.screenPixelOffset = 0; } else //directX needs to be offset by half a pixel { //NOT offsetting directX anymore because it just makes everything look bad! Futile.screenPixelOffset = 0; //Futile.screenPixelOffset = 0.5f * Futile.displayScaleInverse; } halfWidth = Mathf.Round(width / 2.0f); halfHeight = Mathf.Round(height / 2.0f); //_originX = _futileParams.origin.x; //_originY = _futileParams.origin.y; //snap origin to whole pixels _originX = Mathf.Round(width * _futileParams.origin.x) / width; _originY = Mathf.Round(height * _futileParams.origin.y) / height; Debug.Log("Futile: Display scale is " + Futile.displayScale); Debug.Log("Futile: Resource scale is " + Futile.resourceScale); Debug.Log("Futile: Resource suffix is " + _resLevel.resourceSuffix); Debug.Log("FScreen: Screen size in pixels is (" + pixelWidth + "px," + pixelHeight + "px)"); Debug.Log("FScreen: Screen size in points is (" + width + "," + height + ")"); Debug.Log("FScreen: Origin is at (" + _originX * width + "," + _originY * height + ")"); Debug.Log("FScreen: Initial orientation is " + _currentOrientation); _didJustResize = true; }
public FScreen(FutileParams futileParams) { _futileParams = futileParams; #if UNITY_IPHONE || UNITY_ANDROID #if UNITY_3_5 TouchScreenKeyboard.autorotateToLandscapeLeft = false; TouchScreenKeyboard.autorotateToLandscapeRight = false; TouchScreenKeyboard.autorotateToPortrait = false; TouchScreenKeyboard.autorotateToPortraitUpsideDown = false; #else Screen.autorotateToLandscapeLeft = false; Screen.autorotateToLandscapeRight = false; Screen.autorotateToPortrait = false; Screen.autorotateToPortraitUpsideDown = false; #endif #endif //Non-mobile unity always defaults to portrait for some reason, so fix this manually if (Screen.height > Screen.width) { _currentOrientation = ScreenOrientation.Portrait; } else { _currentOrientation = ScreenOrientation.LandscapeLeft; } //get the correct orientation if we're on a mobile platform #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID) _currentOrientation = Screen.orientation; #endif //special "single orientation" mode if (_futileParams.singleOrientation != ScreenOrientation.Unknown) { _currentOrientation = _futileParams.singleOrientation; } else //if we're not in a supported orientation, put us in one! { if (_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft) { if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } else if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } } else if (_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight) { if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } } else if (_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait) { if (_futileParams.supportsPortraitUpsideDown) { _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } } else if (_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown) { if (_futileParams.supportsPortrait) { _currentOrientation = ScreenOrientation.Portrait; } else if (_futileParams.supportsLandscapeLeft) { _currentOrientation = ScreenOrientation.LandscapeLeft; } else if (_futileParams.supportsLandscapeRight) { _currentOrientation = ScreenOrientation.LandscapeRight; } } } Screen.orientation = _currentOrientation; _screenLongLength = Math.Max(Screen.height, Screen.width); _screenShortLength = Math.Min(Screen.height, Screen.width); if (_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown) { pixelWidth = _screenShortLength; pixelHeight = _screenLongLength; } else //landscape { pixelWidth = _screenLongLength; pixelHeight = _screenShortLength; } //note: resolution levels have been sorted smallest to largest //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :) if (_futileParams.resLevels.Count == 0) { throw new FutileException("You must add at least one FResolutionLevel!"); } float checkLength; if (_futileParams.resolutionLevelPickDimension == FResolutionLevelPickDimension.Longest) { checkLength = _screenLongLength; } else { checkLength = _screenShortLength; } _resLevel = null; if (_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Upwards) //finds the smallest resolution level that is bigger than the screen { for (int r = 0; r < _futileParams.resLevels.Count; r++) //iterating from smallest to largest { FResolutionLevel checkResLevel = _futileParams.resLevels[r]; if (checkResLevel.maxLength >= checkLength) //we've found our resLevel { _resLevel = checkResLevel; break; } } } else if (_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Downwards) //finds the biggest resolution level that is smaller than screen { for (int r = _futileParams.resLevels.Count - 1; r >= 0; r--) //note reverse iteration (from largest to smallest) { FResolutionLevel checkResLevel = _futileParams.resLevels[r]; if (checkResLevel.maxLength <= checkLength) //we've found our resLevel { _resLevel = checkResLevel; break; } } } else if (_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Closest) //finds the closest resolution level to the screen size { float winningDist = float.MaxValue; for (int r = 0; r < _futileParams.resLevels.Count; r++) { FResolutionLevel resLevel = _futileParams.resLevels[r]; float dist = Mathf.Abs(resLevel.maxLength - checkLength); if (dist < winningDist) { _resLevel = resLevel; winningDist = dist; } } } //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose the biggest if (_resLevel == null) { _resLevel = _futileParams.resLevels.GetLastItem(); } Futile.resourceSuffix = _resLevel.resourceSuffix; //this is what helps us figure out the display scale if we're not at a specific resolution level //it's relative to the next highest resolution level float displayScaleModifier = 1.0f; if (_futileParams.shouldLerpToNearestResolutionLevel) { displayScaleModifier = checkLength / _resLevel.maxLength; } Futile.displayScale = _resLevel.displayScale * displayScaleModifier; Futile.displayScaleInverse = 1.0f / Futile.displayScale; Futile.resourceScale = _resLevel.resourceScale; Futile.resourceScaleInverse = 1.0f / Futile.resourceScale; width = pixelWidth * Futile.displayScaleInverse; height = pixelHeight * Futile.displayScaleInverse; if (Futile.isOpenGL) { Futile.screenPixelOffset = 0; } else //directX needs to be offset by half a pixel { Futile.screenPixelOffset = 0.5f * Futile.displayScaleInverse; } halfWidth = width / 2.0f; halfHeight = height / 2.0f; _originX = _futileParams.origin.x; _originY = _futileParams.origin.y; Debug.Log("Futile: Display scale is " + Futile.displayScale); Debug.Log("Futile: Resource scale is " + Futile.resourceScale); Debug.Log("Futile: Resource suffix is " + _resLevel.resourceSuffix); Debug.Log("FScreen: Screen size in pixels is (" + pixelWidth + "px," + pixelHeight + "px)"); Debug.Log("FScreen: Screen size in points is (" + width + "," + height + ")"); Debug.Log("FScreen: Origin is at (" + _originX * width + "," + _originY * height + ")"); Debug.Log("FScreen: Initial orientation is " + _currentOrientation); _didJustResize = true; }
public FScreen(FutileParams futileParams) { _futileParams = futileParams; #if UNITY_IPHONE || UNITY_ANDROID #if UNITY_3_5 TouchScreenKeyboard.autorotateToLandscapeLeft = false; TouchScreenKeyboard.autorotateToLandscapeRight = false; TouchScreenKeyboard.autorotateToPortrait = false; TouchScreenKeyboard.autorotateToPortraitUpsideDown = false; #else Screen.autorotateToLandscapeLeft = false; Screen.autorotateToLandscapeRight = false; Screen.autorotateToPortrait = false; Screen.autorotateToPortraitUpsideDown = false; #endif #endif //Non-mobile unity always defaults to portrait for some reason, so fix this manually if(Screen.height > Screen.width) { _currentOrientation = ScreenOrientation.Portrait; } else { _currentOrientation = ScreenOrientation.LandscapeLeft; } //get the correct orientation if we're on a mobile platform #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID) _currentOrientation = Screen.orientation; #endif //special "single orientation" mode if(_futileParams.singleOrientation != ScreenOrientation.Unknown) { _currentOrientation = _futileParams.singleOrientation; } else //if we're not in a supported orientation, put us in one! { if(_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft) { if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if(_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight) { if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if(_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait) { if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; } else if(_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown) { if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; } } Screen.orientation = _currentOrientation; _screenLongLength = Math.Max(Screen.height, Screen.width); _screenShortLength = Math.Min(Screen.height, Screen.width); if(_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown) { pixelWidth = _screenShortLength; pixelHeight = _screenLongLength; } else //landscape { pixelWidth = _screenLongLength; pixelHeight = _screenShortLength; } //note: resolution levels have been sorted smallest to largest //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :) if(_futileParams.resLevels.Count == 0) { throw new FutileException("You must add at least one FResolutionLevel!"); } _resLevel = null; if(_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Upwards) //finds the smallest resolution level that is bigger than the screen { for(int r = 0; r<_futileParams.resLevels.Count; r++) //iterating from smallest to largest { FResolutionLevel checkResLevel = _futileParams.resLevels[r]; if(checkResLevel.maxLength >= _screenLongLength) //we've found our resLevel { _resLevel = checkResLevel; break; } } } else if(_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Downwards) //finds the biggest resolution level that is smaller than screen { for(int r = _futileParams.resLevels.Count-1; r >= 0; r--)//note reverse iteration (from largest to smallest) { FResolutionLevel checkResLevel = _futileParams.resLevels[r]; if(checkResLevel.maxLength <= _screenLongLength) //we've found our resLevel { _resLevel = checkResLevel; break; } } } else if(_futileParams.resolutionLevelPickMode == FResolutionLevelPickMode.Closest) //finds the closest resolution level to the screen size { float winningDist = float.MaxValue; for(int r = 0; r<_futileParams.resLevels.Count; r++) { FResolutionLevel resLevel = _futileParams.resLevels[r]; float dist = Mathf.Abs(resLevel.maxLength - _screenLongLength); if(dist < winningDist) { _resLevel = resLevel; winningDist = dist; } } } //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose the biggest if(_resLevel == null) { _resLevel = _futileParams.resLevels.GetLastItem(); } Futile.resourceSuffix = _resLevel.resourceSuffix; //this is what helps us figure out the display scale if we're not at a specific resolution level //it's relative to the next highest resolution level float displayScaleModifier = 1.0f; if(_futileParams.shouldLerpToNearestResolutionLevel) { displayScaleModifier = _screenLongLength/_resLevel.maxLength; } Futile.displayScale = _resLevel.displayScale * displayScaleModifier; Futile.displayScaleInverse = 1.0f/Futile.displayScale; Futile.resourceScale = _resLevel.resourceScale; Futile.resourceScaleInverse = 1.0f/Futile.resourceScale; width = pixelWidth*Futile.displayScaleInverse; height = pixelHeight*Futile.displayScaleInverse; if(Futile.isOpenGL) { Futile.screenPixelOffset = 0; } else //directX needs to be offset by half a pixel { Futile.screenPixelOffset = 0.5f * Futile.displayScaleInverse; } halfWidth = width/2.0f; halfHeight = height/2.0f; _originX = _futileParams.origin.x; _originY = _futileParams.origin.y; Debug.Log ("Futile: Display scale is " + Futile.displayScale); Debug.Log ("Futile: Resource scale is " + Futile.resourceScale); Debug.Log ("Futile: Resource suffix is " + _resLevel.resourceSuffix); Debug.Log ("FScreen: Screen size in pixels is (" + pixelWidth +"px," + pixelHeight+"px)"); Debug.Log ("FScreen: Screen size in points is (" + width + "," + height+")"); Debug.Log ("FScreen: Origin is at (" + _originX*width + "," + _originY*height+")"); Debug.Log ("FScreen: Initial orientation is " + _currentOrientation); _didJustResize = true; }
public void Init(FutileParams futileParams) { enabled = true; _futileParams = futileParams; Application.targetFrameRate = _futileParams.targetFrameRate; #if UNITY_IPHONE || UNITY_ANDROID TouchScreenKeyboard.autorotateToLandscapeLeft = false; TouchScreenKeyboard.autorotateToLandscapeRight = false; TouchScreenKeyboard.autorotateToPortrait = false; TouchScreenKeyboard.autorotateToPortraitUpsideDown = false; #endif //Non-mobile unity always defaults to portrait for some reason, so fix this manually if(Screen.height > Screen.width) { _currentOrientation = ScreenOrientation.Portrait; } else { _currentOrientation = ScreenOrientation.LandscapeLeft; } //get the correct orientation if we're on a mobile platform #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID) _currentOrientation = Screen.orientation; #endif //special "single orientation" mode if(_futileParams.singleOrientation != ScreenOrientation.Unknown) { _currentOrientation = _futileParams.singleOrientation; } else //if we're not in a supported orientation, put us in one! { if(_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft) { if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if(_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight) { if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; } else if(_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait) { if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown; else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; } else if(_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown) { if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait; else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft; else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight; } } Screen.orientation = _currentOrientation; Futile.startingQuadsPerLayer = _futileParams.startingQuadsPerLayer; Futile.quadsPerLayerExpansion = _futileParams.quadsPerLayerExpansion; Futile.maxEmptyQuadsPerLayer = _futileParams.maxEmptyQuadsPerLayer; _screenLongLength = Math.Max(Screen.height, Screen.width); _screenShortLength = Math.Min(Screen.height, Screen.width); if(_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown) { pixelWidth = _screenShortLength; pixelHeight = _screenLongLength; } else //landscape { pixelWidth = _screenLongLength; pixelHeight = _screenShortLength; } //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :) _resLevel = null; foreach(FResolutionLevel resLevel in _futileParams.resLevels) { if(_screenLongLength <= resLevel.maxLength) //we've found our resLevel { _resLevel = resLevel; break; } } //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose that one if(_resLevel == null) { _resLevel = _futileParams.resLevels.GetLastObject(); if(_resLevel == null) { throw new Exception("You must add at least one FResolutionLevel!"); } } Futile.resourceSuffix = _resLevel.resourceSuffix; //this is what helps us figure out the display scale if we're not at a specific resolution level //it's relative to the next highest resolution level float displayScaleModifier = 1.0f; if(_futileParams.shouldLerpToNearestResolutionLevel) { displayScaleModifier = _screenLongLength/_resLevel.maxLength; } displayScale = _resLevel.displayScale * displayScaleModifier; displayScaleInverse = 1.0f/displayScale; resourceScale = _resLevel.resourceScale; resourceScaleInverse = 1.0f/resourceScale; width = pixelWidth*displayScaleInverse; height = pixelHeight*displayScaleInverse; halfWidth = width/2.0f; halfHeight = height/2.0f; _originX = _futileParams.origin.x; _originY = _futileParams.origin.y; Debug.Log ("Futile: Display scale is " + displayScale); Debug.Log ("Futile: Resource scale is " + resourceScale); Debug.Log ("Futile: Resource suffix is " + _resLevel.resourceSuffix); Debug.Log ("Futile: Screen size in pixels is (" + pixelWidth +"px," + pixelHeight+"px)"); Debug.Log ("Futile: Screen size in points is (" + width + "," + height+")"); Debug.Log ("Futile: Origin is at (" + _originX*width + "," + _originY*height+")"); Debug.Log ("Futile: Initial orientation is " + _currentOrientation); // //Camera setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs // name = "Futile"; _cameraHolder = new GameObject(); _cameraHolder.transform.parent = gameObject.transform; _cameraHolder.AddComponent<Camera>(); _camera = _cameraHolder.camera; _camera.name = "FCamera"; //_camera.clearFlags = CameraClearFlags.Depth; //TODO: check if this is faster or not? _camera.clearFlags = CameraClearFlags.SolidColor; _camera.nearClipPlane = -50.3f; _camera.farClipPlane = 50.0f; _camera.depth = 100; _camera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f); _camera.backgroundColor = _futileParams.backgroundColor; //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels _camera.orthographic = true; _camera.orthographicSize = pixelHeight/2 * displayScaleInverse; UpdateCameraPosition(); _didJustResize = true; touchManager = new FTouchManager(); atlasManager = new FAtlasManager(); stage = new FStage(); }