找回密码
 立即注册
楼主: ruizi

[脚本] Animation的常见属性及方法

[复制链接]
发表于 2013-2-27 09:19 | 显示全部楼层 |阅读模式
Animation.Play播放
  1. function Play (mode : PlayMode = PlayMode.StopSameLayer) : bool
  2. function Play (animation : string, mode : PlayMode = PlayMode.StopSameLayer) : bool
复制代码
Play()将开始播放名称为animation的动画,或者播放默认动画。动画会突然开始播放而没有任何混合。
如果模式是PlayMode.StopSameLayer,那么所有在同一个层的动画将停止播放。如果模式是PlayMode.StopAll,那么所有当前在播放的动画将停止播放。
如果动画已经在播放过程中,别的动画将停止但是动画不会回退到开始位置。
如果动画没有被设置成循环模式,它将停止并且回退到开始位置。
如果动画不能被播放(没有动画剪辑或者没有默认动画),Play()将返回false。
  1. // 播放默认动画。
  2. animation.Play();

  3. // Plays the walk animation - stops all other animations in the same layer
  4. // 播放walk动画 - 停止同一层的其他动画。
  5. animation.Play("walk");
  6. // Plays the walk animation - stops all other animations
  7. // 播放walk动画 - 停止其他动画。
  8. animation.Play("walk", PlayMode.StopAll);
复制代码
Animation.CrossFade淡入淡出
  1. function CrossFade (animation : string, fadeLength : float = 0.3F, mode : PlayMode = PlayMode.StopSameLayer) : void
复制代码
在一定时间内淡入名称为name的动画并且淡出其他动画。
如果模式是PlayMode.StopSameLayer,在同一层的动画将在动画淡入的时候淡出。如果模式是PlayMode.StopAll,所有动画将在淡入的时候淡出。
如果动画没有被设置成循环,它将停止并且在播放完成之后倒带至开始。
  1. // Fade the walk cycle in and fade all other animations in the same layer out.
  2. // 淡入walk循环并且淡出同一层的所有其他动画。
  3. // Complete the fade within 0.2 seconds.
  4. // 在0.2秒之内完成淡入淡出。
  5. animation.CrossFade("Walk", 0.2);
复制代码
  1. // Makes a character contains a Run and Idle animation
  2. // fade between them when the player wants to move
  3. // 让一个角色包含Run和Idle动画,并且在玩家想移动的时候在他们之间淡入淡出。
  4. function Update () {
  5.         if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
  6.                 animation.CrossFade("Run");
  7.         else
  8.                 animation.CrossFade("Idle");
  9. }
复制代码
Animation.Sample采样
  1. function Sample () : void
  2. 在当前状态对动画进行采样。
  3. 当你明确想设置一些动画状态并且对它取样一次的时候有用。
  4. // Set up some state;
  5. // 设置一些状态;
  6. animation["MyClip"].time = 2.0;
  7. animation["MyClip"].enabled = true;
  8. // Sample animations now.
  9. // 取样动画。
  10. animation.Sample();

  11. animation["MyClip"].enabled = false;
复制代码
Animation.Stop 停止
  1. function Stop () : void
复制代码
  1. // Stop all animations
  2. //停止所有动画。
  3. animation.Stop();
复制代码
Animation.this[string name]操作名字

  1. var this[name : string] : AnimationState
复制代码
  1. // Get the walk animation state and set its speed
  2. // 取得walk动画状态并设置其速度。
  3. animation["walk"].speed = 2.0;

  4. // Get the run animation state and set its weight
  5. // 取得run动画状态并设置其重量。
  6. animation["run"].weight = 0.5;
复制代码
Animation.wrapMode循环模式
动画剪辑播放完成之后,应该如何操作?

WrapMode.Default:从动画剪辑中读取循环模式(默认是Once)。
WrapMode.Once:当时间播放到末尾的时候停止动画的播放。
WrapMode.Loop:当时间播放到末尾的时候重新播放从开始播放。
WrapMode.ClampForever:播放动画。当播放到结尾的时候,动画总是处于最后一帧的采样状态。
  1. //Make the animation loop
  2. //使用动画循环模式。
  3. animation.wrapMode = WrapMode.Loop;
复制代码
发表于 2013-4-6 21:20 | 显示全部楼层
{:5_408:}{:5_408:}{:5_408:}
发表于 2013-8-5 16:27 | 显示全部楼层
{:5_424:}{:5_424:}{:5_424:}{:5_424:}{:5_424:}
发表于 2017-2-21 11:38 | 显示全部楼层
楼主是超人
发表于 2017-2-21 11:36 | 显示全部楼层
好帖就是要顶
发表于 2017-2-21 11:21 | 显示全部楼层
难得一见的好帖
发表于 2017-2-21 11:58 | 显示全部楼层
说的非常好
发表于 2017-2-21 11:24 | 显示全部楼层
不错不错
发表于 2017-4-17 08:02 | 显示全部楼层
很不错
发表于 2017-4-17 08:10 | 显示全部楼层
好帖就是要顶
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-3 14:03 , Processed in 0.090662 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表