Esempio n. 1
0
    private static void AddStateTransition(string path, UnityEditor.Animations.AnimatorControllerLayer layer, string motionName, Vector3 pos)
    {
        UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine;
        Motion motion = AssetDatabase.LoadAssetAtPath(path, typeof(Motion)) as Motion;          //根据动画文件读取它的Motion对象

        UnityEditor.Animations.AnimatorState state = sm.AddState(motionName, pos);              //motion.name

        state.motion = motion;                                                                  //取出动画名子 添加到state里面
        UnityEditor.Animations.AnimatorStateTransition trans = sm.AddAnyStateTransition(state); //把state添加在layer里面

        trans.hasExitTime = false;                                                              //把默认的时间条件删除 //false
        //trans.exitTime = 1f; //0.9f

        trans.duration            = 0f;   //默认过渡时间 // 0.1f
        trans.canTransitionToSelf = true; //默认true
    }
Esempio n. 2
0
    private static void AddTransition(UnityEditor.Animations.AnimatorStateMachine machine, UnityEditor.Animations.AnimatorState from, UnityEditor.Animations.AnimatorState to, bool removedef, params object[] conditions)
    {
        UnityEditor.Animations.AnimatorStateTransition transition = null;
        transition = from == null?machine.AddAnyStateTransition(to) : from.AddTransition(to);

        //Unity5中默认是没有condition的
        //if (removedef) transition.RemoveCondition(0);

        transition.offset      = 0.0f;
        transition.duration    = 0.0f;
        transition.hasExitTime = false;

        for (var i = 0; i < conditions.Length;)
        {
            if (conditions.Length - i < 2)
            {
                break;
            }

            //var cond  = transition.AddCondition();
            var mode  = (UnityEditor.Animations.AnimatorConditionMode)conditions[i++];
            var param = conditions[i++].ToString();

            //cond.mode      = mode;
            //cond.parameter = param;

            float threshold = 0f;
            if (i >= conditions.Length)
            {
                break;
            }
            if (mode != UnityEditor.Animations.AnimatorConditionMode.If && mode != UnityEditor.Animations.AnimatorConditionMode.IfNot)
            {
                threshold = (int)conditions[i++];
            }

            transition.AddCondition(mode, threshold, param);
        }
    }