void Update() { var ratio = 0f; var screenHeightRatio = (float)Screen.height / pixelHeight; var ratioWithCroppingAllowed = Mathf.Ceil(screenHeightRatio) / screenHeightRatio; // if we allow cropping we can display things larger but we might lose some of the screen if (allowCropping) { ratio = ratioWithCroppingAllowed; } else { ratio = Mathf.Floor(screenHeightRatio) / screenHeightRatio; } if (_lastPixelHeight != pixelHeight || _lastRatio != ratio || _lastColorDepth != colorDepth || _lastCustomMaterial != customMaterial) { allowCropping = true; if (ratioWithCroppingAllowed > 1f + maxOffAspectRatio) { switch (offAspectBehavior) { case OffAspectBehavior.DisableCrop: { allowCropping = false; break; } case OffAspectBehavior.SetNearestPerfectFitResolution: { // round the current screenHeightRatio to get the closest perfect fit height var bestWholeHeight = Mathf.RoundToInt(screenHeightRatio) * pixelHeight; Screen.SetResolution(Screen.width, bestWholeHeight, Screen.fullScreen); return; } } } updateTexture(true); _lastPixelHeight = pixelHeight; _lastRatio = ratio; _lastColorDepth = colorDepth; _lastCustomMaterial = customMaterial; _quad.transform.localScale = Vector3.one * ratio; } if (targetCamera != null && (targetCamera.targetTexture != _texture || _texture == null)) { updateTexture(true); } }
void Update() { var ratio = 0f; var screenHeightRatio = (float)Screen.height / pixelHeight; var ratioWithCroppingAllowed = Mathf.Ceil( screenHeightRatio ) / screenHeightRatio; // if we allow cropping we can display things larger but we might lose some of the screen if( allowCropping ) ratio = ratioWithCroppingAllowed; else ratio = Mathf.Floor( screenHeightRatio ) / screenHeightRatio; if( _lastPixelHeight != pixelHeight || _lastRatio != ratio || _lastColorDepth != colorDepth || _lastCustomMaterial != customMaterial ) { allowCropping = true; if( ratioWithCroppingAllowed > 1f + maxOffAspectRatio ) { switch( offAspectBehavior ) { case OffAspectBehavior.DisableCrop: { allowCropping = false; break; } case OffAspectBehavior.SetNearestPerfectFitResolution: { // round the current screenHeightRatio to get the closest perfect fit height var bestWholeHeight = Mathf.RoundToInt( screenHeightRatio ) * pixelHeight; Screen.SetResolution( Screen.width, bestWholeHeight, Screen.fullScreen ); return; } } } updateTexture( true ); _lastPixelHeight = pixelHeight; _lastRatio = ratio; _lastColorDepth = colorDepth; _lastCustomMaterial = customMaterial; _quad.transform.localScale = Vector3.one * ratio; } if( targetCamera != null && ( targetCamera.targetTexture != _texture || _texture == null ) ) updateTexture( true ); }