internal static void ConvertFromClipMode(this AnimationTrack track, TimelineAsset timeline)
        {
            if (!track.CanConvertFromClipMode())
            {
                return;
            }

            UndoExtensions.RegisterTrack(track, L10n.Tr("Convert From Clip"));

            var clip  = track.clips[0];
            var delta = (float)clip.start;

            track.infiniteClipTimeOffset        = 0.0f;
            track.infiniteClipPreExtrapolation  = clip.preExtrapolationMode;
            track.infiniteClipPostExtrapolation = clip.postExtrapolationMode;

            var animAsset = clip.asset as AnimationPlayableAsset;

            if (animAsset)
            {
                track.infiniteClipOffsetPosition    = animAsset.position;
                track.infiniteClipOffsetEulerAngles = animAsset.eulerAngles;
                track.infiniteClipRemoveOffset      = animAsset.removeStartOffset;
                track.infiniteClipApplyFootIK       = animAsset.applyFootIK;
                track.infiniteClipLoop = animAsset.loop;
            }

            // clone it, it may not be in the same asset
            var animClip = clip.animationClip;

            float scale = (float)clip.timeScale;

            if (!Mathf.Approximately(scale, 1.0f))
            {
                if (!Mathf.Approximately(scale, 0.0f))
                {
                    scale = 1.0f / scale;
                }
                animClip.ScaleTime(scale);
            }

            TimelineUndo.PushUndo(animClip, L10n.Tr("Convert From Clip"));
            animClip.ShiftBySeconds(delta);

            // manually delete the clip
            var asset = clip.asset;

            clip.asset = null;

            // Remove the clip, remove old assets
            ClipModifier.Delete(timeline, clip);
            TimelineUndo.PushDestroyUndo(null, track, asset);

            track.infiniteClip = animClip;

            EditorUtility.SetDirty(track);
        }
Ejemplo n.º 2
0
        public override void OnBuildTrackContextMenu(GenericMenu menu, TrackAsset track, ITimelineState state)
        {
            base.OnBuildTrackContextMenu(menu, track, state);
            bool           flag      = false;
            AnimationTrack animTrack = track as AnimationTrack;

            if (animTrack != null)
            {
                if (animTrack.CanConvertFromClipMode() || animTrack.CanConvertToClipMode())
                {
                    bool flag2 = animTrack.CanConvertFromClipMode();
                    bool flag3 = animTrack.CanConvertToClipMode();
                    if (flag2)
                    {
                        menu.AddItem(EditorGUIUtility.TextContent("Convert To Infinite Clip"), false, delegate(object parentTrack)
                        {
                            animTrack.ConvertFromClipMode(state.timeline);
                        }, track);
                        flag = true;
                    }
                    if (flag3)
                    {
                        menu.AddItem(EditorGUIUtility.TextContent("Convert To Clip Track"), false, delegate(object parentTrack)
                        {
                            animTrack.ConvertToClipMode();
                            state.Refresh();
                        }, track);
                    }
                }
            }
            if (!track.isSubTrack)
            {
                if (flag)
                {
                    menu.AddSeparator("");
                }
                menu.AddItem(EditorGUIUtility.TextContent("Add Override Track"), false, delegate(object parentTrack)
                {
                    AnimationTrackDrawer.AddSubTrack(state, typeof(AnimationTrack), "Override " + track.subTracks.Count.ToString(), track);
                }, track);
            }
        }
 public static void ConvertFromClipMode(this AnimationTrack track, TimelineAsset timeline)
 {
     if (track.CanConvertFromClipMode())
     {
         TimelineUndo.PushUndo(track, "Convert From Clip");
         TimelineClip timelineClip = track.clips[0];
         float        time         = (float)timelineClip.start;
         track.openClipTimeOffset        = 0.0;
         track.openClipPreExtrapolation  = timelineClip.preExtrapolationMode;
         track.openClipPostExtrapolation = timelineClip.postExtrapolationMode;
         AnimationPlayableAsset animationPlayableAsset = timelineClip.asset as AnimationPlayableAsset;
         if (animationPlayableAsset)
         {
             track.openClipOffsetPosition = animationPlayableAsset.position;
             track.openClipOffsetRotation = animationPlayableAsset.rotation;
         }
         AnimationClip animationClip = timelineClip.animationClip;
         float         num           = (float)timelineClip.timeScale;
         if (!Mathf.Approximately(num, 1f))
         {
             if (!Mathf.Approximately(num, 0f))
             {
                 num = 1f / num;
             }
             animationClip.ScaleTime(num);
         }
         TimelineUndo.PushUndo(animationClip, "Convert From Clip");
         animationClip.ShiftBySeconds(time);
         Object asset = timelineClip.asset;
         timelineClip.asset = null;
         ClipModifier.Delete(timeline, timelineClip);
         TimelineUndo.PushDestroyUndo(null, track, asset, "Convert From Clip");
         track.animClip = animationClip;
         EditorUtility.SetDirty(track);
     }
 }