Beispiel #1
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);
                }
            }
        }