/// <summary>
        /// 查找指定名称的TrackAsset
        /// </summary>
        /// <param name="_trackAsset">TrackAsset</param>
        /// <param name="_trackAssetName">TrackAsset名称</param>
        /// <returns>TrackAsset</returns>
        public static TrackAsset FindChildTrackAsset(this TrackAsset _trackAsset, string _trackAssetName)
        {
            TrackAsset trackAsset = null;

            if (_trackAsset != null)
            {
                IEnumerator childTracks = _trackAsset.GetChildTracks().GetEnumerator();
                while (childTracks.MoveNext())
                {
                    TrackAsset ta = (TrackAsset)childTracks.Current;
                    if (ta.name.Equals(_trackAssetName))
                    {
                        trackAsset = ta;
                        break;
                    }
                }
            }
#if UNITY_EDITOR
            if (trackAsset == null)
            {
                Debug.LogErrorFormat("Can't find ChildTrackAsset for【{0}】.", _trackAssetName);
            }
#endif
            return(trackAsset);
        }
Beispiel #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);
            }
        }
Beispiel #3
0
 public static void EnumerateTracks(TrackAsset track, Action <TrackAsset> act)
 {
     act(track);
     foreach (var child in track.GetChildTracks())
     {
         EnumerateTracks(child, act);
     }
 }
Beispiel #4
0
        public static IEnumerable <TrackAsset> GetFlattenedChildTracks(this TrackAsset asset)
        {
            if (asset == null || !asset.GetChildTracks().Any())
            {
                return(Enumerable.Empty <TrackAsset>());
            }

            var flattenedChildTracks = new List <TrackAsset>();

            GetFlattenedChildTracks(asset, flattenedChildTracks);
            return(flattenedChildTracks);
        }
Beispiel #5
0
        static TrackAsset GetSubTrackAsset(TrackAsset self, string trackName)
        {
            foreach (var subTrackAsset in self.GetChildTracks())
            {
                if (subTrackAsset.name.Equals(trackName))
                {
                    return(subTrackAsset);
                }
            }

            return(null);
        }
Beispiel #6
0
        private static void SetExpandedStates(TrackAsset asset, HashSet <TrackAsset> expanded)
        {
#if UNITY_TIMELINE_1_5_2
            asset.SetCollapsed(!expanded.Contains(asset));
#else
            SetTrackCollapsed(asset, !expanded.Contains(asset));
#endif
            foreach (TrackAsset track in asset.GetChildTracks())
            {
                SetExpandedStates(track, expanded);
            }
        }
Beispiel #7
0
        // Get a flattened list of all child tracks
        public static void GetFlattenedChildTracks(this TrackAsset asset, List <TrackAsset> list)
        {
            if (asset == null || list == null)
            {
                return;
            }

            foreach (var track in asset.GetChildTracks())
            {
                list.Add(track);
                GetFlattenedChildTracks(track, list);
            }
        }
        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);
                // registration has to happen AFTER recursion
                TimelineUndo.RegisterCreatedObjectUndo(newSub, "Duplicate");
                TimelineCreateUtilities.SaveAssetIntoObject(newSub, assetOwner);
            }
        }
        internal static bool IsAllSubTrackMuted(TrackAsset asset)
        {
            if (asset is GroupTrack)
                return asset.mutedInHierarchy;

            foreach (TrackAsset t in asset.GetChildTracks())
            {
                if (!t.muted)
                    return false;

                var childMuted = IsAllSubTrackMuted(t);

                if (!childMuted)
                    return false;
            }
            return true;
        }
        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"));
            }
        }
Beispiel #11
0
            private static TimelineClip GetClipInAllTracks(TrackAsset track, IPlayableAsset Clip)
            {
                TimelineClip clip = GetClip(track, Clip);

                if (clip != null)
                {
                    return(clip);
                }

                foreach (TrackAsset childTrack in track.GetChildTracks())
                {
                    clip = GetClipInAllTracks(childTrack, Clip);

                    if (clip != null)
                    {
                        return(clip);
                    }
                }

                return(null);
            }
Beispiel #12
0
        public static bool IsAllSubTrackMuted(TrackAsset asset)
        {
            if (asset is GroupTrack)
            {
                return(asset.mutedInHierarchy);
            }

            foreach (TrackAsset t in asset.GetChildTracks())
            {
                if (!t.muted)
                {
                    return(false);
                }

                var childMuted = IsAllSubTrackMuted(t);

                if (!childMuted)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #13
0
        static int CalcAnimClipHash(TrackAsset asset)
        {
            int hash = 0;

            if (asset != null)
            {
                AnimationTrack animTrack = asset as AnimationTrack;
                if (animTrack != null)
                {
                    for (var i = 0; i != animTrack.clips.Length; ++i)
                    {
                        hash ^= (animTrack.clips[i]).Hash();
                    }
                }
                foreach (var subTrack in asset.GetChildTracks())
                {
                    if (subTrack != null)
                    {
                        hash ^= CalcAnimClipHash(subTrack);
                    }
                }
            }
            return(hash);
        }
Beispiel #14
0
        public override void OnBuildTrackContextMenu(GenericMenu menu, TrackAsset track, WindowState state)
        {
            var animTrack = track as AnimationTrack;

            if (animTrack == null)
            {
                base.OnBuildTrackContextMenu(menu, track, state);
                return;
            }

            if (animTrack.CanConvertFromClipMode() || animTrack.CanConvertToClipMode())
            {
                var canConvertToInfinite = animTrack.CanConvertFromClipMode();
                var canConvertToClip     = animTrack.CanConvertToClipMode();

                if (canConvertToInfinite)
                {
                    if (track.lockedInHierarchy || TimelineWindow.instance.state.editSequence.isReadOnly)
                    {
                        menu.AddDisabledItem(Styles.ConvertToInfiniteClipMenuItem, false);
                    }
                    else
                    {
                        menu.AddItem(Styles.ConvertToInfiniteClipMenuItem, false, parentTrack =>
                        {
                            animTrack.ConvertFromClipMode(state.editSequence.asset);
                            state.Refresh();
                        }, track);
                    }
                }

                if (canConvertToClip)
                {
                    if (track.lockedInHierarchy || TimelineWindow.instance.state.editSequence.isReadOnly)
                    {
                        menu.AddDisabledItem(Styles.ConvertToClipTrackMenuItem, false);
                    }
                    else
                    {
                        menu.AddItem(Styles.ConvertToClipTrackMenuItem, false, parentTrack =>
                        {
                            animTrack.ConvertToClipMode();
                            state.Refresh();
                        }, track);
                    }
                }
            }

            if (!track.isSubTrack)
            {
                var items = Enum.GetValues(typeof(TrackOffset));
                foreach (var i in items)
                {
                    var item = (TrackOffset)i;
                    if (state.editSequence.isReadOnly)
                    {
                        menu.AddDisabledItem(new GUIContent(Styles.TrackOffsetMenuPrefix + TypeUtility.GetMenuItemName(item)));
                    }
                    else
                    {
                        menu.AddItem(
                            new GUIContent(Styles.TrackOffsetMenuPrefix + TypeUtility.GetMenuItemName(item)),
                            animTrack.trackOffset == item,
                            () =>
                        {
                            animTrack.trackOffset = item;
                            state.UnarmForRecord(animTrack);
                            state.rebuildGraph = true;
                        }
                            );
                    }
                }
            }

            base.OnBuildTrackContextMenu(menu, track, state);

            if (!track.isSubTrack)
            {
                menu.AddSeparator(string.Empty);
                if (track.lockedInHierarchy || TimelineWindow.instance.state.editSequence.isReadOnly)
                {
                    menu.AddDisabledItem(Styles.AddOverrideTrackMenuItem, false);
                }
                else
                {
                    menu.AddItem(Styles.AddOverrideTrackMenuItem, false, parentTrack =>
                    {
                        AddSubTrack(state, typeof(AnimationTrack), "Override " + track.GetChildTracks().Count().ToString(), track);
                    }, track);
                }
            }
        }