Chapter 2 Unity Interface Understanding

In this chapter, we will get to know the main interface of Unity , as shown below

Although Unity 's main interface contains a lot of content, the structure is still relatively clear, so it is not messy. From top to bottom, from left to right are the menu bar, toolbar, hierarchy panel ( Hierarchy ), scene view ( Scene ), game view ( Game ), inspection panel ( Inspector ), project panel ( Project ) and console panel ( Console ). Regarding the Chinese translation of these panels, we don’t have to worry too much. The main thing is to remember the corresponding English names.

What are these panels or views used for?

1. The hierarchy panel is a list display of game objects in the scene. Any visible object in the game scene is a game object.

2. The scene view can be used for visual scene editing, that is, to place any game objects in the scene in a WYSIWYG manner.

3. The game view is the interface effect after the game is running (similar to the scene view). Click  the triangle Play to run the game.

4. The inspection panel can be used to view and edit all properties of the currently selected game object. We often operate here.

5. The project panel displays files that can be used in the current project, including models, textures, materials, scripts and resource libraries.

First, we first introduce the hierarchy panel ( Hierarchy ) and scene view ( Scene ), as shown in the figure below

On the left is the hierarchy panel ( Hierarchy ), and on the right is the scene view ( Scene ). Please note that Scene and Game are two Tabs . We can click on them to switch between the scene view and the game view. As follows

The reason why the two views are laid out in this way is because they are very similar and both display game content. Of course, this is not the point. When we return to the hierarchy panel, we can see the following

SampleScene is a scene that Unity automatically creates for us. There are two game objects in this scene, one is the main camera and the other is the directional light (in fact, there is also a default sky box).

What is a scene? This word is probably more used in film shooting. To simply understand, it is the environmental background when an actor shoots a clip. Scenarios are a similar concept in game development. A scene can be understood as an independent game world. Each scene has its own natural environment, architectural environment, character environment, UI interface, etc. The world in this scene can be very large or very small. Scenes are isolated from each other (because they are two different files themselves), and it is impossible for our game characters to "walk seamlessly" from one scene to another. Generally, we can divide the entire game world into several different scenes. Of course, we can also build the entire game world into one large scene ( seamless large map ) . Unity will save each scene as a scene file with the suffix " unity ". The scene file is saved in the " Assets/Scenes " directory by default. Of course, we can also save it to other locations.  Personal understanding, for reference only!

What is a game object? Anyone who is familiar with programming should know object-oriented programming, which is a common feature of most high-level programming languages ​​today. A class is an abstract template that describes things. After a class is instantiated (exists in computer memory), it becomes an object. Well, the same goes for game objects. Everything (or object) we see in the game world is a game object. The reason why we can see them is because they are instantiated and exist objectively in the computer memory world. The camera and directional light mentioned above are two game objects. Of course, if we want to create a colorful game world, we need to create more game objects, such as mountains and rivers, trees and flowers, buildings, pavilions, birds and animals, etc. As you can see, there may be thousands of game objects in a scene. Most of these game objects are 3D models, which are basically produced by software such as 3ds max or maya and then imported into Unity . We need to "place" these models (that is, these game objects) in the Scene view. Personal understanding, for reference only!

The game objects in the Hierarchy panel are the same as those in the Scene view, except that one is displayed in list form and the other is displayed in three-dimensional form. If we add or remove game objects in the Scene view, they will also be added or removed from the Hierarchy panel. Vice versa, the same effect is achieved. If we select a game object in the Hierarchy panel, it will also be selected in the Scene view. As follows

What we selected above is the " Main Camera " main camera game object.

The above is the " Directional Light " directional light game object we selected .

The key point here is that a parent-child relationship can be formed between Unity's game objects. A child game object can inherit the properties of the parent game object, and when the parent game object is moved, its child game objects will be moved synchronously. Of course, this operation also includes rotation and scaling, which are the three major transformations of the world. This is very helpful to our game development.

We have two game objects " Main Camera" and " Directional Light " in the hierarchy panel . In the corresponding scene view, we can see the two game objects camera and directional light, as shown below

If you can't see it, you can scroll the middle mouse wheel to zoom in and out of the scene view. We can see a camera-like logo and a sun-like logo. They are the main camera and parallel light. The function of the camera is to collect the content of the game world and output it to the Game view, while the function of the parallel light is to simulate sunlight and illuminate the entire game scene. 

When there are many game objects in the scene, we need some convenient operations in order to accurately find the specified game object. For example, we can find this game object in the hierarchy panel (this operation is relatively simple), then we "move (do not click)" the mouse to the scene view, and then press the "F" key to click in the scene view This game object is displayed in . This operation is similar to the " Z " key in 3ds Max . In addition, we can also control the hiding and display of game objects in the hierarchy panel. This operation will not affect the visibility of the object in the game.

The eye logo in the picture is used to control the hiding and display of game objects. You can also select the game object and press the shortcut key H to switch between hiding and displaying (very convenient). When we don't want a certain game object to interfere with our current operations, we can use this "eye" to temporarily hide the game object. This can be useful for working with large or complex scenes where it is difficult to view and select specific game objects. Note that using visibility options is safer than disabling game objects because visibility options only affect the Scene view. In addition, if we select a game object and use the shortcut key Shift + H , we will enter the Isolation view, which will only display the currently selected game object. The purpose of this is to make it easier for us to focus on editing these selected game objects without being disturbed by other game objects. To exit the Isolation view just press Shift + H again , or click the Exit button in the Scene view .

In fact, to put it bluntly, the Isolation view only displays the selected game object and hides other game objects.

Next, we introduce the toolbar in the scene view.

The first one, the drawing mode of the scene view, defaults to Shaded to display game objects normally; Wireframe to display game objects in wireframe form; Shaded Wireframe to mix normal and wireframe forms to display game objects; the others will not be introduced.

The second one, the 2D button turns on the 2D mode, which is generally used when making UI and 2D games for easy operation.

Third, the light button is used to control the turning on and off of the lights in the scene, not to turn off the lights in the game.

Fourth, the sound button is used to control the opening and closing of the audio in the scene, not to turn off the sound in the game.

Fifth, the effect button controls whether to display effects such as skybox, fog, and halo.

Skybox: Displays a skybox in the scene.

Fog : Display fog effect in the scene.

Flares : Displays the lens flare effect on the light source.

Always Refresh : Defines whether the animated material displays animation.

Post Processing : Displays post-processing effects.

Particle Systems : Display particle system effects.

Sixth, the number of hidden game objects

Seventh, whether to display the fence grid (similar to the fence grid in 3ds max )

Eighth, whether to display the component editing panel (the first button on the right) in the scene view

Ninth, the camera editing button of the scene view (not the Main Camera in the scene ).

Tenth, Gizmos controls the display and hiding of object markers.

The eleventh, search bar, searches for game objects in the scene, and the searched objects will be highlighted.

That’s it for the introduction to scene view.

Next, we introduce the Game view.

Click the triangle Play button to run the game project and automatically switch to the Game view, as shown below

What we see in the Game view is the scene content captured by the Main Camera , which is only the gray ground and blue sky. In fact, we can think of the Main Camera as the player's eyes. The game world that players see is presented by the Main Camera . Please note that cameras and directional lights are not visible in the game view. They are used to assist us in creating game scenes and are not game objects that the player can see.

Next, we briefly introduce the Game view toolbar.

The first one, Display1 should be the monitor, and the game content will be output to Display1 by default .

Second, Free Aspect sets the display screen aspect ratio or fixed resolution, or you can add a new resolution manually.

The third one, Scale , adjusts the zoom ratio of the current game view.

Fourth, maximize during playback. Click this to maximize the game view.

The fifth, audio mute, controls the opening and closing of audio in the game.

The sixth one is the status window. This small window displays some information about the game running.

The seventh one, Gizmos , controls the display and hiding of game object markers, similar to Gizmos in the scene .

Here we briefly talk about the status window. The more vertices on the mesh object, the more delicate the shape of the mesh object, but too many vertices will occupy a lot of CPU and GPU resources. When developing a game, you can view statistics about the number of vertices in the stats panel of the game view.

Tris represents the number of triangular faces, and Verts represents the number of vertices.

Finally, we are talking about the understanding of the relationship between Scene scene view and Game game view.

When we click " Main Camera " in the hierarchy panel , a small window will appear in the lower right corner of the Scene view to display the content under the " Main Camera " camera (equivalent to the Game game view content).

The Scene view is the game world from the "God's perspective", which is presented by the Scene Camera . Although we can't see this Scene Camera , we can operate it through shortcut keys. The ninth button in the scene view toolbar mentioned above is used to control the Scene Camera . The Scene scene view mainly allows us developers to create the game world in a "what you see what you get" way. Therefore, we developers are the “Creator God”. There is a Main Camera in the Scene view , which collects the content in the Scene view and presents it to the Game view. This Main Camera is a game object that we can edit and control. Main Camera can be understood as the player's eyes. Since the game world is the same, it is just the presentation of two cameras with different perspectives. Therefore, the two cameras can overlap. In other words, the Scene view and Game view can display exactly the same content. This modification is divided into two situations. The first is to put the Game Camera ( Main Camera ) into the Scene Camera.position to keep the Game view consistent with the Scene view. The other is to place the Scene Camera at the position of the Game Camera ( Main Camera ) to keep the Scene view consistent with the Game view. Please note that the difference between two different operations is that one is motionless and the other is motion, and the motionless one is the final presentation. There are three operations under GameObject in the Unity menu bar : Move To View , Align With View and Align View to Selected . Their operation is explained below.

The first Move To View : If you select any game object and then perform the Move To View operation, the game will be moved to the middle of the scene view. Obviously, the position information of the game object will change. If this game object is a Main Camera , the game view will also change accordingly. Not used often.

The second Align With View : If you select any game object and then perform the Align With View operation, move the game object to the position of the Scene Camera . Obviously, this operation is meaningless. However, when the game object is the Main Camer , the Main Camer will be placed at the position of the Scene Camera . Then, the content presented in the game view at this time is exactly the same as the scene view. Use sparingly and frequently ( avoid modifying Main Camer) .

The third Align View to Selected : If you select any game object and then perform the Align View to Selected operation, the Scene Camera will be moved to the position of the game object. Obviously, this operation is meaningless. However, when the game object is the Main Camer , the Scene Camera will be placed at the position of the Main Camer . Then the content presented in the scene view will be exactly the same as the game view. In other words, if we need to view the rendering effect of the game view in the scene view, we only need to place the Scene Camera to the position of the Main Camer .

Next, we introduce the Project engineering view, as shown below

As we mentioned above, SampleScene is a scene. The scene will be saved in the form of a file in the Assets\Scenes directory of the project. The name of the file is the name of the scene, and the two are consistent. Therefore, you can see a " SampleScene.unity " scene file in the Assets\Scenes directory. We can also see this file in the engineering view ( Project ), as shown below

We can see that the project view includes three parts: Favorites , Assets and Packages . Favorites are mainly used for search, we don't need it for the time being. Assets is the most important, it is consistent with the Assets directory under our project save path. All scripts, materials, models, etc. we create are placed in the Assets directory. Packages are some resource packages needed for game development. This is a great help to us. This is the same as the third-party libraries we use in daily development of applications. Unity official will also provide us with some resource packages to assist us in game development. We can open the resource package manager through Window -> Packages Manager to manage these resource packages uniformly.

Finally, let's introduce the Inspector . This view is not a fixed content, it will dynamically display all the properties of the game based on the game object you click to select. We can select game objects in the hierarchy view or in the scene view. The following is what the inspection view displays after we select the main camera

The top shows the name of the game object, as well as the tag ( Tag ) and the layer it belongs to ( Layer ) and so on.

Each game object has its own name, through which we can easily identify and manage it. At the same time, each game object has an activation status and a check mark next to the game object name. By default, game objects are all activated, that is, automatically checked. When a game object is set to an inactive state (unchecked), the game object will be hidden (that is, unusable) in the scene view and game view. The activation status of the game object can be checked and set through the checkbox to the left of the name, or it can be controlled through C# scripts.

Next, a brief introduction to labels and layers. In a role-playing game, you can add an enemy tag to the monster and a player tag to the protagonist , but both are set to role layers . We use tags to find game objects in a specific range; and through layers, we can set whether game objects belonging to a certain layer will generate collision detection with game objects of other layers, and whether the game objects of this layer need to be rendered, etc. Logical operations. Tags and graphics can understand the classification of game objects. Tag classification is mainly used for game object selection, etc. Layer classification is mainly used for collision and rendering, etc. We will introduce the use of more labels and layers in future cases.

Next, we briefly introduce the properties in the main camera inspection panel, which can be modified. We can see that the main camera has four attribute categories: Transform , Camera , Audio Listener , and New Behavior Script , which we call components. We see that there is an " Add Component " button at the bottom, which means adding other components. Each component can be understood as a different function. Adding different components to a game object will make the game object have different functions. Unity provides many components to help us develop games. Among them, Transform represents the position of the game object in the game world, Camera is the camera, Audio Listener is related to playing sound, and New Behavior Script is a C# script we created in the previous chapter . Please note that the C# script file we created is also a component, and it must be assigned to the game object to run. Components are important knowledge that must be mastered in Unity development. In addition to mastering the officially provided components, we also need to be able to write our own C# script components.

Guess you like

Origin blog.csdn.net/konkon2012/article/details/130380246