示例#1
0
        public static TrackAsset CreateTrack(TimelineAsset asset, Type type, TrackAsset parent = null, string name = null)
        {
            if (asset == null)
            {
                return(null);
            }

            var track = asset.CreateTrack(type, parent, name);

            if (track != null)
            {
                if (parent != null)
                {
                    parent.SetCollapsed(false);
                }

                var editor = CustomTimelineEditorCache.GetTrackEditor(track);
                try
                {
                    editor.OnCreate(track, null);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
                TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
            }

            return(track);
        }
示例#2
0
        internal static void RecursiveSubtrackClone(TrackAsset source, TrackAsset duplicate, PlayableDirector director, PlayableAsset assetOwner)
        {
            var subtracks = source.GetChildTracks();

            foreach (var sub in subtracks)
            {
                var newSub = TimelineHelpers.Clone(duplicate, sub, director, assetOwner);
                duplicate.AddChild(newSub);
                RecursiveSubtrackClone(sub, newSub, director, assetOwner);

                // Call the custom editor on Create
                var customEditor = CustomTimelineEditorCache.GetTrackEditor(newSub);
                try
                {
                    customEditor.OnCreate(newSub, sub);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }

                // registration has to happen AFTER recursion
                TimelineUndo.RegisterCreatedObjectUndo(newSub, "Duplicate");
                TimelineCreateUtilities.SaveAssetIntoObject(newSub, assetOwner);
            }
        }
示例#3
0
        public virtual void OnEnable()
        {
            m_IsBuiltInType      = target != null && target.GetType().Assembly == typeof(TrackAsset).Assembly;
            m_Name               = serializedObject.FindProperty("m_Name");
            m_TrackCurvesWrapper = new TrackCurvesWrapper(target as TrackAsset);
            m_HeaderIcon         = TrackResourceCache.s_DefaultIcon.image;

            // only worry about the first track. if types are different, a different inspector is used.
            var track = target as TrackAsset;

            if (track != null)
            {
                var drawer = CustomTimelineEditorCache.GetTrackEditor(track);
                UnityEngine.Object binding = null;
                var director = m_Context as PlayableDirector;
                if (director != null)
                {
                    binding = director.GetGenericBinding(track);
                }

                var options = drawer.GetTrackOptions(track, binding);
                if (options.icon != null)
                {
                    m_HeaderIcon = options.icon;
                }
                else
                {
                    m_HeaderIcon = TrackResourceCache.GetTrackIcon(track).image;
                }
            }
        }
        public static void BindWithEditorValidation(PlayableDirector director, TrackAsset bindTo, Object objectToBind)
        {
            TrackEditor trackEditor     = CustomTimelineEditorCache.GetTrackEditor(bindTo);
            Object      validatedObject = trackEditor.GetBindingFrom_Safe(objectToBind, bindTo);

            Bind(director, bindTo, validatedObject);
        }
示例#5
0
        public TimelineTrackGUI(TreeViewController tv, TimelineTreeViewGUI w, int id, int depth, TreeViewItem parent, string displayName, TrackAsset sequenceActor)
            : base(tv, w, id, depth, parent, displayName, sequenceActor, false)
        {
            AnimationTrack animationTrack = sequenceActor as AnimationTrack;

            if (animationTrack != null)
            {
                m_InfiniteTrackDrawer = new InfiniteTrackDrawer(new AnimationTrackKeyDataSource(animationTrack));
            }
            else if (sequenceActor.HasAnyAnimatableParameters() && !sequenceActor.clips.Any())
            {
                m_InfiniteTrackDrawer = new InfiniteTrackDrawer(new TrackPropertyCurvesDataSource(sequenceActor));
            }

            UpdateInfiniteClipEditor(w.TimelineWindow);

            var bindings = track.outputs.ToArray();

            m_TrackDrawData.m_HasBinding = bindings.Length > 0;
            if (m_TrackDrawData.m_HasBinding)
            {
                m_TrackDrawData.m_Binding = bindings[0];
            }
            m_TrackDrawData.m_IsSubTrack      = IsSubTrack();
            m_TrackDrawData.m_AllowsRecording = DoesTrackAllowsRecording(sequenceActor);
            m_DefaultTrackIcon = TrackResourceCache.GetTrackIcon(track);


            m_TrackEditor = CustomTimelineEditorCache.GetTrackEditor(sequenceActor);

            try
            {
                m_TrackDrawOptions = m_TrackEditor.GetTrackOptions(track, null);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_TrackDrawOptions = CustomTimelineEditorCache.GetDefaultTrackEditor().GetTrackOptions(track, null);
            }

            m_TrackDrawOptions.errorText = null; // explicitly setting to null for an uninitialized state

            RebuildGUICacheIfNecessary();
        }
        static void RecursiveSubtrackClone(TrackAsset source, TrackAsset duplicate, IExposedPropertyTable sourceTable, IExposedPropertyTable destTable, PlayableAsset assetOwner)
        {
            var subtracks = source.GetChildTracks();

            foreach (var sub in subtracks)
            {
                var newSub = TimelineHelpers.Clone(duplicate, sub, sourceTable, destTable, assetOwner);
                duplicate.AddChild(newSub);
                RecursiveSubtrackClone(sub, newSub, sourceTable, destTable, assetOwner);

                // Call the custom editor on Create
                var customEditor = CustomTimelineEditorCache.GetTrackEditor(newSub);
                customEditor.OnCreate_Safe(newSub, sub);

                // registration has to happen AFTER recursion
                TimelineCreateUtilities.SaveAssetIntoObject(newSub, assetOwner);
                TimelineUndo.RegisterCreatedObjectUndo(newSub, L10n.Tr("Duplicate"));
            }
        }
        public static void BindWithInteractiveEditorValidation(PlayableDirector director, TrackAsset bindTo, Object objectToBind)
        {
            TrackEditor trackEditor = CustomTimelineEditorCache.GetTrackEditor(bindTo);

            if (trackEditor.SupportsBindingAssign())
            {
                BindWithEditorValidation(director, bindTo, objectToBind);
            }
            else
            {
                Type          bindingType = TypeUtility.GetTrackBindingAttribute(bindTo.GetType())?.type;
                BindingAction action      = GetBindingAction(bindingType, objectToBind);
                if (action == BindingAction.BindToMissingComponent)
                {
                    InteractiveBindToMissingComponent(director, bindTo, objectToBind, bindingType);
                }
                else
                {
                    var validatedObject = GetBinding(action, objectToBind, bindingType);
                    Bind(director, bindTo, validatedObject);
                }
            }
        }
示例#8
0
        internal static TrackAsset Duplicate(this TrackAsset track, PlayableDirector director,
                                             TimelineAsset destinationTimeline = null)
        {
            if (track == null)
            {
                return(null);
            }

            // if the destination is us, clear to avoid bad parenting (case 919421)
            if (destinationTimeline == track.timelineAsset)
            {
                destinationTimeline = null;
            }

            var timelineParent = track.parent as TimelineAsset;
            var trackParent    = track.parent as TrackAsset;

            if (timelineParent == null && trackParent == null)
            {
                Debug.LogWarning("Cannot duplicate track because it is not parented to known type");
                return(null);
            }

            // Determine who the final parent is. If we are pasting into another track, it's always the timeline.
            //  Otherwise it's the original parent
            PlayableAsset finalParent = destinationTimeline != null ? destinationTimeline : track.parent;

            // grab the list of tracks to generate a name from (923360) to get the list of names
            // no need to do this part recursively
            var finalTrackParent   = finalParent as TrackAsset;
            var finalTimelineAsset = finalParent as TimelineAsset;
            var otherTracks        = (finalTimelineAsset != null) ? finalTimelineAsset.trackObjects : finalTrackParent.subTracksObjects;

            // Important to create the new objects before pushing the original undo, or redo breaks the
            //  sequence
            var newTrack = TimelineHelpers.Clone(finalParent, track, director, finalParent);

            newTrack.name = TimelineCreateUtilities.GenerateUniqueActorName(otherTracks, newTrack.name);

            RecursiveSubtrackClone(track, newTrack, director, finalParent);
            TimelineUndo.RegisterCreatedObjectUndo(newTrack, "Duplicate");
            TimelineCreateUtilities.SaveAssetIntoObject(newTrack, finalParent);
            TimelineUndo.PushUndo(finalParent, "Duplicate");

            if (destinationTimeline != null) // other timeline
            {
                destinationTimeline.AddTrackInternal(newTrack);
            }
            else if (timelineParent != null) // this timeline, no parent
            {
                ReparentTracks(new List <TrackAsset> {
                    newTrack
                }, timelineParent, timelineParent.GetRootTracks().Last(), false);
            }
            else // this timeline, with parent
            {
                trackParent.AddChild(newTrack);
            }

            // Call the custom editor. this check prevents the call when copying to the clipboard
            if (destinationTimeline == null || destinationTimeline == TimelineEditor.inspectedAsset)
            {
                var customEditor = CustomTimelineEditorCache.GetTrackEditor(newTrack);
                try
                {
                    customEditor.OnCreate(newTrack, track);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            return(newTrack);
        }