por Mike Ton hace 10 años
1628
Ver más
class
public
MecanimControl : MonoBehaviour
var
private
state2Hash
state1Hash
RuntimeAnimatorController
overrideController.runtimeAnimatorController =
(targetAnimationData.speed >0)
controller3
controller1
(targetAnimationData.speed > 0)
else
controller4
controller2
Resources.Load("controller1");
MUST EXIST IN RESOURCE FOLDER!!
//Runtime reprentation of the AnimationController. It can be used to change the Animator's AnimationSource during runtime.
//This class is deprecated, RuntimeAnimationController should be used.
Animator
Namespace: UnityEngine
Parent class: Behaviour
Description
Interface to control the Mecanim animation system.
Variables
animatePhysics When turned on, animations will be executed in the physics loop. This is only useful in conjunction with kinematic rigidbodies.
applyRootMotion Should root motion be applied?
avatar Gets/Sets the current Avatar.
bodyPosition The position of the body center of mass.
bodyRotation The rotation of the body center of mass.
cullingMode Controls culling of this Animator component.
deltaPosition Gets the avatar delta position for the last evaluated frame.
deltaRotation Gets the avatar delta rotation for the last evaluated frame.
feetPivotActive Blends pivot point between body center of mass and feet pivot. At 0%, the blending point is body center of mass. At 100%, the blending point is feet pivot.
gravityWeight The current gravity weight based on current animations that are played.
humanScale Returns the scale of the current Avatar for a humanoid rig, (1 by default if the rig is generic).
isHuman Returns true if the current rig is humanoid, false if it is generic.
isMatchingTarget If automatic matching is active.
layerCount The AnimatorController layer count.
leftFeetBottomHeight Get left foot bottom height.
pivotPosition Get the current position of the pivot.
pivotWeight Gets the pivot weight.
playbackTime Sets the playback position in the recording buffer.
recorderStartTime Start time of the first frame of the buffer relative to the frame at which StartRecording was called.
recorderStopTime End time of the recorded clip relative to when StartRecording was called.
rightFeetBottomHeight Get right foot bottom height.
rootPosition The root position, the position of the game object.
rootRotation The root rotation, the rotation of the game object.
runtimeAnimatorController The runtime representation of AnimatorController that controls the Animator.
speed The playback speed of the Animator. 1 is normal playback speed.
stabilizeFeet Automatic stabilization of feet during transition and blending.
targetPosition Returns the position of the target specified by SetTarget(AvatarTarget targetIndex, float targetNormalizedTime)).
targetRotation Returns the rotation of the target specified by SetTarget(AvatarTarget targetIndex, float targetNormalizedTime)).
Functions
CrossFade Create a dynamic transition between the current state and the destination state.
GetAnimatorTransitionInfo Gets the Transition information on a specified AnimatorController layer.
GetBoneTransform Returns transform mapped to this human bone id.
GetBool Gets the value of a bool parameter.
GetCurrentAnimationClipState Gets the list of AnimationInfo currently played by the current state.
GetCurrentAnimatorStateInfo Gets the current State information on a specified AnimatorController layer.
GetFloat Gets the value of a float parameter.
GetIKPosition Gets the position of an IK goal.
GetIKPositionWeight Gets the translative weight of an IK goal (0 = at the original animation before IK, 1 = at the goal).
GetIKRotation Gets the rotation of an IK goal.
GetIKRotationWeight Gets the rotational weight of an IK goal (0 = rotation before IK, 1 = rotation at the IK goal).
GetInteger Gets the value of an integer parameter.
GetLayerName Gets name of the layer.
GetLayerWeight Gets the layer's current weight.
GetNextAnimationClipState Gets the list of AnimationInfo currently played by the next state.
GetNextAnimatorStateInfo Gets the next State information on a specified AnimatorController layer.
InterruptMatchTarget Interrupts the automatic target matching.
IsInTransition Is the specified AnimatorController layer in a transition.
IsParameterControlledByCurve Returns true if a parameter is controlled by an additional curve on an animation.
MatchTarget Automatically adjust the gameobject position and rotation so that the AvatarTarget reaches the matchPosition when the current state is at the specified progress.
Play Plays a state.
SetBool Sets the value of a bool parameter.
SetFloat Sets the value of a float parameter.
SetIKPosition Sets the position of an IK goal.
SetIKPositionWeight Sets the translative weight of an IK goal (0 = at the original animation before IK, 1 = at the goal).
SetIKRotation Sets the rotation of an IK goal.
SetIKRotationWeight Sets the rotational weight of an IK goal (0 = rotation before IK, 1 = rotation at the IK goal).
SetInteger Sets the value of an integer parameter.
SetLayerWeight Sets the layer's current weight.
SetLookAtPosition Sets the look at position.
SetLookAtWeight Set look at weights.
SetTarget Sets an AvatarTarget and a targetNormalizedTime for the current state.
SetTrigger Sets a trigger parameter to active or inactive.
StartPlayback Sets the animator in playback mode.
StartRecording Sets the animator in recording mode, and allocates a circular buffer of size frameCount.
StopPlayback Stops the animator playback mode. When playback stops, the avatar resumes getting control from game logic.
StopRecording Stops animator record mode.
Static Functions
StringToHash Generates an parameter id from a string.
animator
//Interface to control the Mecanim animation system.
currentAnimationData
static
public static event AnimEvent OnAnimationLoop;
public static event AnimEvent OnAnimationEnd;
public static event AnimEvent OnAnimationBegin;
delegate
public delegate void AnimEvent(AnimationData animationData);
WrapMode defaultWrapMode = WrapMode.Loop;
float defaultTransitionDuration = 0.15f;
AnimationData[] animations = new AnimationData[0];
AnimationData defaultAnimation = new AnimationData();
AnimationData
[HideInInspector]
int stateHash;
int timesPlayed = 0;
WrapMode wrapMode;
float transitionDuration = -1;
float speed = 1;
string clipName;
AnimationClip clip;
Editor
Animations[]
Defaults
DefaultWrapMode
DefaultTransitionDuration
0.15
Size
6
DefaultAnimation
-1 == Default
WrapMode
TransitionDuration
ClipName
anim params
blend trees
i/o -> state machines
animation clips
retargeting not possible
creatures, animated props, four-legged animals,
extended GUI support and retargeting
Muscle
config
FBX
path to bones need to match up to share animation
Maya
can replace animation curve.
defaults to 0.01 scale
maya file defaults to 1.0 scale
must match if using cross file format!
BlendTrees
Finite State Machine?
Human Template?
interruption improvements
based on destination state + start/destination
not just start
multiweight
roll
Clear up
re-order
array
parameter to control them
1 frame animatoin
move
script for sprite logic
data
Side
Up
takes animClip absolute to additive for root ???
Statemachine can be used for logic
enter/exit node
enter
random idle(5)
exit
Animation
Clips
Events
Function
one only
obj
string
int
"playStep"
AnimEvent.cs
void playStep(){ print("I am stepping."); }
must be attached to same Game Object as Animator
Directly create/edit curve feed to Animator Parameters to allow access by script
Prev
Had to query frame count
NOTE: must Enable Use Curve on GameObject
Transform
Determines which curves to ignore
Check when objects are not moving.
EX : Tail
limbs
torso, head, arms, legs, base...etch
IK points
Create from this mode
Copy From other mask
RootMotion
Loop
Pose
Time
Root Transform
Types
Root Transform Position (XZ)
Root Transform Position (Y)
manually adjust the AnimationClip height using the Offset setting
Note: the Animator.gravityWeight is driven by Bake Into Pose position Y. When enabled, gravityWeight = 1, when disable = 0. gravityWeight is blended for clips when transitioning between states.
Most of the AnimationClips will enable this setting. Only clips that will change the GameObject height should have this turned off, like jump up or down.
Y component of the motion will stay on the Body Transform (Pose)
This means that this clip won't change the Game Object Height
The Y component of the Root Transform will be constant and Delta Root Position Y will be 0
Feet
Thus the blending point always remains around the feet which prevents floating problem when blending or transitioning.
When using Feet the Root Transform Position Y will match the lowest foot Y for all frames
Center of Mass
Root Transform Rotation
Option
Offset
Baked Into Pose
Only AnimationClips that have similar start and stop Root Orientation should use this option (walks/run)
This means the the Game Object will not be rotated at all by that AnimationClip.
The Root Orientation will be constant and delta Orientation will be identity
The orientation will stay on the body transform (or Pose)
Based Upon
the orientation of the clip
Original
automatically add the authored offset found in the imported clip
It is usually used with Keyframed data to respect orientation that was set by the artist.
clip will be oriented to follow the forward vector of body
This default setting works well for most Motion Capture (Mocap) data like walks, runs, and jumps, but it will fail with motion like strafing where the motion is perpendicular to the body's forward vector. In those cases you can manually adjust the orientation using the Offset setting
a projection on the Y plane of the Body Transform and is computed at runtime
This change in transform is then applied to the Game Object to make it move
At every frame, a change in the Root Transform is computed
Body Transform
Body Transform and Orientation are stored in the Animation Clip (using the Muscle definitions set up in the Avatar)
Body Orientation
average of the lower and upper body orientation relative to the Avatar T-Pose
mass center of the character
They are the only world-space curves stored in the Animation Clip. Everything else: muscle curves and IK goals (Hands and Feet) are stored relative to the body transform
Mecanim's retargeting engine and provides the most stable displacement model
Anim.Compression
Error
Scale
Position
Rotation
Mode
Optimal
Reduction and Compression ?
Messes up Tyler's parent constraint animation???
KeyFrame Reduction
Off
Range
Note : Negative Frames can cause issues when optimizing/key reducing
Transform Mask
Blend Tree Layer
source import
Rig
Generation
Legacy
Don't Import
(Deprecated)
Store in Original Nodes
Store in Nodes
(New)
Store in Root
Optimize GameObject
Extra Transform to Expose
Displays Selected Transform or Bone.
EX : weapon attachment point
internally hides Avatar and transforms
Definition
Create From This Model
Avatar can be configured after settings are applied
Copy From Other Avatar
Use an existing Avatar and only import animations
(Avatar)
Tpose
Else
Based on Skin Pose???
feet must be on floor
enforce Tpose cmd does this
Model
ScaleFactor
Maya == 1.0
FBX == 0.01
Based On Renders
Always Animate
Handled by Script
rootmotion.cs
void OnAnimatorMove(){ ... }
transform.position = newPosition;
newPosition.z += animator.GetFloat("rootSpeedWalk") * Time.deltaTime
Vector3 newPosition = transform.position ;
Animator animator = GetComponent
[RequireComponent(typeof(Animator))]
Animator Controller
Parameters
Floats
Curves
From Animation Clip
"rootSpeedWalk"
//global for all layers
Trigger
Like Bool, but reverts to back to true after triggered
Bool
HoldingPickup
HoldingPushable
State Machine
States
NOTE:
If clips are from mixxed rigs; no animation will run
ex : Idle == Humanoid, crouch==Generic
var
Transitions
Conditions
Atomic
false == interruptable
true == not interruptable
Path
Layer.StateThis ==> Layer.StateTarget
Arms.Nothing ==> Arms.Hold
Default == Nothing->State
Motion == None Clip
Layer with arms masked
Base.Idle ==> Base.Walk
Mute
Solo
Motion
Mirror
Foot IK
//Should Foot IK be respected for this state
Clip
idle
Prop
Tag
"idle"
type
Any
Anonymous Starting Point
//Cannot be the end point of a transition (ie, jumping to "any state" cannot be used as a way to pick a random state to enter next
//Always present. It exists for the situation where you want to go to a specific state regardless of which state you are currently in. This is a shorthand way of adding the same outward transition to all states in your machine
Default
//state that the machine will be in when it is first activated
Layers
Blend Trees
Type
Direct
2D
Freeform Cartesian
//not mapped to direction
Freeform Directional
//complex dir : walk forward => run forward, walk left => run left ...etc
Simple Directional
//simple dir : walk forward, walk left, walk right
1D
Motions
(config)
Automate thresholds
false
enum
Compute threshold
Angular Speed
Degree
Rad
Velocity
Z
Y
X
Speed
???
true
(animClip)
prop
bool
mirror
float
animation speed
threshold
Arms
Mask
Transforms
Weight
Blending
Additive
Override
Name
"Arms"
Base
private Animator anim;
void
Update(){ ... }
anim.SetFloat("Direction", horizontal, 0.15f, Time.deltaTime);
anim.SetFloat("Speed", vertical, 0.15f, Time.deltaTime);
float vertical = Input.GetAxis("Vertical");
float horizontal = Input.GetAxis("Horizontal");
Awake(){ ... }
anim = this.transform.GetComponent
//link between character and in game property/state update
setup
Generic
Humanoid
Muscle config
Body Mask
used to enable/disable specific body part
used
import inspector
Animation Layer
source skeleton stucture-> Mecanim bone structure
mapping
bones to Mecanim transforms