Unity3d game development Animation class and animator class

Source: Internet
Author: User

Unity3d game development Animation class and animator class


Animation class
The animation component is used to play the animation. You can assign an animated clip to an animation component and control the animation playback from the script. The animation system in unity is based on weights and supports animation blending, overlay animations, animation blending, labeling and full control of all aspects of animation playback.
If you want to play a simple animation, You can use Animation.play; if you want to cross-fade between animations, you can use Animation.crossfade, or if you want to change the animation mode (loop, once, ping-pong), you can change the animation frame's WrapMode in the animated import settings, or change it at run time Animationst The value of Ate.wrapmode; Animationstate can be used to change the animation layer, modify the playback speed, and directly control the fusion and blending. Animations also support enumerations, so you can cycle "dog planing learning nets" between animationstates like this:

// reduce the playback speed of all animations for this character by half

for (var state : animationstate in animation) {

State . speed = 0.5 ;

}


Variables variable
Clip's default animation clip.
playautomatically If the default animation is automatically played at the beginning
WrapMode what to do after the animation clip has finished playing
is isplaying playing any animations?
This [string name] returns the animation state named name.
Animatephysics If this option is turned on, the animation will be executed during the physical loop. This option is useful only when combined with a kinematic rigid body.
animateonlyifvisible If this option is turned on, unity may stop playing when it thinks the user won't see the current animation.
Cullingtype controls the blanking of animation components.
Localbounds The animation component's AABB in the local coordinate space of this animation.
Functions function
Stop stops all animations that are currently playing animation.
Rewind an animation named name.
Sample samples the animation in its current state.
IsPlaying The animation named name is playing?
Play does not have any mix of playback animations.
Crossfade fades in for a certain amount of time and fades out of other animations.
Blend blends the animation named name into the next few seconds until Targetweight
Crossfadequeued fades in and out of the next animation after the previous animation has finished playing.
Playqueued plays the next animation directly after the previous animation has finished playing.
Addclip adds an animated clip called NewName to the animation.
Removeclip Remove clips from the animation list.
Getclipcount gets the number of animated clips for the current animation.
Synclayer synchronizes the playback speed of a layer of animation.
Animator class
Mecanim animation system, through the animator component to control the animation playback, set and get the parameters in the animation.
Variable
Whether the Ishuman is a humanoid animation. The humanoid returns true. The Generic returns FALSE.
HumanScale Humanoid animation Avatar Zoom multiplier. (generic returns 1 by default)
Deltaposition the change in the position of the avatar relative to the previous frame.
Deltarotation The amount of rotation (orientation) of the avatar relative to the previous frame.
Rootposition root node (gameobject) location.
The Rootrotation root node (gameobject) faces.
The Applyrootmotion root node is controlled by animation (animations).
Animatephysics If True, the animation plays in the physical loop. Only used with kinetic rigid bodies (kinematic
rigidbodies) interaction.
Gravityweight the gravity value, depending on the animation currently playing.
Bodyposition Center of gravity position.
Bodyrotation Center of gravity direction.
Stabilizefeet Auto-align feet when animating transitions and blends
The number of LayerCount animation controller (Animatorcontroller) layers.
Feetpivotactive the axis weight of the foot. 0% is the axis at the center of gravity, and the 100% axis is at the soles.
Pivotweight axis weight value;
Pivotposition the current position of the axis.
Whether the ismatchingtarget automatically matches.
Speed playback. (1 means not scaled).
Targetposition the target point location is set by the Settarget () function.
Targetrotation the target point direction. Set by Settarget ().
Cullingmode cropping mode.
Avatar gets and sets the current avatar.
Layersaffectmasscenter additional layers, affecting the center of gravity.
Function
GetFloat gets the parameter of a floating-point type.
SetFloat sets a parameter for the type of floating-point number.
Getbool gets the parameter of a Boolean type.
Setbool sets a parameter of type Boolean.
Getinteger gets an integer-type parameter.
Setinteger sets an integer-type parameter.
Getvector gets a parameter of a vector type.
Setvector sets a parameter for a vector type.
Getquaternion gets a parameter of type four.
Setquaternion sets a parameter of type four.
Whether the Isparametercontrolledbycurve parameter is controlled by a curve.
Getikposition gets the target point position of the inverse dynamics.
Setikposition sets the target point position of the reverse dynamics.
Getikrotation gets the direction of the reverse dynamic target point.
Setikrotation sets the direction of the target point of the reverse dynamics.
Getikpositionweight Gets the inverse kinetic displacement weight. (0 indicates the original location.) 1 indicates reverse dynamics
Target location)
Setikpositionweight Sets the inverse dynamics displacement weight.
Getikrotationweight gets the inverse kinetic direction weight.
Setikrotationweight sets the inverse dynamics direction weight.
Setlookatposition set the viewing direction (z-axis positive direction).
Setlookatweight set the observation point direction weight.
Getlayername gets the name of the layer.
Getlayerweight gets the current weight of the layer.
Setlayerweight the current weight of the set layer.
Getcurrentanimatorstateinfo Gets the current status information for the current animation controller.
Getnextanimatorstateinfo gets the next state information for the current animation controller.
Getanimatortransitioninfo Gets the transformation information on the specified animation controller layer.
Getcurrentanimationclipstate Gets the status information for the current animation clip.
Getnextanimationclipstate gets the next animation clip state information.
Isintransition whether a state switch is in progress
The matchtarget automatically aligns to the target position and orientation.
Interruptmatchtarget interrupts the automatic alignment operation.
Forcestatenormalizedtime Set the normalized time (time to reach the target).
Settarget set the target location.
Iscontrolled Transform property is controlled by animator.
Getbonetransform returns the Transform property of the bone.
Animation Playback and sampling
When you create an animation of 60 frames per second in 3ds Max or Maya, it is also a 60-frame animation when imported into unity. However, when the game is running, the frame rate is not constant. The frame rate will be faster on some faster PCs, and the frame rate will be different from the complexity seen on the camera at any point given. Basically this means that we can not assume the exact frame rate when the game is running. If there is a 60-frame animation, it should be back from a different frame rate, such as 56.18 fps, or 87.61fps, can be any point.
Unity's sampling animations at different frame rates are not their true frame rates. Fortunately, the animations on 3D computer graphics are not composed of separate frames, but are continuous curves. These curves are suitable for sampling at any point, not just those points of the original frame on the timeline. This means that when the game is running, the animation will look smoother and smoother at higher frame rates.
In the case of most exercises, the fact that unity sampling animations do not have to be connected in these variable frame rates is not what you imagine. However, if you have a game logic to judge the control animation of the coordinate properties, then you have to pay attention to. For example, if you have a 30-frame animation that is to rotate an object from 0-180 degrees, you want to know when the code goes to 90 degrees when the animation is halfway through, you should not add a conditional statement to determine if the rotation of the object is now 90 degrees. Because Unity's animated samples are based on the different frame rates of the game, it's time to judge when the rotation is below 90 degrees, and it happens when you're 90 degrees. If you need to know when to specify a point in the animation, you should use Animationevent instead.
To pay attention to the causal relationship on the variable frame rate, it is impossible for a playback animation to be sampled with wrapmode.once for the exact time of a previous frame. The animation frame on the game can be sampled after the animation is played, the time on the next frame will have an extra animation length, so close will not be sampled. If you really need a previous frame of animation to do the sampling, you need to wrapmode.clampforever. This way the animation will keep the last frame sampled until you stop playing the animation.


Disclaimer: This document is from the "Dog Planing Learning Network" community, is the Netizen self-published Unity3d study articles, if there is any content violated your relevant interests, please communicate with the official, we will deal with the real-time.

Unity3d game development Animation class and animator class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.