• Animator.GetBehaviours 获得行为列表

    Animator.GetBehaviours 获得行为列表

    public T[] GetBehaviours();

    描述:

    返回匹配类型T或派生自T的所有状态机行为,如果没有找到返回null。

    1. using UnityEngine;
    2. using System.Collections;
    3. // An example StateMachineBehaviour.
    4. public class BreathBehaviour : StateMachineBehaviour {
    5. public bool fastBreath;
    6. // OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
    7. override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    8. animator.SetBool("FastBreath", fastBreath);
    9. }
    10. }
    11. public class RunBehaviour : StateMachineBehaviour {
    12. // OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
    13. override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    14. {
    15. BreathBehaviour[] breathBehaviours = animator.GetBehaviours<BreathBehaviour>();
    16. for(int i=0;i<breathBehaviours.Length();i++)
    17. breathBehaviours[i].fastBreath = true;
    18. }
    19. }

    ?