public static void ComputeClipWorldSpaceOffset(PlayableDirector director, TimelineClip clip, out Vector3 clipPositionOffset, out Quaternion clipRotationOffset)
        {
            GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(director, clip.parentTrack);
            double     time            = director.get_time();
            TrackAsset parentTrack     = clip.parentTrack;

            TimelineClip[] clips = parentTrack.clips;
            director.Stop();
            for (int i = 0; i < clips.Length; i++)
            {
                parentTrack.RemoveClip(clips[i]);
            }
            parentTrack.AddClip(clip);
            double start           = clip.start;
            double blendInDuration = clip.blendInDuration;

            clip.blendInDuration = 0.0;
            clip.start           = 1.0;
            director.Play();
            director.set_time(0.0);
            director.Evaluate();
            clipPositionOffset = sceneGameObject.get_transform().get_position();
            clipRotationOffset = sceneGameObject.get_transform().get_rotation();
            AnimationPlayableAsset animationPlayableAsset = clip.asset as AnimationPlayableAsset;

            if (!(animationPlayableAsset == null))
            {
                clipPositionOffset += clipRotationOffset * animationPlayableAsset.position;
                clipRotationOffset *= animationPlayableAsset.rotation;
                director.Stop();
                clip.start           = start;
                clip.blendInDuration = blendInDuration;
                parentTrack.RemoveClip(clip);
                for (int j = 0; j < clips.Length; j++)
                {
                    parentTrack.AddClip(clips[j]);
                }
                director.Play();
                director.set_time(time);
                director.Evaluate();
            }
        }
Example #2
0
        public static TimelineClip DuplicateAtTime(this TimelineClip clip, TrackAsset track, double time, PlayableDirector director)
        {
            TimelineUndo.PushUndo(track, "Clone Clip");
            TimelineClip timelineClip = TimelineHelpers.Clone(clip, director);

            timelineClip.start       = time;
            timelineClip.parentTrack = track;
            track.AddClip(timelineClip);
            track.SortClips();
            TrackExtensions.ComputeBlendsFromOverlaps(track.clips);
            return(timelineClip);
        }
        public static void ComputeTrackOffsets(PlayableDirector director, TimelineClip clip, out Vector3 parentPositionOffset, out Quaternion parentRotationOffset, out Vector3 positionOffset, out Quaternion rotationOffset)
        {
            GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(director, clip.parentTrack);
            double     time            = director.get_time();
            TrackAsset parentTrack     = clip.parentTrack;

            TimelineClip[] clips = parentTrack.clips;
            director.Stop();
            for (int i = 0; i < clips.Length; i++)
            {
                parentTrack.RemoveClip(clips[i]);
            }
            parentTrack.AddClip(clip);
            double start           = clip.start;
            double blendInDuration = clip.blendInDuration;

            clip.blendInDuration = 0.0;
            clip.start           = 1.0;
            director.Play();
            director.set_time(1.0);
            director.Evaluate();
            positionOffset = sceneGameObject.get_transform().get_position();
            rotationOffset = sceneGameObject.get_transform().get_rotation();
            director.set_time(0.0);
            director.Evaluate();
            parentPositionOffset = sceneGameObject.get_transform().get_position();
            parentRotationOffset = sceneGameObject.get_transform().get_rotation();
            director.Stop();
            clip.start           = start;
            clip.blendInDuration = blendInDuration;
            parentTrack.RemoveClip(clip);
            for (int j = 0; j < clips.Length; j++)
            {
                parentTrack.AddClip(clips[j]);
            }
            director.Play();
            director.set_time(time);
            director.Evaluate();
        }
Example #4
0
        public static TrackAsset Clone(PlayableAsset parent, TrackAsset trackAsset, PlayableDirector directorInstance)
        {
            TrackAsset result;

            if (trackAsset == null)
            {
                result = null;
            }
            else
            {
                TimelineAsset timelineAsset = trackAsset.timelineAsset;
                if (timelineAsset == null)
                {
                    result = null;
                }
                else
                {
                    TrackAsset trackAsset2 = Object.Instantiate <TrackAsset>(trackAsset);
                    trackAsset2.SetClips(new List <TimelineClip>());
                    trackAsset2.parent    = parent;
                    trackAsset2.subTracks = new List <TrackAsset>();
                    string[] array = (from x in timelineAsset.flattenedTracks
                                      select x.get_name()).ToArray <string>();
                    trackAsset2.set_name(ObjectNames.GetUniqueName(array, trackAsset.get_name()));
                    if (trackAsset.animClip != null)
                    {
                        trackAsset2.animClip = TimelineHelpers.CloneAnimationClipIfRequired(trackAsset.animClip, trackAsset);
                    }
                    TimelineClip[] clips = trackAsset.clips;
                    for (int i = 0; i < clips.Length; i++)
                    {
                        TimelineClip clip         = clips[i];
                        TimelineClip timelineClip = TimelineHelpers.Clone(clip, directorInstance);
                        timelineClip.parentTrack = trackAsset2;
                        trackAsset2.AddClip(timelineClip);
                    }
                    trackAsset2.SetCollapsed(trackAsset.GetCollapsed());
                    if (SelectionManager.Contains(trackAsset))
                    {
                        SelectionManager.Remove(trackAsset);
                        SelectionManager.Add(trackAsset2);
                    }
                    result = trackAsset2;
                }
            }
            return(result);
        }