UnityEditor.Animations.AnimatorControllerLayer.SetOverrideMotion C# (CSharp) Method

SetOverrideMotion() public method

Sets the override motion for the state on the given layer.

public SetOverrideMotion ( AnimatorState state, Motion motion ) : void
state AnimatorState The state which we want to set the motion.
motion UnityEngine.Motion The motion that will be set.
return void
        public void SetOverrideMotion(AnimatorState state, Motion motion)
        {
            StateMotionPair pair;
            if (this.m_Motions == null)
            {
                this.m_Motions = new StateMotionPair[0];
            }
            for (int i = 0; i < this.m_Motions.Length; i++)
            {
                if (this.m_Motions[i].m_State == state)
                {
                    this.m_Motions[i].m_Motion = motion;
                    return;
                }
            }
            pair.m_State = state;
            pair.m_Motion = motion;
            ArrayUtility.Add<StateMotionPair>(ref this.m_Motions, pair);
        }

Usage Example

コード例 #1
0
    void test02()
    {
        AnimatorController controller =
            AnimatorController.CreateAnimatorControllerAtPath("Assets/animation.controller");
        // Add parameters
        //controller.AddLayer("hahaha");
        AnimatorState mstate = new AnimatorState();

        mstate.name = "myState";
        Motion mmotion = Resources.Load <AnimationClip>("animation/playerClip") as Motion;

        mmotion.name = "myMotion";
        AnimatorControllerLayer myLayer = new AnimatorControllerLayer();

        myLayer.name = "hahaha";
        //myLayer.SetOverrideBehaviours(mstate,;
        myLayer.SetOverrideMotion(mstate, mmotion);
        controller.AddLayer(myLayer);
    }