Unity3D中Animation的常见属性及方法

来源:互联网 发布:java date json 编辑:程序博客网 时间:2024/05/05 08:43

Unity3D中Animation的常见属性及方法如下:

Animation.Play播放

function Play (mode : PlayMode = PlayMode.StopSameLayer) : bool
function Play (animation : string, mode : PlayMode = PlayMode.StopSameLayer) : bool

Play()将开始播放名称为animation的动画,或者播放默认动画。动画会突然开始播放而没有任何混合。如果模式是PlayMode.StopSameLayer,那么所有在同一个层的动画将停止播放。如果模式是PlayMode.StopAll,那么所有当前在播放的动画将停止播放。

如果动画已经在播放过程中,别的动画将停止但是动画不会回退到开始位置。

如果动画没有被设置成循环模式,它将停止并且回退到开始位置。

如果动画不能被播放(没有动画剪辑或者没有默认动画),Play()将返回false。

// 播放默认动画。
animation.Play();// Plays the walk animation - stops all other animations in the same layer
// 播放walk动画 - 停止同一层的其他动画。
animation.Play("walk");
// Plays the walk animation - stops all other animations
// 播放walk动画 - 停止其他动画。
animation.Play("walk", PlayMode.StopAll);

Animation.CrossFade淡入淡出

function CrossFade (animation : string, fadeLength : float = 0.3F, mode : PlayMode = PlayMode.StopSameLayer) : void

在一定时间内淡入名称为name的动画并且淡出其他动画。如果模式是PlayMode.StopSameLayer,在同一层的动画将在动画淡入的时候淡出。如果模式是PlayMode.StopAll,所有动画将在淡入的时候淡出。如果动画没有被设置成循环,它将停止并且在播放完成之后倒带至开始。

// Fade the walk cycle in and fade all other animations in the same layer out.
// 淡入walk循环并且淡出同一层的所有其他动画。
// Complete the fade within 0.2 seconds.
// 在0.2秒之内完成淡入淡出。
animation.CrossFade("Walk", 0.2);
// Makes a character contains a Run and Idle animation
// fade between them when the player wants to move
// 让一个角色包含Run和Idle动画,并且在玩家想移动的时候在他们之间淡入淡出。
function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("Run");
else
animation.CrossFade("Idle");
}

Animation.Sample采样

function Sample () : void
在当前状态对动画进行采样。
当你明确想设置一些动画状态并且对它取样一次的时候有用。
// Set up some state;
// 设置一些状态;
animation["MyClip"].time = 2.0;
animation["MyClip"].enabled = true;
// Sample animations now.
// 取样动画。
animation.Sample();animation["MyClip"].enabled = false;

Animation.Stop 停止

function Stop () : void
// Stop all animations
//停止所有动画。
animation.Stop();

Animation.this[string name]操作名字

var this[name : string] : AnimationState
// Get the walk animation state and set its speed
// 取得walk动画状态并设置其速度。
animation["walk"].speed = 2.0;// Get the run animation state and set its weight
// 取得run动画状态并设置其重量。
animation["run"].weight = 0.5;

Animation.wrapMode循环模式动画剪辑播放完成之后,应该如何操作?

WrapMode.Default:从动画剪辑中读取循环模式(默认是Once)。

WrapMode.Once:当时间播放到末尾的时候停止动画的播放。

WrapMode.Loop:当时间播放到末尾的时候重新播放从开始播放。

WrapMode.ClampForever:播放动画。当播放到结尾的时候,动画总是处于最后一帧的采样状态。

//Make the animation loop
//使用动画循环模式。
animation.wrapMode = WrapMode.Loop;
0 0
原创粉丝点击