public static bool ValidateParentTrack(TrackAsset parent, Type childType)
        {
            if (childType == null || !typeof(TrackAsset).IsAssignableFrom(childType))
            {
                return(false);
            }

            // no parent is valid for any type
            if (parent == null)
            {
                return(true);
            }

            // A track supports layers if it implements ILayerable. Only supported for parents that are
            // the same exact type as the child class, and 1 level of nesting only
            if (parent is ILayerable && !parent.isSubTrack && parent.GetType() == childType)
            {
                return(true);
            }

            var attr = Attribute.GetCustomAttribute(parent.GetType(), typeof(SupportsChildTracksAttribute)) as SupportsChildTracksAttribute;

            if (attr == null)
            {
                return(false);
            }

            // group track case, accepts all
            if (attr.childType == null)
            {
                return(true);
            }

            // specific case. Specifies nesting level
            if (childType == attr.childType)
            {
                int nestCount = 0;
                var p         = parent;
                while (p != null && p.isSubTrack)
                {
                    nestCount++;
                    p = p.parent as TrackAsset;
                }

                return(nestCount < attr.levels);
            }
            return(false);
        }
Ejemplo n.º 2
0
        Playable CreateTrackPlayable(PlayableGraph graph, Playable timelinePlayable, TrackAsset track, GameObject go, bool createOutputs)
        {
            if (!track.IsCompilable()) // where parents are not compilable (group tracks)
            {
                return(timelinePlayable);
            }

            Playable playable;

            if (m_PlayableCache.TryGetValue(track, out playable))
            {
                return(playable);
            }

            if (track.name == "root")
            {
                return(timelinePlayable);
            }

            TrackAsset parentActor    = track.parent as TrackAsset;
            var        parentPlayable = parentActor != null?CreateTrackPlayable(graph, timelinePlayable, parentActor, go, createOutputs) : timelinePlayable;

            var  actorPlayable = track.CreatePlayableGraph(graph, go, m_IntervalTree, timelinePlayable);
            bool connected     = false;

            if (!actorPlayable.IsValid())
            {
                // if a track says it's compilable, but returns Playable.Null, that can screw up the whole graph.
                throw new InvalidOperationException(track.name + "(" + track.GetType() + ") did not produce a valid playable.");
            }


            // Special case for animation tracks
            if (parentPlayable.IsValid() && actorPlayable.IsValid())
            {
                int port = parentPlayable.GetInputCount();
                parentPlayable.SetInputCount(port + 1);
                connected = graph.Connect(actorPlayable, 0, parentPlayable, port);
                parentPlayable.SetInputWeight(port, 1.0f);
            }

            if (createOutputs && connected)
            {
                CreateTrackOutput(graph, track, go, parentPlayable, parentPlayable.GetInputCount() - 1);
            }

            CacheTrack(track, actorPlayable, connected ? (parentPlayable.GetInputCount() - 1) : -1, parentPlayable);
            return(actorPlayable);
        }
Ejemplo n.º 3
0
        private Playable CreateTrackPlayable(PlayableGraph graph, Playable timelinePlayable, TrackAsset track, GameObject go, bool createOutputs)
        {
            Playable result;

            TimelinePlayable.ConnectionCache connectionCache;
            if (!track.compilable)
            {
                result = timelinePlayable;
            }
            else if (this.m_PlayableCache.TryGetValue(track, out connectionCache))
            {
                result = connectionCache.playable;
            }
            else if (track.get_name() == "root")
            {
                result = timelinePlayable;
            }
            else
            {
                TrackAsset trackAsset = track.parent as TrackAsset;
                Playable   playable   = (!(trackAsset != null)) ? timelinePlayable : this.CreateTrackPlayable(graph, timelinePlayable, trackAsset, go, createOutputs);
                Playable   playable2  = TimelinePlayable.CreatePlayableGraph(graph, track, go, this.m_IntervalTree);
                bool       flag       = false;
                if (!PlayableExtensions.IsValid <Playable>(playable2))
                {
                    throw new InvalidOperationException(string.Concat(new object[]
                    {
                        track.get_name(),
                        "(",
                        track.GetType(),
                        ") did not produce a valid playable. Use the compilable property to indicate whether the track is valid for processing"
                    }));
                }
                if (PlayableExtensions.IsValid <Playable>(playable) && PlayableExtensions.IsValid <Playable>(playable2))
                {
                    int inputCount = PlayableExtensions.GetInputCount <Playable>(playable);
                    PlayableExtensions.SetInputCount <Playable>(playable, inputCount + 1);
                    flag = graph.Connect <Playable, Playable>(playable2, 0, playable, inputCount);
                    PlayableExtensions.SetInputWeight <Playable>(playable, inputCount, 1f);
                }
                if (createOutputs && flag)
                {
                    this.CreateTrackOutput(graph, track, playable, PlayableExtensions.GetInputCount <Playable>(playable) - 1);
                }
                this.CacheTrack(track, playable2, (!flag) ? -1 : (PlayableExtensions.GetInputCount <Playable>(playable) - 1), playable);
                result = playable2;
            }
            return(result);
        }
Ejemplo n.º 4
0
        internal static bool ValidateParentTrack(TrackAsset parent, Type childType)
        {
            if (childType == null || !typeof(TrackAsset).IsAssignableFrom(childType))
            {
                return(false);
            }

            // no parent is valid for any type
            if (parent == null)
            {
                return(true);
            }

            var attr = Attribute.GetCustomAttribute(parent.GetType(), typeof(SupportsChildTracksAttribute)) as SupportsChildTracksAttribute;

            if (attr == null)
            {
                return(false);
            }

            // group track case, accepts all
            if (attr.childType == null)
            {
                return(true);
            }

            // specific case. Specifies nesting level
            if (childType == attr.childType)
            {
                int nestCount = 0;
                var p         = parent;
                while (p != null && p.isSubTrack)
                {
                    nestCount++;
                    p = p.parent as TrackAsset;
                }

                return(nestCount < attr.levels);
            }
            return(true);
        }
        /// <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);
        }
        internal static bool ValidateParentTrack(TrackAsset parent, Type childType)
        {
            bool result;

            if (childType == null || !typeof(TrackAsset).IsAssignableFrom(childType))
            {
                result = false;
            }
            else if (parent == null)
            {
                result = true;
            }
            else
            {
                SupportsChildTracksAttribute supportsChildTracksAttribute = Attribute.GetCustomAttribute(parent.GetType(), typeof(SupportsChildTracksAttribute)) as SupportsChildTracksAttribute;
                if (supportsChildTracksAttribute == null)
                {
                    result = false;
                }
                else if (supportsChildTracksAttribute.childType == null)
                {
                    result = true;
                }
                else if (childType == supportsChildTracksAttribute.childType)
                {
                    int        num        = 0;
                    TrackAsset trackAsset = parent;
                    while (trackAsset != null && trackAsset.isSubTrack)
                    {
                        num++;
                        trackAsset = (trackAsset.parent as TrackAsset);
                    }
                    result = (num < supportsChildTracksAttribute.levels);
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
Ejemplo n.º 7
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);
        }