예제 #1
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);
        }
예제 #2
0
        // Creates a complete clone of a track and returns it.
        // Does not parent, or add the track to the sequence
        public static TrackAsset Clone(PlayableAsset parent, TrackAsset trackAsset, IExposedPropertyTable sourceTable, IExposedPropertyTable destTable, PlayableAsset assetOwner = null)
        {
            if (trackAsset == null)
            {
                return(null);
            }

            var timelineAsset = trackAsset.timelineAsset;

            if (timelineAsset == null)
            {
                return(null);
            }

            if (assetOwner == null)
            {
                assetOwner = parent;
            }

            // create a duplicate, then clear the clips and subtracks
            var newTrack = Object.Instantiate(trackAsset);

            newTrack.name = trackAsset.name;
            newTrack.ClearClipsInternal();
            newTrack.parent = parent;
            newTrack.ClearSubTracksInternal();

            if (trackAsset.hasCurves)
            {
                newTrack.curves = CloneAnimationClip(trackAsset.curves, assetOwner);
            }

            var animTrack = trackAsset as AnimationTrack;

            if (animTrack != null && animTrack.infiniteClip != null)
            {
                ((AnimationTrack)newTrack).infiniteClip = CloneAnimationClip(animTrack.infiniteClip, assetOwner);
            }

            foreach (var clip in trackAsset.clips)
            {
                var newClip = DuplicateClip(clip, sourceTable, destTable, assetOwner);
                newClip.parentTrack = newTrack;
            }

            newTrack.ClearMarkers();
            foreach (var e in trackAsset.GetMarkersRaw())
            {
                var newMarker = Object.Instantiate(e);
                newTrack.AddMarker(newMarker);
                SaveCloneToAsset(newMarker, assetOwner);
                if (newMarker is IMarker)
                {
                    (newMarker as IMarker).Initialize(newTrack);
                }
            }

            newTrack.SetCollapsed(trackAsset.GetCollapsed());

            // calling code is responsible for adding to asset, adding to sequence, and parenting,
            // and duplicating subtracks
            return(newTrack);
        }