Created
November 27, 2020 10:28
-
-
Save andijakl/d0df8cc08a7d29362f65dc6170686b64 to your computer and use it in GitHub Desktop.
Adapt the RawImage size in Unity to the depth map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the aspect ratio for the current texture. | |
var textureAspectRatio = (float)texture.width / texture.height; | |
// Determine the raw image rectSize preserving the texture aspect ratio, matching the screen orientation, | |
// and keeping a minimum dimension size. | |
const float minDimension = 480.0f; | |
var maxDimension = Mathf.Round(minDimension * textureAspectRatio); | |
var rectSize = new Vector2(maxDimension, minDimension); | |
//var rectSize = new Vector2(minDimension, maxDimension); //Portrait | |
rawImage.rectTransform.sizeDelta = rectSize; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment