Last active
October 1, 2024 04:57
-
-
Save xwipeoutx/4221404088a74b9975a35040819c5861 to your computer and use it in GitHub Desktop.
Find the rectangle a rect transform will use on a SceneView. Good for labels and stuff.
This file contains 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
var sceneView = SceneView.currentDrawingSceneView; | |
var canvas = rectTransform.GetComponentInParent<Canvas>(); | |
var zoomFactor = sceneView.position.height / (sceneView.camera.orthographicSize * 2); | |
var pivotPosition = HandleUtility.WorldToGUIPoint(rectTransform.position); | |
var sizeOnCanvas = RectTransformUtility.PixelAdjustRect(rectTransform, canvas).size; | |
var size = sizeOnCanvas * zoomFactor + buffer * Vector2.one; | |
var pos = pivotPosition - size * new Vector2(rectTransform.pivot.x, 1 - rectTransform.pivot.y); | |
var sceneViewRect = new Rect(pos, size); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment