With Unity's own features, how do you show blood strips?
Display the blood bar, from the resource minimization point of view, as long as the color point of a pixel to enlarge into a rectangle is enough, three different colors of the rectangle, showing the foreground color, background color, fill color, this will consume the least memory resources.
Unity has guitexture that can be used to display color blocks. But Guitexture has a problem is that each guitexture will consume a drawcall, if the screen on the hundreds of units, will consume hundreds of drawcall,drawcall is an expensive resource, A hand tour can only allow 200 or so drawcall, obviously this program can only be used to do the demo, can not be used for practical development and use.
Then is Ugui image and Rawimage, this seems good, as long as the image stitching on a picture, only consumes a drawcall, so no matter how many units, as long as a drawcall can display all the blood bar.
But the blood bar has a request, is the unit moves, the blood bar displays the order, must satisfy the unit the occlusion relation. And Ugui control, can not follow the z-index to show, they are "flat", want to adjust the relationship, you must detect the Z-index of each unit, then sort them, and then sort the results, adjust the order of the blood bar display, this action every frame to do, obviously, The load on this operation is unacceptable.
Is there any other way? There are two other ways to meet the requirements.
The first kind, with a sprite. Unity can pack multiple sprites into one texutre. The sprite can meet the order of display requirements. As long as the three rectangles are oriented to the camera, when displayed, the foreground color is closest to the camera, the fill color is the second, and finally the background color. Multiple Sprite, if its texture is one, then can be displayed with 1 Drawcall.
The second, with four points of the rectangle to display, but also look at the camera, in fact, essentially similar to the principle of the sprite.
There is another problem in this, that is, the issue of transparency. If the background color is required to be opaque, and the fill color is transparent, the first method cannot be implemented. The second method also needs to be improved, the second kind of rectangle must be made into eight vertices, with inner and outer frames, inner box using transparent color, and outer box is opaque color.
Further, if you want the blood bar to show different colors in different states, there will be more complex algorithms, but all must meet the minimum drawcall principle, all the blood strips are only used 1 drawcall.
If you want to display text on the side of a blood bar, you cannot use Guitext and Ugui controls for similar reasons. Can be implemented with Textmesh, this is also multiple words using a drawcall.
How Unity displays blood strips (without using Ngui)