Example #1
0
        internal static Playable CreatePlayable(PlayableGraph graph, AnimationClip clip, Vector3 positionOffset, Vector3 eulerOffset, bool removeStartOffset, AppliedOffsetMode mode, bool applyFootIK, LoopMode loop)
        {
            if (clip == null || clip.legacy)
            {
                return(Playable.Null);
            }


            var clipPlayable = AnimationClipPlayable.Create(graph, clip);

            clipPlayable.SetRemoveStartOffset(removeStartOffset);
            clipPlayable.SetApplyFootIK(applyFootIK);
            clipPlayable.SetOverrideLoopTime(loop != LoopMode.UseSourceAsset);
            clipPlayable.SetLoopTime(loop == LoopMode.On);

            Playable root = clipPlayable;

            if (ShouldApplyScaleRemove(mode))
            {
                var removeScale = AnimationRemoveScalePlayable.Create(graph, 1);
                graph.Connect(root, 0, removeScale, 0);
                removeScale.SetInputWeight(0, 1.0f);
                root = removeScale;
            }

            if (ShouldApplyOffset(mode, clip))
            {
                var offsetPlayable = AnimationOffsetPlayable.Create(graph, positionOffset, Quaternion.Euler(eulerOffset), 1);
                graph.Connect(root, 0, offsetPlayable, 0);
                offsetPlayable.SetInputWeight(0, 1.0F);
                root = offsetPlayable;
            }

            return(root);
        }
Example #2
0
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            Playable result;

            if (this.clip == null || this.clip.legacy)
            {
                result = Playable.Null;
            }
            else
            {
                AnimationClipPlayable animationClipPlayable = AnimationClipPlayable.Create(graph, this.m_Clip);
                this.m_AnimationClipPlayable = animationClipPlayable;
                this.m_AnimationClipPlayable.SetRemoveStartOffset(this.removeStartOffset);
                Playable playable = animationClipPlayable;
                if (this.applyRootMotion)
                {
                    AnimationOffsetPlayable animationOffsetPlayable = AnimationOffsetPlayable.Create(graph, this.m_Position, this.m_Rotation, 1);
                    graph.Connect <AnimationClipPlayable, AnimationOffsetPlayable>(animationClipPlayable, 0, animationOffsetPlayable, 0);
                    animationOffsetPlayable.SetInputWeight(0, 1f);
                    playable = animationOffsetPlayable;
                }
                this.LiveLink();
                result = playable;
            }
            return(result);
        }
Example #3
0
        private Playable AttachOffsetPlayable(PlayableGraph graph, Playable playable, Vector3 pos, Quaternion rot)
        {
            var offsetPlayable = AnimationOffsetPlayable.Create(graph, pos, rot, 1);

            offsetPlayable.SetInputWeight(0, 1.0f);
            graph.Connect(playable, 0, offsetPlayable, 0);
            return(offsetPlayable);
        }
Example #4
0
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            AnimationClipPlayable animationClipPlayable = AnimationClipPlayable.Create(graph, this.m_Clip);

            this.m_AnimationClipPlayable = animationClipPlayable;
            this.m_AnimationClipPlayable.SetRemoveStartOffset(this.removeStartOffset);
            Playable result = animationClipPlayable;

            if (this.applyRootMotion)
            {
                AnimationOffsetPlayable animationOffsetPlayable = AnimationOffsetPlayable.Create(graph, this.m_Position, this.m_Rotation, 1);
                graph.Connect <AnimationClipPlayable, AnimationOffsetPlayable>(animationClipPlayable, 0, animationOffsetPlayable, 0);
                result = animationOffsetPlayable;
            }
            this.LiveLink();
            return(result);
        }
        private Playable ApplyTrackOffset(PlayableGraph graph, Playable root)
        {
            Playable result;

            if (!this.m_ApplyOffsets)
            {
                result = root;
            }
            else
            {
                AnimationOffsetPlayable animationOffsetPlayable = AnimationOffsetPlayable.Create(graph, this.m_Position, this.m_Rotation, 1);
                graph.Connect <Playable, AnimationOffsetPlayable>(root, 0, animationOffsetPlayable, 0);
                animationOffsetPlayable.SetInputWeight(0, 1f);
                result = animationOffsetPlayable;
            }
            return(result);
        }
Example #6
0
        Playable ApplyTrackOffset(PlayableGraph graph, Playable root, GameObject go, AppliedOffsetMode mode)
        {
#if UNITY_EDITOR
            m_ClipOffset = AnimationOffsetPlayable.Null;
#endif

            // offsets don't apply in scene offset, or if there is no root transform (globally or on this track)
            if (mode == AppliedOffsetMode.SceneOffsetLegacy ||
                mode == AppliedOffsetMode.SceneOffset ||
                mode == AppliedOffsetMode.NoRootTransform ||
                !AnimatesRootTransform()
                )
            {
                return(root);
            }


            var pos = position;
            var rot = rotation;

#if UNITY_EDITOR
            // in the editor use the preview position to playback from if available
            if (mode == AppliedOffsetMode.SceneOffsetEditor)
            {
                pos = m_SceneOffsetPosition;
                rot = Quaternion.Euler(m_SceneOffsetRotation);
            }
#endif

            var offsetPlayable = AnimationOffsetPlayable.Create(graph, pos, rot, 1);
#if UNITY_EDITOR
            m_ClipOffset = offsetPlayable;
#endif
            graph.Connect(root, 0, offsetPlayable, 0);
            offsetPlayable.SetInputWeight(0, 1);

            return(offsetPlayable);
        }
Example #7
0
 public static void AddDefaultHumanoidTrack(PlayableGraph graph, Playable rootPlayable, Animator animator)
 {
     if (!(AnimationDefaultTrack.defaultHumanoidClip == null))
     {
         Playable playable = new Playable(AnimationPlayableGraphExtensions.CreateAnimationMotionXToDeltaPlayable(graph));
         PlayableExtensions.SetInputCount <Playable>(playable, 1);
         AnimationOffsetPlayable animationOffsetPlayable = AnimationOffsetPlayable.Create(graph, Vector3.get_zero(), Quaternion.get_identity(), 1);
         AnimationClipPlayable   animationClipPlayable   = AnimationClipPlayable.Create(graph, AnimationDefaultTrack.defaultHumanoidClip);
         PlayableExtensions.SetTime <AnimationClipPlayable>(animationClipPlayable, 0.0);
         PlayableExtensions.SetSpeed <AnimationClipPlayable>(animationClipPlayable, 0.0);
         graph.Connect <AnimationOffsetPlayable, Playable>(animationOffsetPlayable, 0, playable, 0);
         PlayableExtensions.SetInputWeight <Playable>(playable, 0, 1f);
         graph.Connect <AnimationClipPlayable, AnimationOffsetPlayable>(animationClipPlayable, 0, animationOffsetPlayable, 0);
         PlayableExtensions.SetInputWeight <AnimationOffsetPlayable>(animationOffsetPlayable, 0, 1f);
         int inputCount = PlayableExtensions.GetInputCount <Playable>(rootPlayable);
         PlayableExtensions.SetInputCount <Playable>(rootPlayable, inputCount + 1);
         graph.Connect <Playable, Playable>(playable, 0, rootPlayable, inputCount);
         PlayableExtensions.SetInputWeight <Playable>(rootPlayable, inputCount, 1f);
         AnimationPlayableOutput animationPlayableOutput = AnimationPlayableOutput.Create(graph, "DefaultHumanoid", animator);
         PlayableOutputExtensions.SetSourcePlayable <AnimationPlayableOutput, Playable>(animationPlayableOutput, rootPlayable);
         PlayableOutputExtensions.SetSourceInputPort <AnimationPlayableOutput>(animationPlayableOutput, inputCount);
     }
 }
Example #8
0
        internal override Playable OnCreateClipPlayableGraph(PlayableGraph graph, GameObject go, IntervalTree <RuntimeElement> tree)
        {
            if (isSubTrack)
            {
                throw new InvalidOperationException("Nested animation tracks should never be asked to create a graph directly");
            }

            List <AnimationTrack> flattenTracks = new List <AnimationTrack>();

            if (CanCompileClips())
            {
                flattenTracks.Add(this);
            }


            bool animatesRootTransform = AnimatesRootTransform();

            foreach (var subTrack in GetChildTracks())
            {
                var child = subTrack as AnimationTrack;
                if (child != null && child.CanCompileClips())
                {
                    animatesRootTransform |= child.AnimatesRootTransform();
                    flattenTracks.Add(child);
                }
            }

            // figure out which mode to apply
            AppliedOffsetMode mode = GetOffsetMode(go, animatesRootTransform);
            var layerMixer         = CreateGroupMixer(graph, go, flattenTracks.Count);

            for (int c = 0; c < flattenTracks.Count; c++)
            {
                var compiledTrackPlayable = flattenTracks[c].inClipMode ?
                                            CompileTrackPlayable(graph, flattenTracks[c], go, tree, mode) :
                                            flattenTracks[c].CreateInfiniteTrackPlayable(graph, go, tree, mode);
                graph.Connect(compiledTrackPlayable, 0, layerMixer, c);
                layerMixer.SetInputWeight(c, flattenTracks[c].inClipMode ? 0 : 1);
                if (flattenTracks[c].applyAvatarMask && flattenTracks[c].avatarMask != null)
                {
                    layerMixer.SetLayerMaskFromAvatarMask((uint)c, flattenTracks[c].avatarMask);
                }
            }

            Playable mixer = (Playable)layerMixer;

#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                var motionXMixer = AnimationMixerPlayable.Create(graph, 2);

                var      animator     = GetBinding(go != null ? go.GetComponent <PlayableDirector>() : null);
                Playable blendDefault = Playable.Null;
                if (animator != null && animator.isHuman)
                {
                    blendDefault = AnimationClipPlayable.Create(graph, GetDefaultHumanoidClip());
                }
                else
                {
                    blendDefault = AnimationPosePlayable.Create(graph);
                    ((AnimationPosePlayable)blendDefault).SetReadDefaultPose(true);
                }

                var offsetPlayable = AnimationOffsetPlayable.Create(graph, m_SceneOffsetPosition, Quaternion.Euler(m_SceneOffsetRotation), 1);

                graph.Connect(blendDefault, 0, offsetPlayable, 0);
                graph.Connect(layerMixer, 0, motionXMixer, 0);
                graph.Connect(offsetPlayable, 0, motionXMixer, 1);

                offsetPlayable.SetInputWeight(0, 1.0f);
                motionXMixer.SetInputWeight(1, 1.0f);
                motionXMixer.SetInputWeight(0, 0.0f);

                mixer = (Playable)motionXMixer;
            }
#endif

            // motionX playable not required in scene offset mode, or root transform mode
            if (!RequiresMotionXPlayable(mode, go))
            {
                return(mixer);
            }

            // If we are animating a root transform, add the motionX to delta playable as the root node
            var motionXToDelta = AnimationMotionXToDeltaPlayable.Create(graph);
            graph.Connect(mixer, 0, motionXToDelta, 0);
            motionXToDelta.SetInputWeight(0, 1.0f);
            motionXToDelta.SetAbsoluteMotion(UsesAbsoluteMotion(mode));
            return(motionXToDelta);
        }