示例#1
0
        public MarkerTrack(Timeline owner) : base(owner)
        {
            name = "Markers";
            AddToClassList("markerTrack");

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);

            m_MarkerOverlapIndicators = new List <MarkerOverlapIndicator>();
            var manipulator = new ContextualMenuManipulator(evt =>
            {
                DropdownMenu menu = evt.menu;
                float time        = m_Owner.WorldPositionToTime(evt.mousePosition.x);
                if (m_Owner.ViewMode == TimelineViewMode.frames)
                {
                    time = (float)TimelineUtility.RoundToFrame(time, Clip.SampleRate);
                }

                string timeStr = TimelineUtility.GetTimeString(m_Owner.ViewMode, time, (int)Clip.SampleRate);

                menu.AppendAction($"Add Marker at {timeStr}", null, DropdownMenuAction.Status.Disabled);
                menu.AppendSeparator();
                var menuStatus = EditorApplication.isPlaying ? DropdownMenuAction.Status.Disabled : DropdownMenuAction.Status.Normal;
                foreach (Type markerType in MarkerAttribute.GetMarkerTypes())
                {
                    evt.menu.AppendAction(MarkerAttribute.GetDescription(markerType), action => OnAddAnnotationSelection(markerType, time), a => menuStatus, markerType);
                }
            });

            this.AddManipulator(manipulator);
        }
        static void AddMarkerMenu(ContextualMenuPopulateEvent evt, Action <DropdownMenuAction> action, DropdownMenuAction.Status menuStatus)
        {
            const string prefix = "Add Marker /";

            foreach (var markerType in MarkerAttribute.GetMarkerTypes())
            {
                evt.menu.AppendAction($"{prefix}{MarkerAttribute.GetDescription(markerType)}", action, a => menuStatus, markerType);
            }
        }
示例#3
0
        public void RemoveMarker(MarkerAnnotation marker)
        {
            int index = markers.IndexOf(marker);

            if (index >= 0)
            {
                Undo.RecordObject(m_Asset, $"Remove {MarkerAttribute.GetDescription(marker.GetType())}");
                MarkerRemoved?.Invoke(marker);
                marker.Dispose();
                markers.RemoveAt(index);
                NotifyChanged();
            }
        }
 void OnAddAnnotationSelection(Type type)
 {
     if (type != null && m_TaggedClip != null)
     {
         if (TagAttribute.IsTagType(type))
         {
             m_TaggedClip.AddTag(type, m_Owner.ActiveTime);
         }
         else if (MarkerAttribute.IsMarkerType(type))
         {
             m_TaggedClip.AddMarker(type, m_Owner.ActiveTime);
         }
     }
 }
示例#5
0
        void OnAddSelection(Type type)
        {
            if (type != null && TaggedClip != null)
            {
                if (TagAttribute.IsTagType(type))
                {
                    OnAddTagSelection(type, ActiveTime);
                }
                else if (MarkerAttribute.IsMarkerType(type))
                {
                    TaggedClip.AddMarker(type, ActiveTime);
                    TargetAsset.MarkDirty();
                }

                TaggedClip.NotifyChanged();
            }
        }
        void SelectMarkerMenu(ContextualMenuPopulateEvent evt)
        {
            List <MarkerElement> markersAtTime = m_Track.GetMarkersNearX(XPos).ToList();

            foreach (var m in markersAtTime)
            {
                string text = markersAtTime.Count > 1 ? $"Select/{MarkerAttribute.GetDescription(m.marker.payload.Type)}" : $"Select {MarkerAttribute.GetDescription(m.marker.payload.Type)}";
                Action <DropdownMenuAction> action = a => SelectMarkerElement(m, false);
                if (m == this && markersAtTime.Count > 1)
                {
                    text += "*";
                }

                if (m.m_Selected)
                {
                    evt.menu.AppendAction(text, action, DropdownMenuAction.AlwaysDisabled);
                }
                else
                {
                    evt.menu.AppendAction(text, action, DropdownMenuAction.AlwaysEnabled);
                }
            }
        }
示例#7
0
        public MarkerEditor(MarkerAnnotation marker, TaggedAnimationClip clip)
        {
            m_Clip   = clip;
            m_Marker = marker;
            UIElementsUtils.ApplyStyleSheet(BuilderWindow.k_Stylesheet, this);
            UIElementsUtils.CloneTemplateInto("Inspectors/MarkerEditor.uxml", this);
            AddToClassList("drawerElement");

            var deleteButton = this.Q <Button>("deleteButton");

            deleteButton.clickable.clicked += () => { RemoveMarker(m_Marker); };

            if (!marker.payload.ValidPayloadType)
            {
                var contents = this.Q <VisualElement>(classes: "arrayEntryContents");
                contents.Clear();
                var unknownLabel = new Label {
                    text = MarkerAttribute.k_UnknownMarkerType
                };
                unknownLabel.AddToClassList(AnnotationsEditor.k_UnknownAnnotationType);
                contents.Add(unknownLabel);
                return;
            }

            TextField typeLabel = this.Q <TextField>();

            typeLabel.value = MarkerAttribute.GetDescription(m_Marker.payload.Type);
            typeLabel.SetEnabled(false);

            var timeField = this.Q <TimeField>("timeInSeconds");

            timeField.Init(m_Clip, marker.timeInSeconds);
            timeField.TimeChanged += newTime =>
            {
                if (!EqualityComparer <float> .Default.Equals(m_Marker.timeInSeconds, newTime))
                {
                    Undo.RecordObject(m_Clip.Asset, "Change marker time");
                    m_Marker.timeInSeconds = newTime;
                    m_Marker.NotifyChanged();
                    clip.Asset.MarkDirty();
                }
            };

            m_Marker.Changed += UpdateTime;

            m_PayloadInspector = UnityEditor.Editor.CreateEditor(m_Marker.payload.ScriptableObject) as GenericStructInspector;

            m_PayloadInspector.StructModified += () =>
            {
                m_Marker.payload.Serialize();
                m_Clip.Asset.MarkDirty();
            };

            VisualElement inspectorElement   = m_PayloadInspector.CreateInspectorGUI() ?? new IMGUIContainer(m_PayloadInspector.OnInspectorGUI);
            var           inspectorContainer = this.Q <VisualElement>("payloadInspector");

            inspectorContainer.Add(inspectorElement);

            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);
            m_Clip.Asset.AssetWasDeserialized += UpdateTime;
        }