Unity -- Animation (old animation component) and Animator (new animation component)

Legacy animation animator component

If we want a game object to have animation performance, we need to mount animation components to this game object

Like audio components and video components, if we want to play animation effects on game objects, we need to mount an animation component, and then pass an animation clip for playback to this animation component (all animation files we pass are an animation fragment)

Then we can also pass multiple animation clips to the animation component to play, so that our game objects can have multiple animation performances

When transferring multiple animation clips, they should be passed to the Animations list, and then each animation clip will have an index (the index starts from 0)

Culling Type: Culling method

If we choose to always animate, it will continue to execute after the animation is played

If we choose base on renders, the animation will play animation based on rendering, that is to say, only the rendered game object will be played animation, if the game object is not rendered, the animation will not be played

(So ​​how to judge whether it has been rendered? --- It is very simple that the game objects captured by the camera will be rendered, and the objects not captured by the camera will not be rendered)


In addition to importing completed animation clips from the outside world, we can also make animations ourselves in Unity:

1. Click on the window, select Animation, and then select Animation in the new list, and then we can get the following animation production panel:

 We can drag this production panel to the game screen to form another window

This means that let us create an animation clip file to store the animation we created in the animation creation window. After creating the animation file, we choose to add attributes in the animation maker box (the animation we want to make is by modifying the attributes parameter value and then make the game object move to get the animation clip)

 

This panel is the number of playback frames of the animation, here the default is 1s60 frames, we can adjust the number of frames by dragging the end frame on the right (the one on the left is the starting frame, which is fixed) 

Here we can make a simple moving animation:

First, the coordinates of the game object at the start frame are (0, 0, 0), and the coordinates of the game object at the end frame are (10, 0, 0) - this is a position change, and then the animator will automatically help us The action generated from (0, 0, 0) to (10, 0, 0) has changed --- note that here only simulates a simple animation on the line between the start point and the end point

 Then we can also add a key frame between the start frame and the end frame -- drag the line to the position where we want to add a key frame and select the middle one of the three below to add a key frame (the key frame is a transition frame , let’s talk about this knowledge later, now it can be simply understood that we have set a transition slowdown frame here)

 

 Key point: How to play animation through code?

1. Create a script and mount it on the game object with the animation player component

2. Create an animation player variable to take over the animation player component

3. Call the play() method through the animation player variable, and the animation will be played at this time

Of course, you can also call the play method directly through the obtained component

 If you do not pass parameters to the play method, the animation player will play the default animation clip. If you pass parameters, you must pass the file name of the animation clip file we want to play (in the form of a string, and the clip has been added to the component. )


New version of the Animator component

 From top to bottom are: controller, avatar, apply root motion, update mode (Normal is normal), culling mode (always animated in brackets)

1. When using the above, we first need to create an animator controller (animator controller) file (all our animations and animation playback are adjusted and controlled in the animation controller)

2. After creation, we can drag the animator controller file to the controller in the animator component

3. Unity will automatically place all animation clips in the animator controller

 It is these boxes that represent animation clips in the animator controller (all boxes except the three default boxes of Entry, any state, and end), and these boxes are also called animation states

Each animation state contains an animation file and some settings related to the animation

When we right click on an animation state, these options will appear

state: transition, blendTree mixed number, state machine state machine, sub-state machine sub state machine

 

When our animation starts running, it will first enter from the entry animation state, and then execute the first animation state connected to the entry

 

This connection can be changed. We select the animation to be played, then click the right mouse button, and then select Set as the default state of the layer, and the line will connect to the animation state we selected.

Then! The animation playback managed by this animator controller can also be controlled by scripts

The previous steps are the same as the animation component above, so I won’t repeat them here.

 But if you use code to control the switch, it is a direct switch, which is a way to skip the animation manager

But in fact, the animator manager has its own set of switching methods. This switching method is called transition, which will be discussed later

Guess you like

Origin blog.csdn.net/qq_51947882/article/details/126530648