@@ -21,6 +21,53 @@ public static class JCS_Animator
2121
2222 /* Functions */
2323
24+ /// <summary>
25+ /// Return true if the parameter exists.
26+ /// </summary>
27+ public static bool HasParameter ( Animator animator , string paramName )
28+ {
29+ foreach ( AnimatorControllerParameter param in animator . parameters )
30+ {
31+ if ( param . name == paramName )
32+ return true ;
33+ }
34+ return false ;
35+ }
36+
37+ /// <summary>
38+ /// Return true if the layer exists in the aniamtor.
39+ /// </summary>
40+ public static bool HasLayer ( Animator animator , string name )
41+ {
42+ int index = animator . GetLayerIndex ( name ) ;
43+
44+ return HasLayer ( animator , index ) ;
45+ }
46+ public static bool HasLayer ( Animator animator , int index )
47+ {
48+ if ( index < 0 || animator . layerCount <= index )
49+ return false ;
50+
51+ return true ;
52+ }
53+
54+ /// <summary>
55+ /// Like `Animator.HasState` but make second paramter
56+ /// accepts the string.
57+ /// </summary>
58+ public static bool HasState ( Animator animator , int layer , string name )
59+ {
60+ // First check if the layer exists.
61+ if ( HasLayer ( animator , layer ) )
62+ return false ;
63+
64+ // Convert name to hash.
65+ int stateHash = Animator . StringToHash ( name ) ;
66+
67+ // Then do the check.
68+ return animator . HasState ( layer , stateHash ) ;
69+ }
70+
2471 /// <summary>
2572 /// Sets the weight of the layer at the given name.
2673 ///
@@ -54,22 +101,5 @@ public static float GetLayerWeight(Animator ator, int index)
54101 {
55102 return ator . GetLayerWeight ( index ) ;
56103 }
57-
58- /// <summary>
59- /// Like `Animator.HasState` but make second paramter
60- /// accepts the string.
61- /// </summary>
62- public static bool HasState ( Animator animator , int layer , string name )
63- {
64- // First check if the layer exists.
65- if ( layer < 0 || animator . layerCount <= layer )
66- return false ;
67-
68- // Convert name to hash.
69- int stateHash = Animator . StringToHash ( name ) ;
70-
71- // Then do the check.
72- return animator . HasState ( layer , stateHash ) ;
73- }
74104 }
75105}
0 commit comments