用户工具

站点工具


侧边栏



Unity3D中文文档

script:unityengine:classes:statemachinebehaviour:statemachinebehaviour

StateMachineBehaviour 状态机行为

class in UnityEngine/Inherits from: ScriptableObject

Description 描述

tateMachineBehaviour is a component that can be added to a state machine state. It's the base class every script on a state derives from.

状态机行为是个可以添加状态机状态的组件。这是来自基类上的每个脚本派生的状态。

By default the Animator does instantiate a new instance of each behaviour define in the controller. The class attribute SharedBetweenAnimatorsAttribute control how behaviours are instantiated.

默认情况下,Animator示例化一个新的实例的每个行为在控制器中定义。该类属性SharedBetweenAnimatorsAttribute 控制如何实例化该行为。

StateMachineBehaviour has some predefined messages: OnStateEnter, OnStateExit, OnStateIK, OnStateMove, OnStateUpdate.

StateMachineBehaviour 有一些预定义的信息:OnStateEnter, OnStateExit, OnStateIK, OnStateMove, OnStateUpdate。

JavaScript:

#pragma strict
public class AttackBehaviour extends StateMachineBehaviour {
	public var particle: GameObject;
	public var radius: float;
	public var power: float;
	protected var clone: GameObject;
	public override function OnStateEnter(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		clone = Instantiate(particle, animator.rootPosition, Quaternion.identity) as GameObject;
		var rb: var = clone.GetComponent.<Rigidbody>();
		rb.AddExplosionForce(power, animator.rootPosition, radius, 3.0f);
	}
	public override function OnStateExit(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		Destroy(clone);
	}
	public override function OnStateUpdate(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		Debug.Log("On Attack Update ");
	}
	public override function OnStateMove(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		Debug.Log("On Attack Move ");
	}
	public override function OnStateIK(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		Debug.Log("On Attack IK ");
	}
}

C#:

using UnityEngine;
 
public class AttackBehaviour : StateMachineBehaviour
{
	public GameObject particle;
	public float radius;
	public float power;
 
	protected GameObject clone;
 
	override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
		clone = Instantiate(particle, animator.rootPosition, Quaternion.identity) as GameObject;
		var rb = clone.GetComponent<Rigidbody>();
		rb.AddExplosionForce(power, animator.rootPosition, radius, 3.0f);
	}
	override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
		Destroy(clone);
	}
	override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
		Debug.Log("On Attack Update ");
	}
	override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
		Debug.Log("On Attack Move ");
	}
	override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
		Debug.Log("On Attack IK ");
	}
}

Public Functions 公共函数

OnStateMachineEnterCalled on the first Update frame when making a transition to a StateMachine. This is not called when making a transition into a StateMachine sub-state.
变换转进入状态机时调用该属性。变换进入状态机的子状态时不会调用该属性。
OnStateMachineExitCalled on the last Update frame when making a transition out of a StateMachine. This is not called when making a transition into a StateMachine sub-state.
变换超出状态机时调用该属性。变换在状态机的子状态下不会调用该属性。。

Messages 消息

OnStateEnterCalled on the first Update frame when a statemachine evaluate this state.
状态机评估进入状态时调用该属性。
OnStateExitCalled on the last update frame when a statemachine evaluate this state.
当状态机评估停止状态时调用该属性。
OnStateIKCalled right after MonoBehaviour.OnAnimatorIK.
MonoBehaviour.OnAnimatorIK之后调用该属性。
OnStateMoveCalled right after MonoBehaviour.OnAnimatorMove.
MonoBehaviour.OnAnimatorMove之后调用该属性。
OnStateUpdateCalled at each Update frame except for the first and last frame.
除了开始和最后一帧,每次更新时调用。
script/unityengine/classes/statemachinebehaviour/statemachinebehaviour.txt · 最后更改: 2016/08/02 05:33 (外部编辑)