Version: 5.3 (switch to 5.4b)
ЯзыкEnglish
  • C#
  • JS

Язык программирования

Выберите подходящий для вас язык программирования. Все примеры кода будут представлены на выбранном языке.

StateMachineBehaviour

class in UnityEngine

/

Наследует от:ScriptableObject

Предложить изменения

Успех!

Благодарим вас за то, что вы помогаете нам улучшить качество документации по Unity. Однако, мы не можем принять любой перевод. Мы проверяем каждый предложенный вами вариант перевода и принимаем его только если он соответствует оригиналу.

Закрыть

Ошибка внесения изменений

По определённым причинам предложенный вами перевод не может быть принят. Пожалуйста <a>попробуйте снова</a> через пару минут. И выражаем вам свою благодарность за то, что вы уделяете время, чтобы улучшить документацию по Unity.

Закрыть

Отменить

Руководство

Описание

StateMachineBehaviour 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.

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


        
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; Rigidbody 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 "); } }

Открытые функции

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.

Сообщения

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.
OnStateMoveCalled right after MonoBehaviour.OnAnimatorMove.
OnStateUpdateCalled at each Update frame except for the first and last frame.

Унаследованные члены

Переменные

hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Открытые функции

GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the game object.

Статические функции

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateReturns a copy of the object original.
CreateInstanceCreates an instance of a scriptable object.

Операторы

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.

Сообщения

OnDestroyThis function is called when the scriptable object will be destroyed.
OnDisableThis function is called when the scriptable object goes out of scope.
OnEnableThis function is called when the object is loaded.