Unity Avatar动画系统
2014-05-13 17:01
344 查看
Unity Avatar动画系统使用的一些基础属性和方法。以方便日后查找和使用。
using UnityEngine; using System.Collections; public class AnimationTest : MonoBehaviour { private Animator MasterAnim; public GameObject GMaster; public bool ikActive; // Use this for initialization void Start () { } // Update is called once per frame void Update () { MasterAnim = GMaster.GetComponent<Animator> (); AnimatorStateInfo stateInfo=MasterAnim.GetCurrentAnimatorStateInfo(0);//获取当前状态机 float Statelength=stateInfo.length;//动作的总共时间 Debug.Log ("StateLength" + Statelength); float normalizedTime=stateInfo.normalizedTime;//返回了当前动作的时间,整数表示已经循环了几次,小数点后的数字表示目前动作执行的进度 //stateInfo.normalizedTime > 0.6f当前状态运行了0.6正交化时间(即动作时长的60%) Debug.Log("stateNorTime"+normalizedTime); int nameHash=stateInfo.nameHash; if (stateInfo.nameHash == Animator.StringToHash ("Base Layer.idle") && !MasterAnim.IsInTransition (0)) { Debug.Log ("the state is idle"); } else { Debug.Log("the state is other"); } if (stateInfo.loop == true) //判断动画是否是循环播放 { Debug.Log ("The animation loop"); } else { Debug.Log("Tshe animation only one"); } if (stateInfo.IsName ("Base Layer.idle")) { Debug.Log ("动画相等"); } else { Debug.Log("动画不等"); } MasterAnim.avatar.name="monkeyAvatar";//更换Avatar string name = MasterAnim.name;//动作所赋的物体名字 Debug.Log("name"+name); //获取当前Clip AnimationClip Animaclip = MasterAnim.GetCurrentAnimationClipState(0)[0].clip; string Clipname=Animaclip.name;//clip名字 Debug.Log ("Clipname"+Clipname); float ClipLength=Animaclip.length; Debug.Log ("ClipLength"+ClipLength); //设置IK动画 /*IK(Inverse Kinematics)反向动力学的使用只能在PRO版中使用 if(ikActive) { //设置骨骼的权重,1表示完整的骨骼,如果是0.5哪么骨骼权重就是一半呢,可移动或旋转的就是一半,大家可以修改一下参数试试。 MasterAnim.SetIKPositionWeight(AvatarIKGoal.RightHand,1f); MasterAnim.SetIKRotationWeight(AvatarIKGoal.RightHand,1f); //set the position and the rotation of the right hand where the external object is if(rightHandObj != null) { //设置右手根据目标点而旋转移动父骨骼节点 MasterAnim.SetIKPosition(AvatarIKGoal.RightHand,rightHandObj.position); MasterAnim.SetIKRotation(AvatarIKGoal.RightHand,rightHandObj.rotation); } } //如果取消IK动画,哪么重置骨骼的坐标。 else { MasterAnim.SetIKPositionWeight(AvatarIKGoal.RightHand,0); MasterAnim.SetIKRotationWeight(AvatarIKGoal.RightHand,0); } */ } }
相关文章推荐
- Unity动画系统-配置Avatar
- Unity-动画系统_Avatar系统
- Unity进阶 - 动画系统 - 给人物角色制作动画
- Unity 动画系统(Mecanim) 术语及翻译 表格
- Unity进阶 - 动画系统 - 人形动画的导入
- 【Unity编程】Unity动画系统(二)
- unity5.0新功能-布料、动画系统
- unity 动画系统教程(二)
- 【小松教你手游开发】【unity实用技能】动画系统项目实战
- Unity 动画系统(Mecanim)的组成结构
- unity 新的动画系统 Animator的使用(原)
- 使用Unity新版动画系统Animator实现三连击
- 【Unity快速实现小功能】动画系统学习小技巧篇(一)——设置动画循环播放
- Unity进阶 - 动画系统 - 人形动画的导入
- Unity 进阶 - 动画系统 - Mecanim动画系统
- 关于Unity中新版动画系统的使用
- Unity 动画系统
- Unity 动画系统初探(1)
- Unity 进阶 - 动画系统 - Mecanim动画系统概述
- Unity_UGUI_动画系统