Пример #1
0
        Rect GetDopeElementRect(IDopeElement dopeElement)
        {
            Texture defaultDopeKeyIcon = styles.defaultDopeKeyIcon.image;

            float time = m_TimeArea.TimeToPixel(SnapToFrame(dopeElement.time), m_ContentRect);

            return(new Rect(time - (defaultDopeKeyIcon.width / 2), m_ContentRect.y, defaultDopeKeyIcon.width, defaultDopeKeyIcon.height));
        }
Пример #2
0
        public void DoTimeline(Rect rectArea)
        {
            Init();

            if (Event.current.type == EventType.Repaint)
            {
                m_TimeArea.rect = rectArea;
            }

            m_TimeArea.BeginViewGUI();
            m_TimeArea.EndViewGUI();

            GUI.BeginGroup(rectArea);

            Rect rect = new Rect(0f, 0f, rectArea.width, rectArea.height);

            m_HeaderRect = new Rect(0f, 0f, rectArea.width, 18f);

            m_ContentRect = new Rect(0f, 18f, rectArea.width, rectArea.height - m_HeaderRect.height);

            float playHeadPosX = m_TimeArea.TimeToPixel(Time, rectArea);

            Rect playHeadRect = new Rect(playHeadPosX - styles.playhead.fixedWidth * 0.5f - 4f, 4f, styles.playhead.fixedWidth, styles.playhead.fixedHeight);

            if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
            {
                GUIUtility.hotControl      = id;
                GUIUtility.keyboardControl = id;

                if (playHeadRect.Contains(Event.current.mousePosition))
                {
                    m_StartValue = playHeadPosX;

                    m_DragState = Timeline.DragStates.Playhead;
                }
                else if (m_HeaderRect.Contains(Event.current.mousePosition))
                {
                    m_DragState = Timeline.DragStates.TimeLine;

                    Time = SnapToFrame(m_TimeArea.PixelToTime(Event.current.mousePosition.x, rectArea));

                    GUI.changed = true;
                }
                else
                {
                    for (var i = dopeElements.GetEnumerator(); i.MoveNext();)
                    {
                        IDopeElement element = i.Current;

                        Rect position = GetDopeElementRect(element);

                        if (position.Contains(Event.current.mousePosition))
                        {
                            m_DragState = DragStates.Element;

                            m_StartValue = m_TimeArea.TimeToPixel(element.time, rectArea);

                            Time = SnapToFrame(element.time);

                            selectedElement = element;

                            GUI.changed = true;
                        }
                    }
                }

                Event.current.Use();
            }

            if (Event.current.type == EventType.MouseDrag && GUIUtility.hotControl == this.id)
            {
                switch (m_DragState)
                {
                case Timeline.DragStates.Playhead:

                    m_StartValue += Event.current.delta.x;

                    Time = SnapToFrame(m_TimeArea.PixelToTime(m_StartValue, rectArea));

                    break;

                case Timeline.DragStates.TimeLine:
                    Time = SnapToFrame(m_TimeArea.PixelToTime(Event.current.mousePosition.x, rectArea));

                    break;

                case Timeline.DragStates.Element:

                    if (canEditDopeElements)
                    {
                        m_StartValue += Event.current.delta.x;

                        selectedElement.time = SnapToFrame(m_TimeArea.PixelToTime(m_StartValue, rectArea));
                    }

                    break;
                }

                Event.current.Use();
                GUI.changed = true;
            }

            if (Event.current.type == EventType.MouseUp && GUIUtility.hotControl == this.id)
            {
                switch (m_DragState)
                {
                case Timeline.DragStates.Playhead:
                    break;

                case Timeline.DragStates.TimeLine:
                    break;

                case Timeline.DragStates.Element:
                    if (canEditDopeElements)
                    {
                        selectedElement.Flush();
                        selectedElement = null;
                    }
                    break;
                }

                GUI.changed = true;

                m_DragState = Timeline.DragStates.None;

                GUIUtility.hotControl = 0;

                Event.current.Use();
            }

            GUI.Box(m_HeaderRect, GUIContent.none, this.styles.header);

            GUI.Box(m_ContentRect, GUIContent.none, this.styles.background);

            m_TimeArea.TimeRuler(m_HeaderRect, FrameRate);

            GUI.Box(playHeadRect, GUIContent.none, styles.playhead);

            DopeLineRepaint();

            GUI.EndGroup();
        }