Unity-rendering hierarchy


Insert picture description here
Rendering is mainly for the content displayed under the Game window, similar to the drawing board, first draw one layer and then draw one layer, and then you can overwrite the previous layer. So Unity has a hierarchy of rendering relationships.

Camera level

Because the Game window is the mapping screen of the camera, the Camera is the high-level rendering result.
Camera's Depth

For example: I only added two cameras, one is the Main Camera that comes with the scene and the Camera I added. I first disable the Camera.
Insert picture description here
This is the Game scene mapped by the Main Camera, which can perfectly display the scene I set. , The Depth of the Main Camera at this time is -1.
Insert picture description here
After the added Camera is enabled, there is no object in the Game window, and the Depth layer of the camera is 0, which is higher than the Main Camera, so the original Main Camera screen is overwritten, resulting in no screen.

Under the same Camera, Sorting Layer

The previous Camera is suitable for 3D and 2D scenes. The previous one used 3D projects to do experiments. The same is true for 2D. The latter ones are suitable for 2D scenes. Because this is about the rendering of pictures, there are also about the use of pictures in 3D, but I mainly learn about rendering in 2D. (If you think it is, you can understand
Insert picture description here
it according to your actual situation ) This is a newly created 2D scene, all objects are under the Main Camera (in the case of the same camera).
At this time , all objects are in the same Sorting Layer (all are Default) , The rendering level relationship is compared according to the order of the objects in your Hierarchy panel. For example, house is added last, so its rendering level is the highest. When it is before other objects, it will be overwritten and only the house itself will be displayed.
Insert picture description here
Here, the following crates are overwritten. If the
rendering level is changed, the Sorting Layer of the two must be changed. The
Insert picture description here
house has not changed, and the Sorting Layer of the crate is changed. This Sorting Layer can add the level name
Insert picture description here
by itself. The rendering relationship at this time is just Render according to the order panel of Sorting Layer, render the Default layer first, and then render the backGround layer, that is to say, the backGround layer covers the previous Default.
Insert picture description here
So this time, instead of house covering the crate, it becomes a crate covering the house.

Order in Layer

This level is mainly for the problem of not wanting to change the Sorting Layer level and at the same time achieve the order of rendering that you want to render.
Insert picture description here
Once again, change the Sorting Layer level of the crate to be the same as the house level. The house covers the crate
but this time change the Order in Layer level of the
Insert picture description here
crate to let the crate. The Order in Layer level becomes 1, so that the rendering level of the crate is higher than the house,
so it becomes:
Insert picture description here
crate covers the house

Layer level

Insert picture description here
Here is also a hierarchical change of the rendering relationship, but it is mainly similar to the classification order of scene objects
Insert picture description here

At this time, I made the sorting layer and order in layer of the crate the same as the house, only changed the layer of the crate to Ground (there were only 5 in the original layer, and my Ground was added by myself, and the Sorting Layer above was added in the same way. Same)
Insert picture description here
But I didn't think that the rendering level of Ground is greater than Default to cover the house as I expected. So Layer is usually used for classification, and the Layer level used in the script needs to be added to detect collisions and so on.

summary

To build a 2D scene, you usually need to change the Sorting Layer and Order in Layer. You can add some unique Layer levels to the object classification by writing your own script or in some cases.

Guess you like

Origin blog.csdn.net/m0_48554728/article/details/112701771