Unity-Animator深入系列---fullPathHash和shortNameHash

时间:2023-12-31 15:05:14

回到 Animator深入系列总目录

Unity5对状态哈希做了改进,拆分成了fullPathHash和shortNameHash,那么就来看看他们有什么区别

测试结果:

fullPathHash支持嵌套子状态以及层,shortNameHash直接不支持路径

这是使用的测试状态机,一共三种状态

Unity-Animator深入系列---fullPathHash和shortNameHash

测试脚本:

public class A1 : MonoBehaviour
{
public Animator animator; void OnGUI()
{
GUILayout.Box("Layer1 fullPathHash - " + (animator.GetCurrentAnimatorStateInfo().fullPathHash == Animator.StringToHash("Layer1.Idle")));
GUILayout.Box("Layer1 Idle2 fullPathHash - " + (animator.GetCurrentAnimatorStateInfo().fullPathHash == Animator.StringToHash("Layer1.Group.Idle")));
GUILayout.Box("Layer2 fullPathHash - " + (animator.GetCurrentAnimatorStateInfo().fullPathHash == Animator.StringToHash("Layer2.Idle"))); GUILayout.Box("Layer1 shortNameHash - " + (animator.GetCurrentAnimatorStateInfo().shortNameHash == Animator.StringToHash("Idle")));
GUILayout.Box("Layer1 Idle2 shortNameHash(1) - " + (animator.GetCurrentAnimatorStateInfo().shortNameHash == Animator.StringToHash("Group.Idle")));
GUILayout.Box("Layer1 Idle2 shortNameHash(2) - " + (animator.GetCurrentAnimatorStateInfo().shortNameHash == Animator.StringToHash("Idle")));
GUILayout.Box("Layer2 shortNameHash - " + (animator.GetCurrentAnimatorStateInfo().shortNameHash == Animator.StringToHash("Idle")));
}
}

测试结果1(Layer1.Group.Idle未跳转):

Unity-Animator深入系列---fullPathHash和shortNameHash

测试结果2(Layer1.Group.Idle已跳转):

Unity-Animator深入系列---fullPathHash和shortNameHash

最终结论:

fullPathHash支持子状态以及层,shortNameHash直接不支持路径