返回介绍

Animator.GetBehaviours 获得行为列表

发布于 2019-12-18 15:37:14 字数 2508 浏览 1312 评论 0 收藏 0

JavaScript => public function GetBehaviours(): T[];
C# => public T[] GetBehaviours();

Description 描述

Returns all StateMachineBehaviour that match type T or are derived from T. Returns null if none are found.

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

JavaScript:

#pragma strict
// An example StateMachineBehaviour.
public class BreathBehaviour extends StateMachineBehaviour {
	public var fastBreath: boolean;
	// OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
	public override function OnStateUpdate(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		animator.SetBool("FastBreath", fastBreath);
	}
}
public class RunBehaviour extends StateMachineBehaviour {
	// OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
	public override function OnStateUpdate(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		var breathBehaviours: BreathBehaviour[] = animator.GetBehaviours.<BreathBehaviour>();
		for (var i: int = 0; i < breathBehaviours.Length(); i++)
			breathBehaviours[i].fastBreath = true;
	}
}

C#:

using UnityEngine;
using System.Collections;
 
// An example StateMachineBehaviour.
public class BreathBehaviour : StateMachineBehaviour {
 
	public bool  fastBreath;
 
	// OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
	override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
		animator.SetBool("FastBreath", fastBreath);
	}
}
 
 
public class RunBehaviour : StateMachineBehaviour {
 
	// OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
	override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 
	{
		BreathBehaviour[] breathBehaviours = animator.GetBehaviours<BreathBehaviour>();
        for(int i=0;i<breathBehaviours.Length();i++)
             breathBehaviours[i].fastBreath = true;
	}
}

Animator

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文