[Unity component extension] Reduce the rendering of Image

It is necessary to implement the transparent mask function, such as clicking any to close the interface, transparent masking to prevent clicking, etc. Generally, you can add an Image component, and then set the alpha value to 0. However, in Unity2018.4.3.6f1 and previous versions, this approach will increase DC and increase overdraw.

You can inherit Graphic and rewrite the OnPopulateMesh method to reduce the performance consumption in this area.

using UnityEngine.UI;

public class EmptyImage : Graphic
{
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
    }
}

But in 2021.3.19f1, this problem has been optimized. After setting the alpha value of Image to 0, DC and overdraw will not be increased.

1111
Image does not have alpha set

Image alpha is 0

おすすめ

転載: blog.csdn.net/qq_33461689/article/details/131911984