In Unity, get a grid or else get local borders on Sprite?

This question only applies to the Unity game engine .

Here is a visual example of a so-called unity sprite (Unity Sprite class), which is a thin three-dimensional object.

enter image description here enter image description here

Shown AABB (green lines). On Unity live, AABB with gpu is provided via .bounds( doco ). If new to CG, explanation of AABB .

(Note: "local" in Unity ( doco , doco ) means: in the quaternion of the parent object, "world" means in the quaternion of the scene object.)

Now! For all Unity engineers:

Usually in Unity with a visible object, when you want to get Unity Bounds ,

if you want them in world space, renderer.boundsreturns Unity Bounds in world space.

if you want them in local space, mesh.boundsreturns Unity Bounds in local space.

This is the foundation of unity, and you do it all the time. However. As for the new sprite, that is SpriteRenderer, there is no real access to the grid , as far as I know.

(In fact, you can get triangles, but it would be quite a challenge to restore the winding and size from there.)

How then can you get a local Unity Bounds for a sprite?

( , sprite.bounds renderer.bounds, .)

+4
1

, SpriteRenderer.sprite.bounds.

public class LogBounds : MonoBehaviour {
    void OnGUI () {
        var r = GetComponent<SpriteRenderer>();
        GUILayout.Label("SpriteRenderer.bounds center " + r.bounds.center + " size " + r.bounds.size);
        GUILayout.Label("SpriteRenderer.sprite.bounds center " + r.sprite.bounds.center + " size " + r.sprite.bounds.size);
    }
}

example

, SpriteRenderer.sprite.bounds - .

+5

All Articles