StateMachineBehaviour はステートマシンのステートに追加できるコンポーネントです。ステートのすべてのスクリプトが継承する基底クラスでもあります。
通常、Animator はコントローラーで定義されるそれぞれのビヘイビアの新しいインスタンスをインスタンス化しません。クラス属性である SharedBetweenAnimatorsAttribute は、ビヘイビアがどのようにインスタンス化されるかを管理します。
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 "); } }
| OnStateMachineEnter | Called on the first Update frame when making a transition to a state machine. This is not called when making a transition into a state machine sub-state. |
| OnStateMachineExit | StateMachine からの移行を行うとき、最後の Update フレームが呼ばれます。StateMachine のサブステートの中へ移行を行うとき、これは呼び出されません。 |
| OnStateEnter | Called on the first Update frame when a state machine evaluate this state. |
| OnStateExit | Called on the last update frame when a state machine evaluate this state. |
| OnStateIK | MonoBehaviour.OnAnimatorIK の直後に呼び出されます。 |
| OnStateMove | MonoBehaviour.OnAnimatorMove の直後に呼び出されます。 |
| OnStateUpdate | 最初と最後のフレームを除いて Update フレームごとに呼び出されます。 |
| hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
| name | オブジェクト名 |
| GetInstanceID | オブジェクトのインスタンス ID を返します |
| ToString | Returns the name of the object. |
| Destroy | Removes a GameObject, component or asset. |
| DestroyImmediate | Destroys the object obj immediately. You are strongly recommended to use Destroy instead. |
| DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
| FindObjectOfType | タイプ type から最初に見つけたアクティブのオブジェクトを返します |
| FindObjectsOfType | Gets a list of all loaded objects of Type type. |
| Instantiate | original のオブジェクトをクローンします |
| CreateInstance | ScriptableObject のインスタンスを作成します。 |
| bool | オブジェクトが存在するかどうか |
| operator != | 二つのオブジェクトが異なるオブジェクトを参照しているか比較します |
| operator == | 2つのオブジェクト参照が同じオブジェクトを参照しているか比較します。 |
| Awake | ScriptableObject スクリプトを開始するとき、この関数は呼び出されます。 |
| OnDestroy | ScriptableObject が破棄されるとき、この関数は呼び出されます。 |
| OnDisable | ScriptableObject クラスのオブジェクトがスコープを外れるとき、この関数は呼び出されます。 |
| OnEnable | オブジェクトがロードされたとき、この関数は呼び出されます。 |
| OnValidate | This function is called when the script is loaded or a value is changed in the Inspector (Called in the editor only). |
| Reset | デフォルト値にリセットします |