Exemplo n.º 1
0
        private TimelineClip CreateAndAddNewClipOfType(Type requestedType)
        {
            ScriptableObject scriptableObject = ScriptableObject.CreateInstance(requestedType);

            if (scriptableObject == null)
            {
                throw new InvalidOperationException("Could not create an instance of the ScriptableObject type " + requestedType.Name);
            }
            scriptableObject.name = requestedType.Name;
            TimelineCreateUtilities.SaveAssetIntoObject(scriptableObject, this);
            TimelineClip timelineClip = this.CreateNewClipContainerInternal();

            timelineClip.displayName = scriptableObject.name;
            timelineClip.asset       = scriptableObject;
            try
            {
                this.OnCreateClipFromAsset(scriptableObject, timelineClip);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message, scriptableObject);
                return(null);
            }
            this.AddClip(timelineClip);
            return(timelineClip);
        }
Exemplo n.º 2
0
        public IMarker CreateMarker(Type type, double time, TrackAsset owner)
        {
            if (!typeof(ScriptableObject).IsAssignableFrom(type) || !typeof(IMarker).IsAssignableFrom(type))
            {
                throw new InvalidOperationException(
                    "The requested type needs to inherit from ScriptableObject and implement IMarker");
            }
            if (!owner.supportsNotifications && typeof(INotification).IsAssignableFrom(type))
            {
                throw new InvalidOperationException(
                    "Markers implementing the INotification interface cannot be added on tracks that do not support notifications");
            }

            var markerSO = ScriptableObject.CreateInstance(type);
            var marker = (IMarker)markerSO;
            marker.time = time;

            TimelineCreateUtilities.SaveAssetIntoObject(markerSO, owner);
            TimelineUndo.RegisterCreatedObjectUndo(markerSO, "Create " + type.Name);
            TimelineUndo.PushUndo(owner, "Create " + type.Name);

            Add(markerSO);
            marker.Initialize(owner);

            return marker;
        }
        TrackAsset AllocateTrack(TrackAsset trackAssetParent, string trackName, Type trackType)
        {
            if (trackAssetParent != null && trackAssetParent.timelineAsset != this)
            {
                throw new InvalidOperationException("Addtrack cannot parent to a track not in the Timeline");
            }

            if (!typeof(TrackAsset).IsAssignableFrom(trackType))
            {
                throw new InvalidOperationException("Supplied type must be a track asset");
            }

            var asset = (TrackAsset)CreateInstance(trackType);

            asset.name = trackName;

            const string createTrackUndoName = "Create Track";

            PlayableAsset parent = trackAssetParent != null ? trackAssetParent as PlayableAsset : this;

            TimelineCreateUtilities.SaveAssetIntoObject(asset, parent);
            TimelineUndo.RegisterCreatedObjectUndo(asset, createTrackUndoName);
            TimelineUndo.PushUndo(parent, createTrackUndoName);

            if (trackAssetParent != null)
            {
                trackAssetParent.AddChild(asset);
            }
            else //TimelineAsset is the parent
            {
                AddTrackInternal(asset);
            }

            return(asset);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a marker track for the TimelineAsset.
 /// </summary>
 /// In the editor, the marker track appears under the Timeline ruler.
 /// <remarks>
 /// This track is always bound to the GameObject that contains the PlayableDirector component for the current timeline.
 /// The marker track is created the first time this method is called. If the marker track is already created, this method does nothing.
 /// </remarks>
 public void CreateMarkerTrack()
 {
     if (m_MarkerTrack == null)
     {
         m_MarkerTrack = CreateInstance <MarkerTrack>();
         TimelineCreateUtilities.SaveAssetIntoObject(m_MarkerTrack, this);
         m_MarkerTrack.parent = this;
         m_MarkerTrack.name   = "Markers"; // This name will show up in the bindings list if it contains signals
         Invalidate();
     }
 }
        /// <summary>
        /// Allows you to create a track and add it to the Timeline.
        /// </summary>
        /// <param name="type">The type of track to create. Must derive from TrackAsset.</param>
        /// <param name="parent">Track to parent to. This can be null.</param>
        /// <param name="name">Name to give the track.</param>
        /// <returns>The created track.</returns>
        /// <remarks>
        /// This method will throw an InvalidOperationException if the parent is not valid. The parent can be any GroupTrack, or a supported parent type of track. For example, this can be used to create override tracks in AnimationTracks.
        /// </remarks>
        public TrackAsset CreateTrack(Type type, TrackAsset parent, string name)
        {
            if (parent != null && parent.timelineAsset != this)
            {
                throw new InvalidOperationException("Addtrack cannot parent to a track not in the Timeline");
            }

            if (!typeof(TrackAsset).IsAssignableFrom(type))
            {
                throw new InvalidOperationException("Supplied type must be a track asset");
            }

            if (parent != null)
            {
                if (!TimelineCreateUtilities.ValidateParentTrack(parent, type))
                {
                    throw new InvalidOperationException("Cannot assign a child of type " + type.Name + " to a parent of type " + parent.GetType().Name);
                }
            }


            var actualParent = parent != null ? parent as PlayableAsset : this;

            TimelineUndo.PushUndo(actualParent, "Create Track");

            var baseName = name;

            if (string.IsNullOrEmpty(baseName))
            {
                baseName = type.Name;
#if UNITY_EDITOR
                baseName = UnityEditor.ObjectNames.NicifyVariableName(baseName);
#endif
            }

            var trackName = baseName;
            if (parent != null)
            {
                trackName = TimelineCreateUtilities.GenerateUniqueActorName(parent.subTracksObjects, baseName);
            }
            else
            {
                trackName = TimelineCreateUtilities.GenerateUniqueActorName(trackObjects, baseName);
            }

            TrackAsset newTrack = AllocateTrack(parent, trackName, type);
            if (newTrack != null)
            {
                newTrack.name = trackName;
                TimelineCreateUtilities.SaveAssetIntoObject(newTrack, actualParent);
            }
            return(newTrack);
        }
Exemplo n.º 6
0
        internal TimelineClip CreateClipOfType(Type requestedType)
        {
            if (!ValidateClipType(requestedType))
                throw new System.InvalidOperationException("Clips of type " + requestedType + " are not permitted on tracks of type " + GetType());

            var playableAsset = CreateInstance(requestedType);
            if (playableAsset == null)
            {
                throw new System.InvalidOperationException("Could not create an instance of the ScriptableObject type " + requestedType.Name);
            }
            playableAsset.name = requestedType.Name;
            TimelineCreateUtilities.SaveAssetIntoObject(playableAsset, this);
            TimelineUndo.RegisterCreatedObjectUndo(playableAsset, "Create Clip");

            return CreateClipFromAsset(playableAsset);
        }
Exemplo n.º 7
0
        internal override void OnCreateClipFromAsset(Object asset, TimelineClip clip)
        {
            AnimationClip animationClip = asset as AnimationClip;

            if (animationClip != null)
            {
                if (animationClip.legacy)
                {
                    throw new InvalidOperationException("Legacy Animation Clips are not supported");
                }
                AnimationPlayableAsset animationPlayableAsset = ScriptableObject.CreateInstance <AnimationPlayableAsset>();
                TimelineCreateUtilities.SaveAssetIntoObject(animationPlayableAsset, this);
                animationPlayableAsset.clip = animationClip;
                clip.asset = animationPlayableAsset;
                this.AssignAnimationClip(clip, animationClip);
            }
        }
Exemplo n.º 8
0
        public TrackAsset CreateTrack(Type type, TrackAsset parent, string name)
        {
            if (parent != null && parent.timelineAsset != this)
            {
                throw new InvalidOperationException("Addtrack cannot parent to a track not in the Timeline");
            }
            if (!typeof(TrackAsset).IsAssignableFrom(type))
            {
                throw new InvalidOperationException("Supplied type must be a track asset");
            }
            if (parent != null)
            {
                if (!TimelineCreateUtilities.ValidateParentTrack(parent, type))
                {
                    throw new InvalidOperationException("Cannot assign a child of type " + type.Name + "to a parent of type " + parent.GetType().Name);
                }
            }
            PlayableAsset masterAsset = (!(parent != null)) ? this : parent;
            string        text        = name;

            if (string.IsNullOrEmpty(text))
            {
                text = type.Name;
            }
            string text2;

            if (parent != null)
            {
                text2 = TimelineCreateUtilities.GenerateUniqueActorName(parent.subTracksObjects, text);
            }
            else
            {
                text2 = TimelineCreateUtilities.GenerateUniqueActorName(this.trackObjects, text);
            }
            TrackAsset trackAsset = this.AllocateTrack(parent, text2, type);

            if (trackAsset != null)
            {
                trackAsset.name = text2;
                TimelineCreateUtilities.SaveAssetIntoObject(trackAsset, masterAsset);
            }
            return(trackAsset);
        }
        static void MoveToTrack_Impl(TimelineClip clip, TrackAsset destinationTrack, Object asset, TrackAsset parentTrack)
        {
            TimelineUndo.PushUndo(asset, k_UndoSetParentTrackText);
            if (parentTrack != null)
            {
                TimelineUndo.PushUndo(parentTrack, k_UndoSetParentTrackText);
            }

            TimelineUndo.PushUndo(destinationTrack, k_UndoSetParentTrackText);

            clip.SetParentTrack_Internal(destinationTrack);

            if (parentTrack == null)
            {
                TimelineCreateUtilities.SaveAssetIntoObject(asset, destinationTrack);
            }
            else if (parentTrack.timelineAsset != destinationTrack.timelineAsset)
            {
                TimelineCreateUtilities.RemoveAssetFromObject(asset, parentTrack);
                TimelineCreateUtilities.SaveAssetIntoObject(asset, destinationTrack);
            }
        }
Exemplo n.º 10
0
        public IMarker CreateMarker(Type type, double time, TrackAsset owner)
        {
            if (!typeof(ScriptableObject).IsAssignableFrom(type) || !typeof(IMarker).IsAssignableFrom(type))
            {
                throw new InvalidOperationException(
                          "The requested type needs to inherit from ScriptableObject and implement IMarker");
            }

            var markerSO = ScriptableObject.CreateInstance(type);
            var marker   = (IMarker)markerSO;

            marker.time = time;

            TimelineCreateUtilities.SaveAssetIntoObject(markerSO, owner);
            TimelineUndo.RegisterCreatedObjectUndo(markerSO, "Create " + type.Name);
            TimelineUndo.PushUndo(owner, "Create " + type.Name);

            Add(markerSO);
            marker.Initialize(owner);

            return(marker);
        }