unity--动画系统
发布日期:2021-05-07 17:59:12
浏览次数:15
分类:技术文章
本文共 6102 字,大约阅读时间需要 20 分钟。
分割动画
分割参数
参数 | 含义 |
---|---|
Start | 动画片段的第一帧 |
End | 动画片段的最后一帧 |
Loop Time | 是否设定该动画片段为循环动画 |
LoopPose | 是否设定该动画片段的姿势循环 |
Cycle | 为该动画片段指定一定的偏移量 |
分割动画的操作其实并不复杂,可以通过单击动画片段列表u右下角的+、-按钮来进行动画片段的增删操作,拖动动画滑杆或者修改Start和End参数可以修改该动画片段的长度。同时分割而成的动画片段会编程模型文件的子对象,如图:
动画控制器
制作一个动画角色的第一件事是为角色对象添加动画控制器
动画控制器属性
Animation | 启动自动播放(Play Automatically)时,默认播放动画 |
---|---|
Animations | 可以从脚本访问的动画列表 |
Play Automatically | 启动游戏的时候是否自动播放动画 |
– | – |
Animate Physics | 动画是否与物理交互 |
Culling Type | 设置动画的剔除模型 |
其中Culling Type 有两种类型,分别Always Animate和Based OnRenders ,前者是总是播放动画,后者是只有对象渲染在屏幕上是才播放动画。
播放动画
using System.Collections;using System.Collections.Generic;using UnityEngine;public class NewBehaviourScript : MonoBehaviour{ public Animation animation; // Start is called before the first frame update void Start() { animation = this.GetComponent(); animation.Play("run"); animation.Stop("run"); } // Update is called once per frame void Update() { }}
动画融合\动画之间平滑过渡
动画融合是确保角色平滑动画的一项重要功能,在游戏的人和时间点都有可能从一个动画转换到另一个动画,开发人员不希望两个不同的动画动作之间突然发生跳转,所以如果想要动画之间平滑过渡,需要使用CrossFade;
签名: void CrossFade(animation :striing,fadeLength:float = 0.3F,mode:PlayMode = PlayMode.StopSameLayer) 其作用是把将要播放的动画,在一定的时间内淡入,将播放完的动画淡出using System.Collections;using System.Collections.Generic;using UnityEngine;public class NewBehaviourScript : MonoBehaviour{ public Animation animation; // Start is called before the first frame update void Start() { animation = this.GetComponent(); animation.CrossFade("Walk", 0.3f); } // Update is called once per frame void Update() { }}
动画混合(局部动画)
动画混合的作用是削减游戏创建的动画数ou’l量,使某一些动画值应用给胜利的一部分,比如走路挥手,我们可以将走路的动画与一只手挥手的动画混合起来在,通过调用AddMIxingTransform方法进行动画混合变化
using System.Collections;using System.Collections.Generic;using UnityEngine;public class NewBehaviourScript : MonoBehaviour{ public AnimationClip wave_hand;//挥手动画片段 private Transform shoulder;//定义混合transfor // Start is called before the first frame update void Start() { GetComponent()[wave_hand.name].AddMixingTransform(shoulder);//将wave_hand动画添加到shoulder上 Transform mixTransform = transform.Find("root / upper_body / left_shoulder");//用路径增加一个混合transform GetComponent ()[wave_hand.name].AddMixingTransform(mixTransform);//将wave_hand动画应用到mixTranform上 } // Update is called once per frame void Update() { }}
动画控制器
动画控制器的配置
1.动画状态机和过度条件
通过状态控制及,可以让游戏动画师进行五代码的可视化开发,将准备好的动画拖拽到动画状态及中,并搭建,在动画中,IDLE呗设置为默认动画,当然其他的也可以设置为默认,所谓默认就是在场景开始的时候,游戏对象保持的动画。 过度条件其实就是两个动画之间的过渡,通过右击动画状态单元,选择Make Transition创建过度条件。 每一个动画控制器都可以由若干个动画曾,每个动画曾都是一个动画状态机。 下图可以认为是一个动画状态机,也就是一个动画层。 2.过度条件的参数设置 动画状态机和过度条件搭建完成之后,需要对状态机间的过度条件进行设置,为了实现对各个过度条件的操纵,需要创建一个或者多个参数与之搭配 这里是三个动画状态机,也就是三个层, 这是过度条件的设置,使用方法如下using UnityEngine;using System.Collections;public class StaticAniCtrl : MonoBehaviour { //private KeyCode[] keys = new KeyCode[] { KeyCode.Keypad0, KeyCode.Keypad1, KeyCode.Keypad2, KeyCode.Keypad3 }; Animator myAnimator; Transform myCamera; void Start () { myAnimator = GetComponent(); UIInit(); myCamera = GameObject.Find("Main Camera").transform; } void Update () { myCamera.position = transform.position + new Vector3(0, 1.5f, 5); myCamera.LookAt(transform); } void UIInit() { GameObject.Find("Canvas/Button0").transform.GetComponent ().localPosition = new Vector3(Screen.height / 6 - Screen.width / 2, Screen.height * 2 / 5 - Screen.height / 2); GameObject.Find("Canvas/Button0").transform.GetComponent ().localScale = Screen.width / 600.0f * new Vector3(1, 1, 1); GameObject.Find("Canvas/Button1").transform.GetComponent ().localPosition = new Vector3(Screen.height / 6 - Screen.width / 2, Screen.height / 6 - Screen.height / 2); GameObject.Find("Canvas/Button1").transform.GetComponent ().localScale = Screen.width / 600.0f * new Vector3(1, 1, 1); } public void ButtonOnClick(int index) { myAnimator.SetFloat("AniFlag", index); }}
其中这句代码传递参数,动画控制器获得参数之后,将对指定的过度条件进行调控,从而实现动画播放的操控。
角色动画的重定向
1.角色动画重定向的应用
所谓重定向其实就是创建一个动画控制器,然后将器拖拽到两个对象的Animation组件中的Controller选项内 实例:using UnityEngine;using System.Collections;public class AniController : MonoBehaviour{ #region Variables Animator animator; //声明动画控制器 Animator girlAnimator; //声明小女孩对象的动画控制器 Transform myCamera; //声明摄像机对象 #endregion // Use this for initialization #region Function which be called by system void Start () { animator = GetComponent(); girlAnimator = GameObject.Find("Girl").GetComponent (); UIInit(); myCamera = GameObject.Find("Main Camera").transform; } // Update is called once per frame void Update () { myCamera.position = transform.position + new Vector3(0, 1.5f, 5); myCamera.LookAt(transform); } #endregion #region UI recall function and setting public void ButtonOnClick(int Index) { bool[] pars = new bool[] { true, false }; animator.SetBool("JtoR", pars[Index]); animator.SetBool("RtoJ", pars[(Index + 1) % 2]); girlAnimator.SetBool("JtoR", pars[Index]); girlAnimator.SetBool("RtoJ", pars[(Index + 1) % 2]); } void UIInit() { GameObject.Find("Canvas/Button0").transform.GetComponent ().localPosition = new Vector3(Screen.height / 6 - Screen.width / 2, Screen.height * 2 / 5 - Screen.height / 2); GameObject.Find("Canvas/Button0").transform.GetComponent ().localScale = Screen.width / 600.0f * Vector3.one; GameObject.Find("Canvas/Button1").transform.GetComponent ().localPosition = new Vector3(Screen.height / 6 - Screen.width / 2, Screen.height / 6 - Screen.height / 2); GameObject.Find("Canvas/Button1").transform.GetComponent ().localScale = Screen.width / 600.0f * Vector3.one; } #endregion}
角色动画的混合------创建动画混合树
转载地址:https://blog.csdn.net/lfanyize/article/details/104262887 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月17日 01时34分47秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
HTTP keep-alive详解
2019-04-26
字符编码(python编码机制的过去和现在)
2019-04-26
python序列的高阶函数:map,reduce,filter,sorted
2019-04-26
python模块的定义,和模块的作用域
2019-04-26
面向对象,即class类,类的封装,属性的类别划分,
2019-04-26
面向对象的继承和多态,剖析对象的信息(获取相关信息),类属性和实例属性
2019-04-26
JS的语句标识,注释,区分大小写
2019-04-26
JS的变量,使用strict模式
2019-04-26
对象,对象属性和方法
2019-04-26
Ubuntu的安装,搜狗输入法的安装
2019-04-26
itertools处理迭代
2019-04-26
iterable对象 yeield
2019-04-26
一些实用的快捷键
2019-04-26
添加打印机,在windows上面和Ubuntu上面
2019-04-26
Prepare the data
2019-04-26
scipy.misc.imresize改变图像的大小
2019-04-26
np.all的实例应用
2019-04-26