天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.6 KiB

using UnityEngine;
using System.Collections;
public class Locomotion
{
private Animator m_Animator = null;
private int m_SpeedId = 0;
private int m_AgularSpeedId = 0;
private int m_DirectionId = 0;
public float m_SpeedDampTime = 0.1f;
public float m_AnguarSpeedDampTime = 0.25f;
public float m_DirectionResponseTime = 0.2f;
public Locomotion(Animator animator)
{
m_Animator = animator;
m_SpeedId = Animator.StringToHash("Speed");
m_AgularSpeedId = Animator.StringToHash("AngularSpeed");
m_DirectionId = Animator.StringToHash("Direction");
}
public void Do(float speed, float direction)
{
AnimatorStateInfo state = m_Animator.GetCurrentAnimatorStateInfo(0);
bool inTransition = m_Animator.IsInTransition(0);
bool inIdle = state.IsName("Locomotion.Idle");
bool inTurn = state.IsName("Locomotion.TurnOnSpot") || state.IsName("Locomotion.PlantNTurnLeft") || state.IsName("Locomotion.PlantNTurnRight");
bool inWalkRun = state.IsName("Locomotion.WalkRun");
float speedDampTime = inIdle ? 0 : m_SpeedDampTime;
float angularSpeedDampTime = inWalkRun || inTransition ? m_AnguarSpeedDampTime : 0;
float directionDampTime = inTurn || inTransition ? 1000000 : 0;
float angularSpeed = direction / m_DirectionResponseTime;
m_Animator.SetFloat(m_SpeedId, speed, speedDampTime, 10*Time.deltaTime);
m_Animator.SetFloat(m_AgularSpeedId, angularSpeed, angularSpeedDampTime, Time.deltaTime);
m_Animator.SetFloat(m_DirectionId, direction, directionDampTime, Time.deltaTime);
}
}