Unity3D中Animation的常见属性及方法
2016-01-06 16:08
375 查看
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;
![](http://www.manew.com/wp-content/themes/unitymanual/images/code.jpg)
* 版权声明:转载时请以超链接形式标明文章原始出处和作者信息
* 本文来自:Unity3D 教程手册
* 本文链接: http://www.manew.com/2834.html
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;
![](http://www.manew.com/wp-content/themes/unitymanual/images/code.jpg)
* 版权声明:转载时请以超链接形式标明文章原始出处和作者信息
* 本文来自:Unity3D 教程手册
* 本文链接: http://www.manew.com/2834.html
相关文章推荐
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android中ViewFlipper的使用及设置动画效果实例详解
- jQuery实现美观的多级动画效果菜单代码
- php判断GIF图片是否为动画的方法
- jQuery实现动画效果circle实例
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- jQuery实现连续动画效果实例分析
- jQuery实现的给图片点赞+1动画效果(附在线演示及demo源码下载)
- jQuery实现带有洗牌效果的动画分页实例
- jQuery动画效果相关方法实例分析
- jquery实现先淡出再折叠收起的动画效果
- jQuery实现有动画淡出效果的二级折叠菜单代码
- jQuery使用animate创建动画用法实例
- jquery带动画效果幻灯片特效代码