Example #1
0
        public AnimationClipPlayable Play(AnimationClip clip, float transition = 0, int toLayer = 0)
        {
            var playable = AnimationClipPlayable.Create(_playableGraph, clip);

            int inputIndex;

            if (AnimationPlayLayers.Length > 1)
            {
                var animationMixerPlayable = (AnimationMixerPlayable)layerMixerPlayable.GetInput(toLayer);
                inputIndex = GetInputIndex(animationMixerPlayable);
                _playableGraph.Connect(playable, 0, animationMixerPlayable, inputIndex);
            }
            else
            {
                if (AnimationClipIsPlaying(mixerPlayable, clip, out var playingPlayable))
                {
                    return(playingPlayable);
                }
                inputIndex = GetInputIndex(mixerPlayable);
                var layer = AnimationPlayLayers[toLayer];
                layer.Add(inputIndex, transition);
                _playableGraph.Connect(playable, 0, mixerPlayable, inputIndex);
                if (layer.bInputIndex == -1)
                {
                    mixerPlayable.SetInputWeight(layer.aInputIndex, 1f);
                }
            }
            return(playable);
        }
Example #2
0
        void FindMixers()
        {
            m_Mixers.Clear();
            m_PoseMixer       = AnimationLayerMixerPlayable.Null;
            m_LayerMixer      = AnimationLayerMixerPlayable.Null;
            m_MotionXPlayable = AnimationMotionXToDeltaPlayable.Null;

            var playable   = m_Output.GetSourcePlayable();
            var outputPort = m_Output.GetSourceOutputPort();

            if (!playable.IsValid() || outputPort < 0 || outputPort >= playable.GetInputCount())
            {
                return;
            }

            var mixer = FindFirstAnimationPlayable(playable.GetInput(outputPort));

            Playable motionXPlayable = mixer;

            if (motionXPlayable.IsPlayableOfType <AnimationMotionXToDeltaPlayable>())
            {
                m_MotionXPlayable = (AnimationMotionXToDeltaPlayable)motionXPlayable;
                mixer             = m_MotionXPlayable.GetInput(0);
            }

#if UNITY_EDITOR
            // Default pose mixer
            if (!Application.isPlaying)
            {
                if (mixer.IsValid() && mixer.IsPlayableOfType <AnimationLayerMixerPlayable>())
                {
                    m_PoseMixer = (AnimationLayerMixerPlayable)mixer;
                    mixer       = m_PoseMixer.GetInput(1);
                }
            }
#endif

            // Track mixer
            if (mixer.IsValid() && mixer.IsPlayableOfType <AnimationLayerMixerPlayable>())
            {
                m_LayerMixer = (AnimationLayerMixerPlayable)mixer;
            }

            if (!m_LayerMixer.IsValid())
            {
                return;
            }

            var count = m_LayerMixer.GetInputCount();
            for (var i = 0; i < count; i++)
            {
                FindMixers(m_LayerMixer, i, m_LayerMixer.GetInput(i));
            }
        }
        void FindMixers()
        {
            m_Mixers.Clear();
            m_PoseMixer       = AnimationMixerPlayable.Null;
            m_LayerMixer      = AnimationLayerMixerPlayable.Null;
            m_MotionXPlayable = AnimationMotionXToDeltaPlayable.Null;

            var playable   = m_Output.GetSourcePlayable();
            var outputPort = m_Output.GetSourceOutputPort();

            if (!playable.IsValid() || outputPort < 0 || outputPort >= playable.GetInputCount())
            {
                return;
            }

            var mixer = FindFirstAnimationPlayable(playable.GetInput(outputPort));

            Playable motionXPlayable = mixer;

            if (motionXPlayable.IsPlayableOfType <AnimationMotionXToDeltaPlayable>())
            {
                m_MotionXPlayable = (AnimationMotionXToDeltaPlayable)motionXPlayable;
                mixer             = m_MotionXPlayable.GetInput(0);
            }

            if (mixer.IsValid() && mixer.IsPlayableOfType <AnimationMixerPlayable>())
            {
                m_PoseMixer = (AnimationMixerPlayable)mixer;
                Playable layerMixer = m_PoseMixer.GetInput(0);

                if (layerMixer.IsValid() && layerMixer.IsPlayableOfType <AnimationLayerMixerPlayable>())
                {
                    m_LayerMixer = (AnimationLayerMixerPlayable)layerMixer;
                }
            }
            else if (mixer.IsValid() && mixer.IsPlayableOfType <AnimationLayerMixerPlayable>())
            {
                m_LayerMixer = (AnimationLayerMixerPlayable)mixer;
            }


            if (!m_LayerMixer.IsValid())
            {
                return;
            }

            var count = m_LayerMixer.GetInputCount();

            for (var i = 0; i < count; i++)
            {
                FindMixers(m_LayerMixer, i, m_LayerMixer.GetInput(i));
            }
        }