Esempio n. 1
0
        public TagElement(Track track, TaggedAnimationClip clip, TagAnnotation tag) : base(track)
        {
            m_Tag     = tag;
            focusable = true;

            AddToClassList("clipTagRoot");

            m_ManipulateStartLabel = new Label();
            m_ManipulateStartLabel.AddToClassList("tagManipulateStartLabel");
            m_ManipulateStartLabel.AddToClassList("tagManipulateLabel");

            m_ManipulateEndLabel = new Label();
            m_ManipulateEndLabel.AddToClassList("tagManipulateEndLabel");
            m_ManipulateEndLabel.AddToClassList("tagManipulateLabel");

            m_BackgroundColor = AnnotationAttribute.GetColor(m_Tag.Type);
            var background = m_BackgroundColor;

            background.r         *= k_BackgroundAlpha;
            background.g         *= k_BackgroundAlpha;
            background.b         *= k_BackgroundAlpha;
            style.backgroundColor = background;
            int   hash = new Random(m_Tag.payload.GetHashedData()).Next();
            Color colorFromValueHash = ColorUtility.FromHtmlString("#" + Convert.ToString(hash, 16));
            Color borderColor        = background;

            borderColor.r           = (borderColor.r + colorFromValueHash.r) / 2;
            borderColor.g           = (borderColor.g + colorFromValueHash.g) / 2;
            borderColor.b           = (borderColor.b + colorFromValueHash.b) / 2;
            style.borderLeftColor   = borderColor;
            style.borderBottomColor = borderColor;
            style.borderRightColor  = borderColor;

            VisualElement startHandle = CreateHandle(TagManipulator.Mode.StartTime);

            startHandle.style.left = -4;
            Insert(0, startHandle);
            startHandle.Add(m_ManipulateStartLabel);

            m_LabelContainer.AddManipulator(new TagManipulator(this, TagManipulator.Mode.Body));
            m_Label.text = string.IsNullOrEmpty(m_Tag.name) ? m_Tag.Name : m_Tag.name;

            VisualElement endHandle = CreateHandle(TagManipulator.Mode.Duration);

            endHandle.style.left = 4;
            Add(endHandle);
            endHandle.Add(m_ManipulateEndLabel);

            var contextMenuManipulator = new ContextualMenuManipulator(OpenTagRemoveMenu);

            this.AddManipulator(contextMenuManipulator);

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
        }
        public static Color GetColor(Type type)
        {
            if (type == null)
            {
                return(Color.gray);
            }

            AnnotationAttribute attribute = type.GetCustomAttributes(typeof(AnnotationAttribute), true).FirstOrDefault() as AnnotationAttribute;

            return(attribute.m_Color);
        }
        public MarkerElement(MarkerAnnotation marker, MarkerTrack track) : base(track)
        {
            m_Track     = track;
            this.marker = marker;
            focusable   = true;

            m_Content = new VisualElement();
            m_Content.AddToClassList(k_MarkerStyleClass);
            m_BackgroundColor = AnnotationAttribute.GetColor(marker.payload.Type);
            var background = m_BackgroundColor;

            background.a = k_BackgroundAlpha;
            m_Content.style.backgroundColor = background;
            Add(m_Content);

            SetupManipulators(m_Content);

            m_ManipulateLabel = new Label();
            m_ManipulateLabel.AddToClassList("markerManipulateLabel");
            m_ManipulateLabel.style.visibility = Visibility.Hidden;
            Add(m_ManipulateLabel);

            style.position  = Position.Absolute;
            style.minHeight = 22;
            style.maxWidth  = 1;

            marker.Changed += Reposition;

            if (panel != null)
            {
                SetupTimelineGuideline(panel.visualTree);
            }
            else
            {
                RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            }

            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);
        }