アニメータコントローラは、State Machine(ステートマシン)でレイヤーを通じてアニメーションを制御します。また、パラメータによって制御されます。
using UnityEngine; using UnityEditor; using UnityEditor.Animations; using System.Collections;
// Create a menu item that causes a new controller and statemachine to be created.
public class SM : MonoBehaviour { [MenuItem("MyMenu/Create Controller")] static void CreateController() { // Creates the controller var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Mecanim/StateMachineTransitions.controller");
// Add parameters controller.AddParameter("TransitionNow", AnimatorControllerParameterType.Trigger); controller.AddParameter("Reset", AnimatorControllerParameterType.Trigger); controller.AddParameter("GotoB1", AnimatorControllerParameterType.Trigger); controller.AddParameter("GotoC", AnimatorControllerParameterType.Trigger);
// Add StateMachines var rootStateMachine = controller.layers[0].stateMachine; var stateMachineA = rootStateMachine.AddStateMachine("smA"); var stateMachineB = rootStateMachine.AddStateMachine("smB"); var stateMachineC = stateMachineB.AddStateMachine("smC");
// Add States var stateA1 = stateMachineA.AddState("stateA1"); var stateB1 = stateMachineB.AddState("stateB1"); var stateB2 = stateMachineB.AddState("stateB2"); stateMachineC.AddState("stateC1"); var stateC2 = stateMachineC.AddState("stateC2"); // don’t add an entry transition, should entry to state by default
// Add Transitions var exitTransition = stateA1.AddExitTransition(); exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow"); exitTransition.duration = 0;
var resetTransition = rootStateMachine.AddAnyStateTransition(stateA1); resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "Reset"); resetTransition.duration = 0;
var transitionB1 = stateMachineB.AddEntryTransition(stateB1); transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoB1"); stateMachineB.AddEntryTransition(stateB2); stateMachineC.defaultState = stateC2; var exitTransitionC2 = stateC2.AddExitTransition(); exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow"); exitTransitionC2.duration = 0;
var stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC); stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoC"); rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineB); } }
layers | コントローラーのレイヤー |
parameters | パラメータは、スクリプトとコントローラー間の通信に使われます。例えば、それらはドライブを制御するためやブレンドツリーに使われます。 |
AnimatorController | コンストラクター |
AddEffectiveStateMachineBehaviour | Adds a state machine behaviour class of a specific type to the AnimatorState for layer layerIndex. This method should be used when you are dealing with synchronized layer and would like to add a state machine behaviour on a synchronized layer. Note that there is no corresponding "Remove" method. To remove a state machine behaviour, use Object.Destroy. |
AddLayer | レイヤーをコントローラーに加えるためのユーティリティ関数です。 |
AddMotion | Motion に対する新しいステートを作成するユーティリティ機能です。 |
AddParameter | コントローラーにパラメーターを追加するためのユーティリティ機能です。 |
CreateBlendTreeInController | 新しい AnimatorState にブレンドツリー(BlendTree)を作成します。 |
GetBehaviours | T 型にマッチする、または T 型派生のすべての StateMachineBehaviour を返します。 |
GetStateEffectiveBehaviours | アニメーターのステート(AnimatorState)に効果的なステートマシンの振る舞い(Behaviour)リストを取得します。振る舞いは、アニメーターのステートマシン(AnimatorStateMachine )内かアニメーターレイヤーのオーバーライド(ovverride)内のいずれかで格納されます。効果的に使える振る舞い(Behaviour)リストを取得するために、この機能を使用します。 |
GetStateEffectiveMotion | アニメーターのステートのために効果的に Motion(動作)を取得します。Motion(動作)はアニメーターのステートマシン(AnimatorStateMachine)かアニメーターレイヤーのオーバーライド(ovverride)モードで格納されます。効果的に使える Motion(動作)を取得するために、この機能を使用します。 |
MakeUniqueLayerName | ユニークなレイヤー名を作成します。 |
MakeUniqueParameterName | ユニークなパラメータ名を作成します。 |
RemoveLayer | コントローラーからレイヤーを削除するためのユーティリティ機能です。 |
RemoveParameter | コントローラーからパラメーターを削除するためのユーティリティ機能です。 |
SetStateEffectiveBehaviours | アニメーターのステート(AnimatorState)に効果的なステートマシンの振る舞い(Behaviour)リストを設定します。振る舞いリストは、アニメーターのステートマシン(AnimatorStateMachine)内かアニメーターレイヤーのオーバーライド(ovverride)内のいずれかで格納されます。効果的に使える振る舞い(Behaviour)リストを設定するために、この機能を使用します。 |
SetStateEffectiveMotion | アニメーターのステートのために効果的な Motion(動作)を設定します。Motion(動作)はアニメーターのステートマシン(AnimatorStateMachine)かアニメーターレイヤーのオーバーライド(ovverride)モードで格納されます。効果的に使える Motion(動作)を設定するために、この機能を使用します。 |
CreateAnimatorControllerAtPath | 与えられたパスを使用してアニメータコントローラ(AnimatorController)を作成します。 |
CreateAnimatorControllerAtPathWithClip | 指定されたパスでアニメータコントローラー(AnimatorController)を作成し、アニメーションクリップ(AnimationClip)でステートを加える機能を持つアニメータのステートマシン(AnimatorStateMachine)を使用し自動的にアニメータのレイヤーを作成します。 |
CreateStateMachineBehaviour | この機能は、スクリプトで定義するクラスに基づいて StateMachineBehaviour のインスタンスを作成します。 |
FindStateMachineBehaviourContext | この振る舞い(動作)のオーナーを検索するために、この機能を使用します。 |
hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
name | オブジェクト名 |
animationClips | Retrieves all AnimationClip used by the controller. |
GetInstanceID | Gets the instance ID of the object. |
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 のオブジェクトをクローンします |
bool | オブジェクトが存在するかどうか |
operator != | 二つのオブジェクトが異なるオブジェクトを参照しているか比較します |
operator == | 2つのオブジェクト参照が同じオブジェクトを参照しているか比較します。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.