private void OnUpdate()
        {
            if (!_syncWithAnimationWindow)
            {
                return;
            }

            if (Selection.activeTransform != Track.Owner)
            {
                Selection.activeTransform = Track.Owner;
            }

            if (!AnimationMode.InAnimationMode())
            {
//				AnimationMode.StartAnimationMode();
                AnimationWindowProxy.StartAnimationMode();
            }

//			if( _track.IsPreviewing )
            {
                int animWindowFrame = AnimationWindowProxy.GetCurrentFrame();

                FEvent[] evts    = new FEvent[2];
                int      numEvts = Track.GetEventsAt(SequenceEditor.Sequence.CurrentFrame, ref evts);

                if (numEvts > 0)
                {
                    FPlayAnimationEvent animEvt = (FPlayAnimationEvent)evts[numEvts - 1];
                    if (animEvt.ControlsAnimation)
                    {
                        int normCurrentFrame = SequenceEditor.Sequence.CurrentFrame - animEvt.Start;

                        if (animWindowFrame > animEvt.Length)
                        {
                            animWindowFrame = animEvt.Length;
                            AnimationWindowProxy.SetCurrentFrame(animWindowFrame, animEvt.LengthTime);
                        }

                        if (animWindowFrame >= 0 && animWindowFrame != normCurrentFrame)
                        {
                            SequenceEditor.SetCurrentFrame(animEvt.Start + animWindowFrame);
                            SequenceEditor.Repaint();
                            //						Debug.Log( "AnimWindow->Flux: " + (animEvt.Start + animWindowFrame) );
                        }
                    }
                }
            }
        }
Пример #2
0
        public virtual void Render(int id, Rect rect, int headerWidth, FrameRange viewRange, float pixelsPerFrame)
        {
            rect.y += _offsetAnim.value.y;

            _rect = rect;

            Rect viewRect = rect;

            viewRect.y     += _offsetAnim.value.y;
            viewRect.xMax   = headerWidth;
            viewRect.xMin   = viewRect.xMax - 16;
            viewRect.height = 16;

            if (_track.CanTogglePreview())
            {
                if (Event.current.type == EventType.MouseDown)
                {
                    if (viewRect.Contains(Event.current.mousePosition))
                    {
                        if (Event.current.button == 0)                          // left click?
                        {
                            _track.IsPreviewing = !_track.IsPreviewing;
                            FUtility.RepaintGameView();
                            Event.current.Use();
                        }
                    }
                }
            }

            Rect trackHeaderRect = rect;

            trackHeaderRect.xMax = headerWidth;

            bool selected = _isSelected;

            if (selected)
            {
                Color c = FGUI.GetSelectionColor();
                GUI.color = c;
                GUI.DrawTexture(trackHeaderRect, EditorGUIUtility.whiteTexture);
                GUI.color = FGUI.GetTextColor();

//				Debug.Log( GUI.color );
            }

            Rect trackLabelRect = trackHeaderRect;

            trackLabelRect.xMin += 10;

            GUI.Label(trackLabelRect, new GUIContent(_track.name), FGUI.GetTrackHeaderStyle());

            rect.xMin = trackHeaderRect.xMax;

            FrameRange validKeyframeRange = new FrameRange(0, SequenceEditor.GetSequence().Length);

            for (int i = 0; i != _eventEditors.Count; ++i)
            {
                if (i == 0)
                {
                    validKeyframeRange.Start = 0;
                }
                else
                {
                    validKeyframeRange.Start = _eventEditors[i - 1]._evt.End;
                }

                if (i == _eventEditors.Count - 1)
                {
                    validKeyframeRange.End = SequenceEditor.GetSequence().Length;
                }
                else
                {
                    validKeyframeRange.End = _eventEditors[i + 1]._evt.Start;
                }
                _eventEditors[i].Render(rect, viewRange, pixelsPerFrame, validKeyframeRange);
            }

            switch (Event.current.type)
            {
            case EventType.ContextClick:
                if (trackHeaderRect.Contains(Event.current.mousePosition))
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Duplicate Track"), false, DuplicateTrack);
                    menu.AddItem(new GUIContent("Delete Track"), false, DeleteTrack);
                    menu.ShowAsContext();
                    Event.current.Use();
                }
                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && trackHeaderRect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.button == 0)                      // selecting
                    {
                        if (Event.current.control)
                        {
                            if (IsSelected())
                            {
                                SequenceEditor.Deselect(this);
                            }
                            else
                            {
                                SequenceEditor.Select(this);
                            }
                        }
                        else if (Event.current.shift)
                        {
                            SequenceEditor.Select(this);
                        }
                        else
                        {
                            SequenceEditor.SelectExclusive(this);
                            _timelineEditor.StartTrackDrag(this);
                            _offsetAnim.value           = _offsetAnim.target = new Vector2(0, rect.yMin) - Event.current.mousePosition;
                            EditorGUIUtility.hotControl = id;
                        }
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == id)
                {
                    EditorGUIUtility.hotControl = 0;
                    _offsetAnim.value           = _offsetAnim.target = Vector2.zero;

                    _timelineEditor.StopTrackDrag();

                    SequenceEditor.Repaint();
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == id)
                {
                    SequenceEditor.Repaint();
                    Event.current.Use();
                }
                break;
            }

            if (_track.CanTogglePreview())
            {
                GUI.color = FGUI.GetTextColor();

                if (!_track.IsPreviewing)
                {
                    Color c = GUI.color;
                    c.a       = 0.3f;
                    GUI.color = c;
                }

                GUI.DrawTexture(viewRect, _previewIcon);

                GUI.color = Color.white;
            }

#if UNITY_4_5
            if (_offsetAnim.isAnimating)
            {
                SequenceEditor.Repaint();
            }
#endif
        }
Пример #3
0
        protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            bool leftHandleVisible  = viewRange.Contains(Evt.Start);
            bool rightHandleVisible = viewRange.Contains(Evt.End);

            Rect leftHandleRect  = _eventRect; leftHandleRect.width = 4;
            Rect rightHandleRect = _eventRect; rightHandleRect.xMin = rightHandleRect.xMax - 4;

            if (leftHandleVisible && IsSelected)
            {
                EditorGUIUtility.AddCursorRect(leftHandleRect, MouseCursor.ResizeHorizontal, _leftHandleGuiId);
            }

            if (rightHandleVisible && IsSelected)
            {
                EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, _rightHandleGuiId);
            }

            switch (Event.current.type)
            {
            case EventType.Repaint:
                if (!viewRange.Overlaps(Evt.FrameRange))
                {
                    break;
                }

                GUIStyle evtStyle = GetEventStyle();

                GUI.backgroundColor = GetColor();

                evtStyle.Draw(_eventRect, _isSelected, _isSelected, false, false);

                string text = Evt.Text;
                if (text != null)
                {
                    var style = GetTextStyle();
                    //style.alignment = TextAnchor.MiddleCenter;
                    GUI.Label(_eventRect, text, style);
                }

                /*
                 * var leftRect = _eventRect;
                 * leftRect.xMax = leftRect.xMin + 16;
                 * GUI.Label(leftRect, Evt.Start.ToString(), GetTextStyle());
                 * var rightRect = _eventRect;
                 * rightRect.xMin = rightRect.xMax - 16;
                 * GUI.Label(rightRect, Evt.End.ToString(), GetTextStyle());
                 */
                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift)
                {
                    Vector2 mousePos = Event.current.mousePosition;

                    if (Event.current.button == 0)     // left click?
                    {
                        if (rightHandleVisible && rightHandleRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = _rightHandleGuiId;
                            //						keyframeOnSelect = evt.Start;
                            Event.current.Use();
                        }
                        else if (leftHandleVisible && leftHandleRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = _leftHandleGuiId;
                            //						keyframeOnSelect = evt.End;
                            Event.current.Use();
                        }
                        else if (_eventRect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = GuiId;
                            _mouseOffsetFrames          = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start;

                            if (IsSelected)
                            {
                                if (Event.current.control)
                                {
                                    SequenceEditor.Deselect(this);
                                }
                            }
                            else
                            {
                                if (Event.current.shift)
                                {
                                    SequenceEditor.Select(this);
                                }
                                else if (!Event.current.control)
                                {
                                    SequenceEditor.SelectExclusive(this);
                                }
                            }
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.button == 1 && _eventRect.Contains(Event.current.mousePosition))     // right click?
                    {
                        CreateEventContextMenu().ShowAsContext();
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == GuiId ||
                        EditorGUIUtility.hotControl == _leftHandleGuiId ||
                        EditorGUIUtility.hotControl == _rightHandleGuiId)
                    {
                        EditorGUIUtility.hotControl = 0;
                        Event.current.Use();
                        SequenceEditor.Repaint();
                        FinishMovingEventEditors();
                    }
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl != 0)
                {
                    if (EditorGUIUtility.hotControl == GuiId)
                    {
                        int t     = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames;
                        int delta = t - Evt.Start;
                        SequenceEditor.MoveEvents(delta);
                        Event.current.Use();
                    }
                    else if (EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId)
                    {
                        int leftLimit  = 0;
                        int rightLimit = 0;

                        bool draggingStart = EditorGUIUtility.hotControl == _leftHandleGuiId;

                        if (draggingStart)
                        {
                            leftLimit  = validKeyframeRange.Start;
                            rightLimit = Evt.End - 1;
                        }
                        else
                        {
                            leftLimit  = Evt.Start + 1;
                            rightLimit = validKeyframeRange.End;
                        }


                        int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x);

                        t = Mathf.Clamp(t, leftLimit, rightLimit);

                        int delta = t - (draggingStart ? Evt.Start : Evt.End);

                        if (draggingStart)
                        {
                            int newLength = Evt.Length - delta;
                            if (newLength < Evt.GetMinLength())
                            {
                                delta += newLength - Evt.GetMinLength();
                            }
                            if (newLength > Evt.GetMaxLength())
                            {
                                delta += newLength - Evt.GetMaxLength();
                            }
                        }
                        else
                        {
                            int newLength = Evt.Length + delta;
                            if (newLength < Evt.GetMinLength())
                            {
                                delta -= newLength - Evt.GetMinLength();
                            }
                            if (newLength > Evt.GetMaxLength())
                            {
                                delta -= newLength - Evt.GetMaxLength();
                            }
                        }

                        if (delta != 0)
                        {
                            if (draggingStart)
                            {
                                SequenceEditor.ResizeEventsLeft(delta);
                            }
                            else
                            {
                                SequenceEditor.ResizeEventsRight(delta);
                            }
                        }

                        Event.current.Use();
                    }
                }
                break;

            case EventType.Ignore:
                if (EditorGUIUtility.hotControl == GuiId ||
                    EditorGUIUtility.hotControl == _leftHandleGuiId ||
                    EditorGUIUtility.hotControl == _rightHandleGuiId)
                {
                    EditorGUIUtility.hotControl = 0;
                    SequenceEditor.Repaint();
                    FinishMovingEventEditors();
                }
                break;
            }
        }
Пример #4
0
        protected virtual void RenderList(Rect listRect, float headerWidth)
        {
            if (ContentOffset.x > 0)
            {
                Rect sideRect = listRect;
                sideRect.width = ContentOffset.x;

                if (Event.current.type == EventType.Repaint)
                {
                    GUI.color = BackgroundColor;
                    EditorGUI.DrawTextureAlpha(sideRect, EditorGUIUtility.whiteTexture);
                    GUI.color = Color.white;
                }
            }

            listRect.xMin += ContentOffset.x;
            headerWidth   -= ContentOffset.x;

            Rect editorRect = listRect;

            GUI.BeginGroup(listRect);
            editorRect.y      = 0;
            editorRect.x      = 0;
            editorRect.height = 0;

            for (int i = 0; i != _editors.Count; ++i)
            {
                editorRect.yMin   = editorRect.yMax;
                editorRect.height = _editors[i].Height;

                if (SequenceEditor.EditorDragged == _editors[i])
                {
                    Rect editorDraggedRect = editorRect;
                    editorDraggedRect.y = -_editors[i].Offset.value.y;

                    SequenceEditor.EditorDraggedRect = editorDraggedRect;

                    SequenceEditor.Repaint();
                }
                else
                {
                    if (SequenceEditor.EditorDragged != null && SequenceEditor.EditorDragged.Owner == this)
                    {
                        float mouseOffsetY     = SequenceEditor.EditorDragged.Offset.value.y;
                        float editorDraggedTop = Event.current.mousePosition.y - mouseOffsetY;
                        float editorDraggedBot = editorDraggedTop + SequenceEditor.EditorDraggedRect.height;

                        if (i < SequenceEditor.EditorDragged.Obj.GetId())
                        {
                            if (_editors[i].Offset.target.y == 0)
                            {
                                if (editorDraggedTop < editorRect.center.y)
                                {
                                    _editors[i].Offset.target = new Vector3(0, SequenceEditor.EditorDragged.Height, 0);
                                }
                                else
                                {
                                    _editors[i].Offset.target = Vector3.zero;
                                }
                            }
                            else
                            {
                                if (editorDraggedBot > editorRect.center.y + SequenceEditor.EditorDragged.Height)
                                {
                                    _editors[i].Offset.target = Vector3.zero;
                                }
                                else
                                {
                                    _editors[i].Offset.target = new Vector3(0, SequenceEditor.EditorDragged.Height, 0);
                                }
                            }
                        }
                        else if (i > SequenceEditor.EditorDragged.Obj.GetId())
                        {
                            if (_editors[i].Offset.target.y == 0)
                            {
                                if (editorDraggedBot > editorRect.center.y)
                                {
                                    _editors[i].Offset.target = new Vector3(0, -SequenceEditor.EditorDragged.Height, 0);
                                }
                                else
                                {
                                    _editors[i].Offset.target = Vector3.zero;
                                }
                            }
                            else
                            {
                                if (editorDraggedTop < editorRect.center.y - SequenceEditor.EditorDragged.Height)
                                {
                                    _editors[i].Offset.target = Vector3.zero;
                                }
                                else
                                {
                                    _editors[i].Offset.target = new Vector3(0, -SequenceEditor.EditorDragged.Height, 0);
                                }
                            }
                        }
                    }

                    Rect editorRenderRect = editorRect;
                    editorRenderRect.y += _editors[i].Offset.value.y;

                    _editors[i].Render(editorRenderRect, headerWidth);

                    Rect editorHeaderRect = editorRect;
                    editorHeaderRect.width = headerWidth;

                    if (EditorGUIUtility.hotControl == 0 && Event.current.type == EventType.MouseDrag && Event.current.button == 0 && editorHeaderRect.Contains(Event.current.mousePosition))
                    {
                        SequenceEditor.StartDraggingEditor(_editors[i]);
                        _editors[i].Offset.target = _editors[i].Offset.value = new Vector3(0, Event.current.mousePosition.y - editorRect.y, 0);
                    }
                }
            }

            GUI.EndGroup();
        }
Пример #5
0
        public void Render(int id, Rect rect, int hierarchyWidth, FrameRange viewRange, float pixelsPerFrame)
        {
            if (_timeline == null)
            {
                return;
            }

            rect.y += _offsetAnim.value.y;

            _rect = rect;

            float alpha = 1;

            if (EditorGUIUtility.hotControl == id)
            {
                rect.xMin += 5;
                rect.xMax -= 5;
                alpha      = 0.7f;
                Color c = GUI.color; c.a = alpha;
                GUI.color = c;
            }

            Rect hierarchyHeaderRect = rect; hierarchyHeaderRect.width = hierarchyWidth; hierarchyHeaderRect.height = HEADER_HEIGHT;

            Rect timelineHeaderRect = rect; timelineHeaderRect.height = HEADER_HEIGHT;

            Rect trackRect = timelineHeaderRect;

            trackRect.yMin   = timelineHeaderRect.yMax;
            trackRect.height = TRACK_HEIGHT;

            if (Event.current.type == EventType.Repaint)
            {
                GUI.color = FGUI.GetTimelineColor();
                GUI.DrawTexture(timelineHeaderRect, EditorGUIUtility.whiteTexture);
                GUI.color = new Color(1f, 1f, 1f, alpha);
            }

            if (_showTracks)
            {
                for (int i = 0; i != _trackEditors.Count; ++i)
                {
                    Vector3 upperLeft = trackRect.min;
                    Handles.color = FGUI.GetLineColor();

                    if (_trackDragged != null)
                    {
                        if (_trackDragged == _trackEditors[i])
                        {
                            Handles.DrawLine(upperLeft, upperLeft + new Vector3(trackRect.width, 0, 0));
                            trackRect.y += TRACK_HEIGHT;
                            continue;
                        }

                        if (i < _trackDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y < trackRect.yMax)
                        {
                            _trackEditors[i].SetOffset(new Vector2(0, TRACK_HEIGHT));
                        }
                        else if (i > _trackDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y > trackRect.yMin)
                        {
                            _trackEditors[i].SetOffset(new Vector2(0, -TRACK_HEIGHT));
                        }
                        else
                        {
                            _trackEditors[i].SetOffset(Vector2.zero);
                        }
                    }

                    GUI.color = new Color(0.3f, 0.3f, 0.3f, alpha);

                    GUI.color = new Color(1f, 1f, 1f, alpha);
                    _trackEditors[i].Render(_trackEditorIds[i], trackRect, hierarchyWidth, viewRange, pixelsPerFrame);

                    Handles.DrawLine(upperLeft, upperLeft + new Vector3(trackRect.width, 0, 0));

                    trackRect.y += TRACK_HEIGHT;
                }

                if (_trackDragged != null)
                {
                    Rect r = trackRect;
                    r.y = Event.current.mousePosition.y;
                    _trackDragged.Render(_trackEditorIds[_trackDragged.GetRuntimeObject().GetId()], r, hierarchyWidth, viewRange, pixelsPerFrame);
                }
            }

            Rect hierarchyLabelRect = hierarchyHeaderRect;

            hierarchyLabelRect.height = 20;
            hierarchyLabelRect.xMax   = hierarchyLabelRect.xMax - 23;

            Rect foldoutRect = hierarchyLabelRect;

            foldoutRect.width        = 16;
            hierarchyLabelRect.xMin += 16;

            string timelineHeaderName = _timeline.Owner != null ? _timeline.Owner.name : _timeline.name + " (Missing)";

            GUI.Label(hierarchyLabelRect, new GUIContent(timelineHeaderName), FGUI.GetTimelineHeaderStyle());

            _showTracks = EditorGUI.Foldout(foldoutRect, _showTracks, GUIContent.none);

            switch (Event.current.type)
            {
            case EventType.ContextClick:
                if (hierarchyHeaderRect.Contains(Event.current.mousePosition))
                {
                    GenericMenu menu = new GenericMenu();

                    if (Selection.activeGameObject == null || PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.Prefab || PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.ModelPrefab)
                    {
                        menu.AddDisabledItem(new GUIContent("Change Owner"));
                    }
                    else
                    {
                        menu.AddItem(new GUIContent("Change Owner to " + Selection.activeGameObject.name), false, ChangeOwner);
                    }

                    menu.AddItem(new GUIContent("Duplicate Timeline"), false, DuplicateTimeline);
                    menu.AddItem(new GUIContent("Delete Timeline"), false, DeleteTimeline);
                    menu.AddItem(new GUIContent("Add Timeline"), false, AddTimeline);

                    menu.ShowAsContext();
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == id)
                {
                    SequenceEditor.Repaint();
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == id)
                {
                    EditorGUIUtility.hotControl = 0;
                    _offsetAnim.value           = _offsetAnim.target = Vector2.zero;
                    SequenceEditor.Repaint();

                    SequenceEditor.StopTimelineDrag();
                    Event.current.Use();
                }
                break;

            case EventType.Repaint:
                Handles.color = FGUI.GetLineColor();
                Handles.DrawLine(new Vector3(rect.xMin, rect.yMax, 0), new Vector3(rect.xMax, rect.yMax, 0));
                break;

            case EventType.KeyDown:
                if (EditorGUIUtility.hotControl == id && Event.current.keyCode == KeyCode.Escape)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;
            }

            Rect timelineOptionsRect = hierarchyHeaderRect;

            timelineOptionsRect.xMin   = hierarchyHeaderRect.xMax - 20;
            timelineOptionsRect.yMin   = hierarchyHeaderRect.yMin;
            timelineOptionsRect.width  = 14;
            timelineOptionsRect.height = 14;

            if (Event.current.type == EventType.MouseDown && timelineOptionsRect.Contains(Event.current.mousePosition))
            {
                Event.current.Use();

                GenericMenu menu  = new GenericMenu();
                Type[]      types = typeof(FEvent).Assembly.GetTypes();
                List <KeyValuePair <Type, FEventAttribute> > validTypeList = new List <KeyValuePair <Type, FEventAttribute> >();

                foreach (Type t in types)
                {
                    if (!typeof(FEvent).IsAssignableFrom(t))
                    {
                        continue;
                    }

                    object[] attributes = t.GetCustomAttributes(typeof(FEventAttribute), false);
                    if (attributes.Length == 0)
                    {
                        continue;
                    }

                    validTypeList.Add(new KeyValuePair <Type, FEventAttribute>(t, (FEventAttribute)attributes[0]));
                }

                validTypeList.Sort(delegate(KeyValuePair <Type, FEventAttribute> x, KeyValuePair <Type, FEventAttribute> y)
                {
                    return(x.Value.menu.CompareTo(y.Value.menu));
                });

                foreach (KeyValuePair <Type, FEventAttribute> kvp in validTypeList)
                {
                    menu.AddItem(new GUIContent(kvp.Value.menu), false, AddTrackMenu, kvp);
                }

                menu.ShowAsContext();
            }

            GUI.color = FGUI.GetTextColor();

            GUI.DrawTexture(timelineOptionsRect, (Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "Plus.png", typeof(Texture2D)));

            if (Event.current.type == EventType.MouseDown && hierarchyHeaderRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.button == 0)                  // dragging
                {
                    EditorGUIUtility.hotControl = id;

                    _offsetAnim.value = _offsetAnim.target = new Vector2(0, hierarchyHeaderRect.yMin) - Event.current.mousePosition;

                    SequenceEditor.StartTimelineDrag(this);

                    Event.current.Use();
                }
            }

#if UNITY_4_5
            if (_offsetAnim.isAnimating)
            {
                _sequenceEditor.Repaint();
            }
#endif
        }
Пример #6
0
        private void SingleFrameRender(FrameRange viewRange, FrameRange validKeyframeRange)
        {
            Rect rect = _eventRect;

            rect.width = 15;
            rect.x     = SequenceEditor.PixelsPerFrame * Evt.Start;
            FrameRange range = Evt.FrameRange;

            range.Start    = SequenceEditor.GetFrameForX(rect.x);
            range.End      = range.Start + 1 + _mouseOffsetFrames + SequenceEditor.GetFrameForX(rect.width);
            Evt.FrameRange = range;
            switch (Event.current.type)
            {
            case EventType.Repaint:
            {
                if (!viewRange.Overlaps(Evt.FrameRange))
                {
                    break;
                }

                _mouseOffsetFrames = 0;

                GUIStyle evtStyle = _singleFrameStyle;
                GUI.backgroundColor = Color.white;
                Rect renderRect = rect;
                renderRect.x -= 2.5f;
                evtStyle.Draw(renderRect, _isSelected, _isSelected, false, false);

                string text = Evt.Text;
                if (text != null)
                {
                    GUIStyle style = GetTextStyle();
                    Vector2  size  = style.CalcSize(new GUIContent(text));
                    rect.size = size;
                    GUI.Label(rect, text, GetTextStyle());
                }
                break;
            }

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift)
                {
                    Vector2 mousePos = Event.current.mousePosition;
                    if (Event.current.button == 0)
                    {
                        if (rect.Contains(mousePos))
                        {
                            EditorGUIUtility.hotControl = GuiId;
                            _mouseOffsetFrames          = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start;

                            if (IsSelected)
                            {
                                if (Event.current.control)
                                {
                                    SequenceEditor.Deselect(this);
                                }
                            }
                            else
                            {
                                if (Event.current.shift)
                                {
                                    SequenceEditor.Select(this);
                                }
                                else if (!Event.current.control)
                                {
                                    SequenceEditor.SelectExclusive(this);
                                }
                            }
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.button == 1 && rect.Contains(Event.current.mousePosition))     // right click?
                    {
                        CreateEventContextMenu().ShowAsContext();
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == GuiId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                    SequenceEditor.Repaint();
                    FinishMovingEventEditors();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == GuiId)
                {
                    int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames;

                    int delta = t - Evt.Start;
                    if (t < viewRange.Start)
                    {
                        t = viewRange.Start;
                    }
                    else if (t > viewRange.End - 1)
                    {
                        t = viewRange.End - 1;
                    }
                    Evt.SingleFrame = t + 1;

                    SequenceEditor.MoveEvents(delta);
                    Event.current.Use();
                }
                break;

            case EventType.Ignore:
                if (EditorGUIUtility.hotControl == GuiId)
                {
                    EditorGUIUtility.hotControl = 0;
                    SequenceEditor.Repaint();
                    FinishMovingEventEditors();
                }
                break;
            }
        }