Ejemplo n.º 1
0
        public static Animator GetAnimator(TrackAsset asset, PlayableDirector director)
        {
            AnimationTrack animationTrack = asset as AnimationTrack;
            Animator       result;

            if (animationTrack != null && !animationTrack.isSubTrack)
            {
                Object genericBinding = director.GetGenericBinding(animationTrack);
                if (genericBinding == null)
                {
                    result = null;
                }
                else
                {
                    Animator   animator   = genericBinding as Animator;
                    GameObject gameObject = genericBinding as GameObject;
                    if (animator == null && gameObject != null)
                    {
                        animator = gameObject.GetComponent <Animator>();
                    }
                    result = animator;
                }
            }
            else
            {
                result = null;
            }
            return(result);
        }
Ejemplo n.º 2
0
        private void DeleteRecordingClip(TrackAsset track)
        {
            AnimationTrack animationTrack = track as AnimationTrack;

            if (!(animationTrack == null) && !(animationTrack.animClip == null))
            {
                TimelineUndo.PushDestroyUndo(this, track, animationTrack.animClip, "Delete Track");
            }
        }
Ejemplo n.º 3
0
        private static void ReplaceAnimationTrackClips(AnimationTrack track, AnimationClip newClip, Dictionary <AnimationPlayableAsset, AnimationClip> map)
        {
            foreach (var clip in track.GetClips())
            {
                var animationPlayableAsset = (AnimationPlayableAsset)clip.asset;

                map[animationPlayableAsset] = animationPlayableAsset.clip;
                animationPlayableAsset.clip = newClip;
            }
        }
Ejemplo n.º 4
0
            public static void ConvertRootMotion(AnimationTrack track)
            {
                track.m_TrackOffset = TrackOffset.Auto; // loaded tracks should use legacy mode

                // reset offsets if not applied
                if (!track.m_ApplyOffsets)
                {
                    track.m_Position    = Vector3.zero;
                    track.m_EulerAngles = Vector3.zero;
                }
            }
Ejemplo n.º 5
0
        internal override Playable OnCreatePlayableGraph(PlayableGraph graph, GameObject go, IntervalTree <RuntimeElement> tree)
        {
            if (base.isSubTrack)
            {
                throw new InvalidOperationException("Nested animation tracks should never be asked to create a graph directly");
            }
            List <AnimationTrack> list = new List <AnimationTrack>();

            if (this.compilableIsolated)
            {
                list.Add(this);
            }
            foreach (TrackAsset trackAsset in base.GetChildTracks())
            {
                AnimationTrack animationTrack = trackAsset as AnimationTrack;
                if (animationTrack != null && animationTrack.compilable)
                {
                    list.Add(animationTrack);
                }
            }
            AnimationMotionXToDeltaPlayable animationMotionXToDeltaPlayable = AnimationMotionXToDeltaPlayable.Create(graph);
            AnimationLayerMixerPlayable     animationLayerMixerPlayable     = AnimationTrack.CreateGroupMixer(graph, go, list.Count);

            graph.Connect <AnimationLayerMixerPlayable, AnimationMotionXToDeltaPlayable>(animationLayerMixerPlayable, 0, animationMotionXToDeltaPlayable, 0);
            animationMotionXToDeltaPlayable.SetInputWeight(0, 1f);
            for (int i = 0; i < list.Count; i++)
            {
                Playable source = (!list[i].inClipMode) ? list[i].CreateInfiniteTrackPlayable(graph, go, tree) : this.CompileTrackPlayable(graph, list[i], go, tree);
                graph.Connect <Playable, AnimationLayerMixerPlayable>(source, 0, animationLayerMixerPlayable, i);
                animationLayerMixerPlayable.SetInputWeight(i, (float)((!list[i].inClipMode) ? 1 : 0));
                if (list[i].applyAvatarMask && list[i].avatarMask != null)
                {
                    animationLayerMixerPlayable.SetLayerMaskFromAvatarMask((uint)i, list[i].avatarMask);
                }
            }
            return(animationMotionXToDeltaPlayable);
        }
Ejemplo n.º 6
0
        Playable CompileTrackPlayable(PlayableGraph graph, AnimationTrack track, GameObject go, IntervalTree <RuntimeElement> tree, AppliedOffsetMode mode)
        {
            var mixer = AnimationMixerPlayable.Create(graph, track.clips.Length);

            for (int i = 0; i < track.clips.Length; i++)
            {
                var c     = track.clips[i];
                var asset = c.asset as PlayableAsset;
                if (asset == null)
                {
                    continue;
                }

                var animationAsset = asset as AnimationPlayableAsset;
                if (animationAsset != null)
                {
                    animationAsset.appliedOffsetMode = mode;
                }

                var source = asset.CreatePlayable(graph, go);
                if (source.IsValid())
                {
                    var clip = new RuntimeClip(c, source, mixer);
                    tree.Add(clip);
                    graph.Connect(source, 0, mixer, i);
                    mixer.SetInputWeight(i, 0.0f);
                }
            }

            if (!track.AnimatesRootTransform())
            {
                return(mixer);
            }

            return(ApplyTrackOffset(graph, mixer, go, mode));
        }
Ejemplo n.º 7
0
 public static void ConvertInfiniteTrack(AnimationTrack track)
 {
     track.m_InfiniteClip = track.m_AnimClip;
     track.m_AnimClip     = null;
 }
Ejemplo n.º 8
0
 public static void ConvertRotationsToEuler(AnimationTrack track)
 {
     track.m_EulerAngles = track.m_Rotation.eulerAngles;
     track.m_InfiniteClipOffsetEulerAngles = track.m_OpenClipOffsetRotation.eulerAngles;
 }