コード例 #1
0
        public void AddTag(Type tagType, float startTime = 0f, float duration = -1f)
        {
            if (!Valid)
            {
                return;
            }

            if (duration < 0)
            {
                duration = DurationInSeconds - startTime;
            }

            int existing = tags.Count(t => t.Type == tagType &&
                                      FloatComparer.AreEqual(t.startTime, startTime, FloatComparer.kEpsilon) &&
                                      FloatComparer.AreEqual(t.duration, duration, FloatComparer.kEpsilon));

            if (existing > 0)
            {
                return;
            }

            Undo.RecordObject(m_Asset, $"Add {TagAttribute.GetDescription(tagType)} tag");

            TagAnnotation newTag = TagAnnotation.Create(tagType, startTime, duration);

            tags.Add(newTag);

            NotifyChanged();
        }
コード例 #2
0
 public void RemoveTag(TagAnnotation tag)
 {
     Undo.RecordObject(m_Asset, $"Remove {TagAttribute.GetDescription(tag.Type)} tag");
     tags.RemoveAll(x => x == tag);
     tag.Dispose();
     TagRemoved?.Invoke(tag);
     NotifyChanged();
 }
コード例 #3
0
        static void AddTagMenu(ContextualMenuPopulateEvent evt, Action <DropdownMenuAction> action, DropdownMenuAction.Status menuStatus)
        {
            const string prefix = "Add Tag/";

            foreach (var tagType in TagAttribute.GetVisibleTypesInInspector())
            {
                evt.menu.AppendAction($"{prefix}{TagAttribute.GetDescription(tagType)}", action, a => menuStatus, tagType);
            }
        }
コード例 #4
0
        public void AddMarker(MarkerAnnotation marker)
        {
            if (!Valid)
            {
                return;
            }

            Undo.RecordObject(m_Asset, $"Add {TagAttribute.GetDescription(marker.payload.Type)}");
            markers.Add(marker);
            MarkerAdded?.Invoke(marker);
            NotifyChanged();
        }
コード例 #5
0
        public void AddTag(TagAnnotation tag)
        {
            if (!Valid)
            {
                return;
            }

            Undo.RecordObject(m_Asset, $"Add {TagAttribute.GetDescription(tag.Type)} tag");
            tags.Add(tag);
            TagAdded?.Invoke(tag);
            NotifyChanged();
        }
コード例 #6
0
 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);
         }
     }
 }
コード例 #7
0
        public void RemoveTag(Type type)
        {
            var matchingTags = tags.Where(t =>
                                          t.Type == type && FloatComparer.s_ComparerWithDefaultTolerance.Equals(t.startTime, 0f) && FloatComparer.s_ComparerWithDefaultTolerance.Equals(t.duration, Clip.DurationInSeconds)).ToList();

            if (matchingTags.Any())
            {
                Undo.RecordObject(m_Asset, $"Remove {matchingTags.Count} {TagAttribute.GetDescription(type)} tag(s)");
                foreach (var t in matchingTags)
                {
                    tags.Remove(t);
                    t.Dispose();
                }

                NotifyChanged();
            }
        }
コード例 #8
0
        void BuildAnimationClipItemMenu(ContextualMenuPopulateEvent evt, VisualElement ve)
        {
            var clip = ve.userData as TaggedAnimationClip;

            if (clip == null)
            {
                evt.menu.AppendSeparator("Missing Clip");
                return;
            }

            if (m_AnimationLibraryListView.m_ClipSelection.Count > 0)
            {
                if (!m_AnimationLibraryListView.m_ClipSelection.Contains(clip))
                {
                    // We can't change the selection of the list from inside a context menu event
                    return;
                }

                evt.menu.AppendAction("Delete Selected Clip(s)", action => m_AnimationLibraryListView.DeleteSelection(), DropdownMenuAction.AlwaysEnabled);
                evt.menu.AppendSeparator();
                foreach (var tagType in TagAttribute.GetVisibleTypesInInspector())
                {
                    evt.menu.AppendAction($"Tag Selected Clip(s)/{TagAttribute.GetDescription(tagType)}", OnTagSelectionClicked, DropdownMenuAction.AlwaysEnabled, tagType);
                }

                evt.menu.AppendAction("Set Boundary Clips", action => BoundaryClipWindow.ShowWindow(m_Asset, m_AnimationLibraryListView.m_ClipSelection));

                evt.menu.AppendAction("Experimental - Generate Procedural Annotations", action => m_AnimationLibraryListView.GenerateProceduralAnnotations(), m_AnimationLibraryListView.CanGenerateProceduralAnnotations());
            }
            else
            {
                evt.menu.AppendAction("Delete Clip", action =>
                {
                    m_Asset.RemoveClips(new[] { clip });
                    m_AnimationLibraryListView.Refresh();
                }, DropdownMenuAction.AlwaysEnabled);

                evt.menu.AppendSeparator();
                foreach (var tagType in TagAttribute.GetVisibleTypesInInspector())
                {
                    evt.menu.AppendAction($"Tag Clip/{TagAttribute.GetDescription(tagType)}",
                                          action => clip.AddTag(tagType),
                                          DropdownMenuAction.AlwaysEnabled, tagType);
                }
            }
        }
コード例 #9
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();
            }
        }
コード例 #10
0
        public static object CreateDefaultTag()
        {
            if (!k_DefaultTagTypeComputed)
            {
                foreach (Type tagType in TagAttribute.GetVisibleTypesInInspector())
                {
                    if (tagType.IsDefined(typeof(DefaultTagAttribute)))
                    {
                        if (k_CreateDefaultTagMethod == null)
                        {
                            MethodInfo createTagMethod = tagType.GetMethod("CreateDefaultTag", BindingFlags.Static | BindingFlags.Public);
                            if (createTagMethod == null)
                            {
                                Debug.LogWarning($"Default tag type {tagType.FullName} is missing \"public static {tagType.FullName} CreateDefaultTag()\" function, cannot create default tag");
                                return(null);
                            }
                            else if (createTagMethod.GetGenericArguments().Length > 0 || createTagMethod.ReturnType != tagType)
                            {
                                Debug.LogWarning($"Default tag type {tagType.FullName} should have \"public static {tagType.FullName} CreateDefaultTag()\" signature, cannot create default tag");
                                return(null);
                            }

                            k_CreateDefaultTagMethod = createTagMethod;
                            k_DefaultTagType         = tagType;
                        }
                        else
                        {
                            Debug.LogWarning($"Tag type {tagType.FullName} has default tag attribute, but {k_DefaultTagType.FullName} is already defined as the default tag");
                        }
                    }
                }

                k_DefaultTagTypeComputed = true;
            }

            if (k_CreateDefaultTagMethod == null)
            {
                return(null);
            }

            return(k_CreateDefaultTagMethod.Invoke(null, null));
        }
コード例 #11
0
        public static int MaskFlags(List <bool> boolValues)
        {
            if (boolValues.Count > 32)
            {
                return(0);
            }

            int intValue = 0;

            TagAttribute.GetVisibleTypesInInspector();

            for (int i = 0; i < boolValues.Count; i++)
            {
                if (boolValues[i])
                {
                    intValue += 1 << i;
                }
            }

            return(intValue);
        }
コード例 #12
0
        protected override void OnMouseUpEvent(MouseUpEvent evt)
        {
            if (!m_Active || !target.HasMouseCapture() || !CanStopManipulation(evt))
            {
                return;
            }

            base.OnMouseUpEvent(evt);

            float distanceFromMouseDown = Math.Abs(evt.mousePosition.x - m_MouseDownPosition.x);

            if (distanceFromMouseDown >= k_MinDistance && !EditorApplication.isPlaying)
            {
                float mouseUpTime = m_Timeline.WorldPositionToTime(evt.mousePosition.x);

                float startTime = Math.Min(m_MouseDownTime, mouseUpTime);
                float duration  = Math.Max(m_MouseDownTime, mouseUpTime) - startTime;

                var menu = new GenericMenu();

                foreach (Type tagType in TagAttribute.GetVisibleTypesInInspector())
                {
                    menu.AddItem(new GUIContent($"{TagAttribute.GetDescription(tagType)}"),
                                 false,
                                 () => { m_Timeline.OnAddTagSelection(tagType, startTime, duration); });
                }

                menu.DropDown(new Rect(evt.mousePosition, Vector2.zero));
            }
            else
            {
                m_Timeline.ReSelectCurrentClip();
            }

            m_Target.style.visibility = Visibility.Hidden;
        }
コード例 #13
0
        internal TagEditor(TagAnnotation tag, TaggedAnimationClip clip)
        {
            m_Tag  = tag;
            m_Clip = clip;

            UIElementsUtils.CloneTemplateInto("Inspectors/TagEditor.uxml", this);
            UIElementsUtils.ApplyStyleSheet(AnnotationsEditor.k_AnnotationsEditorStyle, this);
            AddToClassList(AnnotationsEditor.k_AnnotationsContainer);
            AddToClassList("drawerElement");

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

            deleteButton.clickable.clicked += () => { RemoveTag(m_Tag); };

            if (!tag.payload.ValidPayloadType)
            {
                Clear();
                var unknownLabel = new Label {
                    text = TagAttribute.k_UnknownTagType
                };
                unknownLabel.AddToClassList(AnnotationsEditor.k_UnknownAnnotationType);
                Add(unknownLabel);
                return;
            }

            TextField tagType = this.Q <TextField>("tagType");

            tagType.value = TagAttribute.GetDescription(m_Tag.Type);
            tagType.SetEnabled(false);

            Asset asset = m_Clip.Asset;

            TextField tagName = this.Q <TextField>("name");

            tagName.value = m_Tag.name;
            tagName.RegisterValueChangedCallback(evt =>
            {
                if (!evt.newValue.Equals(m_Tag.name, StringComparison.Ordinal))
                {
                    Undo.RecordObject(asset, "Change tag name");
                    m_Tag.name = evt.newValue;
                    m_Tag.NotifyChanged();
                    asset.MarkDirty();
                }
            });

            TextField metricLabel = this.Q <TextField>("metricLabel");
            var       metric      = asset.GetMetricForTagType(m_Tag.Type);

            if (metric != null)
            {
                metricLabel.value = metric.name;
                metricLabel.SetEnabled(false);
            }
            else
            {
                metricLabel.style.display = DisplayStyle.None;
            }

            TimeField stf = this.Q <TimeField>("startTime");

            stf.Init(m_Clip, m_Tag.startTime);
            stf.TimeChanged += (newTime) =>
            {
                if (!EqualityComparer <float> .Default.Equals(m_Tag.startTime, newTime))
                {
                    Undo.RecordObject(asset, "Change tag start time");
                    m_Tag.startTime = newTime;
                    m_Tag.NotifyChanged();
                    asset.MarkDirty();
                }
            };


            TimeField dtf = this.Q <TimeField>("durationTime");

            dtf.Init(m_Clip, m_Tag.duration);
            dtf.TimeChanged += (newTime) =>
            {
                if (!EqualityComparer <float> .Default.Equals(m_Tag.duration, newTime))
                {
                    Undo.RecordObject(asset, "Change tag duration");
                    m_Tag.duration = newTime;
                    m_Tag.NotifyChanged();
                    asset.MarkDirty();
                }
            };

            var so = m_Tag.payload.ScriptableObject;

            if (so != null)
            {
                m_PayloadInspector = UnityEditor.Editor.CreateEditor(so) as GenericStructInspector;
                m_PayloadInspector.StructModified += () =>
                {
                    m_Tag.payload.Serialize();
                    m_Tag.NotifyChanged();
                    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_Tag.Changed += Refresh;
            asset.AssetWasDeserialized += Refresh;
        }