Managed Sprites
In cases where it is advantageous to have direct control over things like draw-order, or you do not want to rely on dynamic batching to control draw calls, EZ GUI provides the ability to optionally use a SpriteManager to combine sprites together into a single mesh.Using Managed Sprites
To use managed sprites, you must first create a GameObject in your scene with a SpriteManager script attached:
Depth-sorting Sorting among sprites in the same manager Unlike unmanaged sprites, managed sprites are not automatically depth-sorted according to their distance from the camera. Instead, you can control the draw order of your sprites by setting their drawLayer value either by setting it in the inspector, or by calling SetDrawLayer() at runtime in script. Sprites with a lower draw layer value will appear to be drawn behind sprites with a higher draw layer value. All of this only holds true within a single sprite manager. Unity will automatically handle depth sorting between sprite managers, as it views each manager as a single mesh (which it is). It is therefore only possible to interleave sprites from different managers when using shaders that read and write to the Z-buffer. Sorting with other scene objects There is an additional consideration regarding depth-sorting when using managed sprites: depth-sorting sprites with regard to other objects in the scene. For example, you have may a sprite that is paired with a TextMesh (3D Text) that you want to be drawn on top of the sprite, such as if this is being used as a button control. The problem can arise that even though your text is in front of your sprite, the sprite is being drawn over the text. This is because all sprites in the SpriteManager are a single mesh, and as such, that mesh has a bounding box. The center of that bounding box is what Unity uses to determine the distance of the object to the camera versus other objects in the scene, and if both objects in question are blended, then the nearer of the two objects will get draw last on top of the one that is farther away. So if your text is appearing behind your sprite despite it being positioned in front of it, check to see where the center point of the over all SpriteManager is by selecting it, or by checking its Draw Bounding Box checkbox. This will display a yellow bounding box, at the center of which is a small "star" which indicates the center point. If this center point is nearer to the camera than the text in our example scenario, then ALL sprites in the SpriteManager will be draw on top. To remedy this, make sure you either move some of your sprites back to shift the center point of the bounding box, or move your text or other objects forward to be in front of the SpriteManager's center point. (Also see important note below.)
|