Example #1
0
            public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphStand settings)
            {
                m_Settings       = settings;
                m_AnimState      = controller.GetComponent <AnimStateData>();
                m_PredictedState = controller.GetComponent <LogicStateData>();

                m_Mask = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Platform");

                m_LocomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count);

                m_AnimIdle = AnimationClipPlayable.Create(graph, settings.animIdle);
                graph.Connect(m_AnimIdle, 0, m_LocomotionMixer, (int)LocoMixerPort.Idle);
                m_LocomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f);

                m_AnimTurnL = CreateTurnPlayable(graph, settings.animTurnL, m_LocomotionMixer, LocoMixerPort.TurnL);
                m_AnimTurnR = CreateTurnPlayable(graph, settings.animTurnR, m_LocomotionMixer, LocoMixerPort.TurnR);

                var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR };

                m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_LocomotionMixer, ports);

                if (settings.animTurnL.events.Length != 0)
                {
                    m_LeftTurnFootFalls  = ExtractFootFalls(settings.animTurnL);
                    m_RightTurnFootFalls = ExtractFootFalls(settings.animTurnR);
                }

                var animator  = controller.GetComponent <Animator>();
                var skeleton  = controller.GetComponent <Skeleton>();
                var leftToes  = skeleton.bones[skeleton.GetBoneIndex(settings.leftToeBone.GetHashCode())];
                var rightToes = skeleton.bones[skeleton.GetBoneIndex(settings.rightToeBone.GetHashCode())];

                var ikJob = new FootIkJob
                {
                    settings = settings.footIK,
                    leftToe  = animator.BindStreamTransform(leftToes),
                    rightToe = animator.BindStreamTransform(rightToes)
                };

                m_FootIk = AnimationScriptPlayable.Create(graph, ikJob, 1);
                graph.Connect(m_LocomotionMixer, 0, m_FootIk, 0);
                m_FootIk.SetInputWeight(0, 1f);

                m_AimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true);

                m_AnimAimLeft  = CreateAimPlayable(graph, settings.animAimLeft, m_AimMixer, AimMixerPort.AimLeft);
                m_AnimAimMid   = CreateAimPlayable(graph, settings.animAimMid, m_AimMixer, AimMixerPort.AimMid);
                m_AnimAimRight = CreateAimPlayable(graph, settings.animAimRight, m_AimMixer, AimMixerPort.AimRight);

                m_AdditiveMixer = AnimationLayerMixerPlayable.Create(graph);

                var locoMixerPort = m_AdditiveMixer.AddInput(m_FootIk, 0);

                m_AdditiveMixer.SetInputWeight(locoMixerPort, 1);

                var aimMixerPort = m_AdditiveMixer.AddInput(m_AimMixer, 0);

                m_AdditiveMixer.SetInputWeight(aimMixerPort, 1);
                m_AdditiveMixer.SetLayerAdditive((uint)aimMixerPort, true);
            }
    public ActionAnimationHandler(AnimationLayerMixerPlayable mixer, ActionAnimationDefinition[] actionAnimationDefs)
    {
        if (actionAnimationDefs == null)
        {
            return;
        }

        m_mixer = mixer;
        foreach (var def in actionAnimationDefs)
        {
            if (def.animation == null)
            {
                continue;
            }

            if (m_actionAnimations.ContainsKey(def.action))
            {
                continue;
            }

            ActionAnimation actionAnim = new ActionAnimation();
            actionAnim.animation = AnimationClipPlayable.Create(mixer.GetGraph(), def.animation);
            actionAnim.animation.SetApplyFootIK(false);
            actionAnim.animation.SetDuration(def.animation.length);
            actionAnim.port = mixer.AddInput(actionAnim.animation, 0);
            actionAnim.restartTimeOffset = def.restartTimeOffset;
            mixer.SetLayerAdditive((uint)actionAnim.port, true);
            m_actionAnimations.Add(def.action, actionAnim);
        }
    }
Example #3
0
        public static AnimationClipPlayable AddClip(this AnimationLayerMixerPlayable layerMixer, PlayableGraph graph, AnimationClip clip, out int index)
        {
            var playable = AnimationClipPlayable.Create(graph, clip);

            index = layerMixer.AddInput(playable, 0);
            return(playable);
        }
Example #4
0
    public AimVerticalHandler(AnimationLayerMixerPlayable mixer, AnimationClip animAimDownToUp)
    {
        // Aim
        m_animAim = AnimationClipPlayable.Create(mixer.GetGraph(), animAimDownToUp);
        m_animAim.SetApplyFootIK(false);
        m_animAim.Pause();
        m_aimTimeFactor = animAimDownToUp.length / 180.0f;

        m_port = mixer.AddInput(m_animAim, 0);
        mixer.SetLayerAdditive((uint)m_port, true);
        mixer.SetInputWeight(m_port, 1.0f);
    }
Example #5
0
        public Mixer(PlayableGraph playableGraph, ref AnimationLayerMixerPlayable animationLayerMixerPlayable, AnimationCurve blendingCurve, List <AnimationClip> animationClips)
        {
            animationMixerPlayable = AnimationMixerPlayable.Create(playableGraph, animationClips.Count, true);
            animationLayerMixerPlayable.AddInput(animationMixerPlayable, 0, 1);
            this.blendingCurve = blendingCurve;

            for (var i = 0; i < animationClips.Count; i++)
            {
                var animationClipPlayable = AnimationClipPlayable.Create(playableGraph, animationClips[i]);
                animationMixerPlayable.ConnectInput(i, animationClipPlayable, 0);

                animationClipPlayables.Add(animationClipPlayable);
                index.Add(animationClips[i].name, i);
                times.Add(animationClips[i].name, animationClips[i].length);
            }

            Observable
            .EveryUpdate()
            .Subscribe(_ =>
            {
                for (var i = 0; i < animationClipPlayables.Count; i++)
                {
                    animationMixerPlayable.SetInputWeight(i, 0);
                }
                if (string.IsNullOrEmpty(prev))
                {
                    animationMixerPlayable.SetInputWeight(index[next], 1.0f);
                }
                else
                {
                    var dt    = Time.timeSinceLevelLoad - currentTime;
                    var ratio = blendingCurve.Evaluate(dt);
                    animationMixerPlayable.SetInputWeight(index[prev], 1 - ratio);
                    animationMixerPlayable.SetInputWeight(index[next], ratio);
                }
            });
        }
Example #6
0
 // For Logic layer
 public void AddLayerPlayable(LogicMotionMatchingLayer layer)
 {
     layer.SetPlayable(AnimationMixerPlayable.Create(this.graph, 0, true));
     layerMixer.AddInput(layer.GetPlayable(), 0, 1f);
 }