Skip to content

Instantly share code, notes, and snippets.

@andijakl
Created November 27, 2020 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andijakl/d0df8cc08a7d29362f65dc6170686b64 to your computer and use it in GitHub Desktop.
Save andijakl/d0df8cc08a7d29362f65dc6170686b64 to your computer and use it in GitHub Desktop.
Adapt the RawImage size in Unity to the depth map
// 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