Unity Avatar动画系统

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);            
		}
*/

	}
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值