Summary of the latest two years of work experience

Summary of the latest two years of work experience

Preface

The company's profits are not good, the entire team has been laid off, and N+1 compensation has been given. It's okay. After a month or two of rest, I will summarize the work experience of the past two years. This blog technology will not be recorded like the previous documents. It is very detailed (the previous document has a gif screen recording to implement the corresponding operation), and many places will only briefly mention it. After all, it is most convenient to check the document when it is actually used.

Usage of URP

1: How to enable URP

1. Upgrade old projects to URP

Just search it on Baidu. I won’t go into details here. I’ll attach a random link
and upgrade the old project to URP.

2. Select URP creation when creating a new project

If not, it may be that the version does not support it.
If your project does not have this item, it may be that the version does not support it yet.

2: Settings of URP shadow

Insert image description here
As shown in the picture, find the URP settings file in the project file, click it, and then change the shadows in the properties panel.

Use of PolyBrush (map editing plug-in)

Make peaks or valleys

Insert image description here
Hold down the left button and slide on the map to form a mountain peak, and Ctrl + left button to create a trough.

edge softening

Insert image description here

Color wipers

Insert image description here
Fill or other modes can be selected

Create objects in the scene

Insert image description here
Just drag the prefab into the Current Palette

Map terrain creation

Insert image description here

Easy to get into trouble

After drawing the map, be sure to uncheck ProlBrush, otherwise objects cannot be selected in the scene.
Insert image description here

ProBuilder (map editing plug-in)

Thoughts

As we all know, the map part should be left entirely to the artist, but China has too many people. If you don’t do it, there will be people doing it, and it will become more and more complicated. Small and medium-sized companies do not have specific map editors, so they can only leave it to the developers themselves. , I had to learn some map editing plug-ins.
Insert image description here

Instructions

Probulider can create a multi-vertex ground. If you change the Scale directly, it will only change the size but not the number of vertices. In addition: the vertices created by Probulider are not in the center. You can choose to select the object and click on the rightmost icon in the middle.

ProGrids plug-in (auxiliary reference lines, generally not used, and may trigger bugs)

Insert image description here
Before using it, you need to check an attribute in the Rproject Setting in Edit, as shown in the picture above.
Insert image description here
ProGrids can implement auxiliary reference lines, objects in the scene move according to the set units, etc. I personally don’t like to use it very much.

Automatic navigationNavigation

Stationary non-interactive (passable) objects

Set the immobile objects in the scene to Navigation Static, and then set whether they can be moved in the Navigation property panel.
Insert image description here

Objects that move but cannot be interacted with (pass through)

NavMeshObstacle needs to be used in places where the scene will move and the protagonist cannot pass. Just check the Carve attribute.
Insert image description here

Parameter settings for the main clause

Insert image description here
Insert image description here
Add the NavMeshAgent component to the protagonist. Parameters such as height and width must correspond to the Agent attribute parameters in Navigation, otherwise bugs may occur.

Use of Camera from multiple perspectives

Camera locking angle of view following (implemented in various ways)

The first way: write a Cinema management class

The first method is more time-consuming, which is to write a Cinema management class yourself to achieve the functions you want.

Second way: use Cinemachine plug-in

Search Cinemachine in the unity body and import it directly.
Then there will be one more menu bar,
Insert image description here
select CreateVirtualCinema.
Drag the object you want to follow into follow.
Insert image description here

Then adjust the desired angle, and then press Ctrl+Shift+F to quickly lock it. (It may conflict with other shortcut keys, you can select Align With View in the GameObject menu bar)

Camera free perspective (third person)

The first way: write the script yourself

Second way: use Cinemachine plug-in

Create a FreeLookCamera in the Cinemachine menu bar in the Unity panel. Set the relevant parameters according to your own preferences as shown in the figure.
Follow is the same as the locked perspective above. I will not go into too much detail here.
Axis Control controls the movement of the perspective. Fill in the Project Settings on the left and right lines. >The value of Input Manager
in Binding Mode can be free or fixed to follow the player's perspective. This depends on personal needs.
Insert image description here
Insert image description here

An easy place to step into pitfalls

Shortcut key conflict

Ctrl+Shift+F may conflict with other shortcut keys, especially when multiple software are open, Unity's shortcut keys have low priority. Align With View can be selected in the GameObject menu bar.

Different monster perspectives look high and low

There is a problem with the resources provided by the art (the process of small and medium-sized companies is not standardized or the art does not pay attention when working), and the central store is at the foot, which leads to a strange viewing angle. Create an empty object inside the game object, and then observe the empty object.
Insert image description here

fog

Confidently set it in the Environment panel of the Lighting property bar. I won’t go into details here (programmers don’t have artistic ideas, so leave it to professionals)
Insert image description here

Post-processing

Right-click in the Hierarchy panel to create various volumes and debug them yourself. The reason is the same as above. Programmers have no artistic skills. A bunch of parameters to adjust to your liking.
Insert image description here

animation control

The Animator control used will be discussed in detail later. At present, it is only controlled by a Speed ​​floating point number.
Insert image description here

The protagonist's mobile attack (using coroutines)

When the player clicks on the monster, he needs to do two steps:
1: Determine the distance to the monster (try not to write it in Update, otherwise it may be confused with the movement logic, so you need to use Ctrip)
2: The distance is enough Just attack the monster
Insert image description here

Switching of multiple sets of action modules for the protagonist (different attack actions under different weapons)

Create an Animator Override Controller component to replace the attack animation that needs to be changed.
Drag the original Animator Controller component to it.
Insert image description here

Monster AI (using state machines)

state machine

The so-called state machine is to set several regular states for monsters and encapsulate the corresponding methods, such as stationary, patrolling, attacking, etc. Do corresponding things for each state. Generally, you constantly determine what state the current state is in Update, and then do things corresponding to the state.

Animation layer layering

Using multiple layers can avoid the spider web situation (the states are all lines, and switching between them is very messy). The parameters are set as follows.
Insert image description here
Base Layer serves as the basic layer and controls the most basic idel and walk.
Insert image description here

Attack Layer controls attack-related animations. When the attack animation ends, it returns to an empty state (BaseState is an empty state created without animation), and the BaseLayer layer will not be covered at this time.
Insert image description here

You can also use the Behavior Tree plugin

Refer to this article I wrote

material falling

Normally, materials will be exploded when fighting monsters, usually with a trigger. When the player touches the material, he picks it up and puts it into his backpack. However, there is a situation at this time that the material hits the player before it falls to the ground. The player may did not see. Therefore double collider can be used.
Collider A is responsible for triggering with the ground (usually with a delay of one second, so that players can see what equipment or materials have exploded). When triggered, collider B is activated and is responsible for colliding with the player.

animation event

Right click in the Animation panel to add.
Events are generally not calculated using physical methods, such as calculating time. Animation events are generally used.
Insert image description here

animation state machine

Similar to the Awake and Update methods in MonoBehavior, you can control the current animation to do what you want to do.
Insert image description here
For example, you cannot move while being stunned.
Insert image description here

Project examples

The Minotaur BOSS will kick players hard at close range. Stones will be thrown at players from a distance, and the stones can knock back players. Players can attack the stone and bounce it back to the Minotaur to cause damage to the Minotaur (a bit like the phaseless ice in Genshin Impact).

How to achieve kicking:

Add an animation event. When the animation reaches the kicking frame, get the player, call the player's animation controller, and enter the dizzy state. At the same time, add animation state machine control and call the Api in the above picture.
If you want to be more detailed, for example, the player has already run away when kicking, you can add some judgments at this time. However, the legendary game I am doing is just a numerical competition in itself, so I will not add it here.

Throwing a stone will knock back the player or knock the stone away, causing damage to the stone man:

First, create a stone prefab. At the frame when the minotaur raises his hand, create the stone. The stone class has a state machine. It is initially AttackPlayer. When it encounters a player or other things, it becomes AttackNothing. When it is attacked by a player, it becomes AttackBoss.
The stone and the player each have a rigid body. When the boss throws it at the player, it gives him a force to fly towards the player, calls the collision method of the rigid body, gets the relevant parameters of the player, and then operates on the player. Vice versa, the player attacks the stone on the ground and gives it a force in the player's current direction. When encountering the boss, the collision method of the rigid body is also called to obtain the boss-related parameters for operation.
After the stone hits the boss, you can use the particle system to add a shattering effect, which will not be discussed here.

Kick the player unconscious

important point

Parameters are case-sensitive, so be careful!

Occlusion culling

Write Shader Graph

In actual projects, the player character can easily run behind obstacles. At this time, we also want the player to display it, such as an outline. At this time, we can write a simple Shader Graph.
1. Create a Shader (Urp shader) in the Project panel
2. Create a Node in the shader panel, select Fresnel Effect, and then drag the out node to derive a Multiply, which can be assigned a color equivalent value
Insert image description here
3. Select the right side of the shader Click to create a material, and the properties can be changed in the material property bar, as shown in the figure.
Insert image description here
4. Modify the layer layer in the Urp Render settings, modify the material, and check the depth (depth)
DepthTest and select Greater Equal (forgot to mark it on the picture)
Insert image description here
5. Unblocked The situation must also be set
Insert image description here

UI related

How to use the Canvas panel

Canvas has two commonly used modes, one is World Space, which puts the UI into the game world.
One is Screen Space, where the UI panel covers the entire screen.

Monster health bar

In the actual scene, the health bar must always follow the monster, so we need to use World Space mode, add a health bar coordinate to each monster prefab, and then update the UI position of the health bar in real time.
Insert image description here

Player's health bar

This is using Screen Space. Regular settings use this mode.

Canvas Group

You can control whether the UI is interactive, blocking rays, and changing the alpha value.

backpack system

There is nothing much to say about the regular creation of a backpack. This is just to get the backpack data and create it one by one. Mainly talk about the item drag function.

Backpack item click function

Implementation method 1: The backpack Item itself contains a Button and calls the button OnClick event.

Implementation method 2: Backpack Item inherits the IPointerClickHandler interface

Insert image description here

Item drag function

First of all, we need to inherit the drag-and-drop function interface provided by unity, as follows:
Let’s make a complaint: I didn’t know about this excuse before. They all inherited the Onenter, long press and other interfaces, so I need to encapsulate it one more layer.
Insert image description here
After EndDrag ends dragging, determine the current position, and then swap the two backpack items in the backpack.

Judgment method 1: Use rays to judge.

Insert image description here
This method can determine the object detected by the ray at the end and whether it is a backpack grid, thereby completing the exchange.
If you want to throw it into the game world, if you do not touch the UI at this time, a Null value will be returned. Just convert the ray coordinates at this time into world coordinates (the Z axis is the negative value of the camera Z axis) and generate the corresponding Just game objects. (Legendary games are usually thrown directly at the player’s feet)

Judgment method 2: Use EventSystem.IsPointerOverGameObject. First determine whether to interact with the UI.

Insert image description here
Then it determines whether it is on the specified UI and calls the API under the picture.
Insert image description here
It should be noted that during the dragging process, the levels between different UIs may be blocked. For example, the thing you drag is generated first and you want to throw it behind. At this time, you need to change its parent object and drag it. Change it back when you're done.

Dynamic display of character information panel

Everyone who has played legendary games knows that when you open the character panel, the characters are moving, which looks very delicate, but this function is actually very easy to implement.
You need a RawImage, a RenderTexture (the same size as the RawImage), and a Camera facing the player.
Then assign RenderTexture to Camera, change the layer to only render the player, and then assign RenderTexture to RawImage.
Do not display the background, change the background type to color, and set the alpha value to 0
Insert image description here

Insert image description here

UI adaptation common components

Method 1: Write your own code to control

The disadvantage of writing code control yourself is that it is more cumbersome. The advantage is that you know where to fix problems when they occur. Using the plug-in provided by Unity is sometimes troublesome to troubleshoot problems.

Method 2: Use the Layout Group component and Content SizeFitter provided by unity

The Layout Group component is used in conjunction with the Content SizeFitter, which can be perfectly adapted to most scenarios, such as controlling the size of the player's chat box.
Disadvantage: The UI is not updated in real time, and sometimes it is necessary to call the API to refresh the canvas immediately.

ScriptableObject

Used to manage data, there are many components hanging on the role, and ScriptableObject is specially used to handle data related.
This data can be serialized and converted to string for temporary storage when switching scenes.

Guess you like

Origin blog.csdn.net/qq_40629631/article/details/132300351