Пример #1
0
 protected virtual void OnHeaderInput(Rect labelRect, Rect iconRect)
 {
     if (Event.current.type == EventType.MouseDown && Event.current.clickCount > 1 && labelRect.Contains(Event.current.mousePosition))
     {
         Selection.activeTransform = this.Obj.transform;
         Event.current.Use();
     }
     else if (Event.current.type == EventType.MouseDown && labelRect.Contains(Event.current.mousePosition))
     {
         if (Event.current.button == 0)
         {
             if (Event.current.shift)
             {
                 SequenceEditor.Select(this);
             }
             else
             {
                 SequenceEditor.SelectExclusive(this);
             }
         }
         else if (Event.current.button == 1)
         {
             ShowHeaderContextMenu();
         }
         Event.current.Use();
     }
 }
Пример #2
0
 public void SelectEvents(FrameRange range)
 {
     for (int i = 0; i != _eventEditors.Count; ++i)
     {
         if (range.Overlaps(_eventEditors[i]._evt.FrameRange))
         {
             SequenceEditor.Select(_eventEditors[i]);
         }
         else if (_eventEditors[i]._evt.Start > range.End)
         {
             break;
         }
     }
 }
Пример #3
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
        }
Пример #4
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;
            }
        }
Пример #5
0
        public override void Render(Rect rect, float headerWidth)
        {
            Rect = rect;

            _headerWidth = headerWidth;

            Rect headerRect = rect;

            headerRect.width = headerWidth;

            Rect viewRect = rect;

            viewRect.xMax   = rect.xMin + 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?
                        {
                            if (Event.current.shift)                            // turn all?
                            {
                                SequenceEditor.TurnOnAllPreviews(!Track.CanPreview);
                            }
                            else
                            {
                                OnTogglePreview(!Track.CanPreview);
                            }
                            FUtility.RepaintGameView();
                            Event.current.Use();
                        }
                    }
                }
            }

            Rect trackHeaderRect = rect;

            trackHeaderRect.xMax = viewRect.xMax;            //headerWidth;

            Color guiColor = GUI.color;

            bool selected = _isSelected;

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

            if (!Track.enabled)
            {
                Color c = guiColor;
                c.a       = 0.5f;
                GUI.color = c;
            }

            Rect trackLabelRect = trackHeaderRect;

            trackLabelRect.xMin += 8;

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

            rect.xMin = trackHeaderRect.xMax;

            if (rect.Contains(Event.current.mousePosition))
            {
                SequenceEditor.SetMouseHover(Event.current.mousePosition.x - rect.xMin, this);
            }

            FrameRange validKeyframeRange = new FrameRange(0, SequenceEditor.Sequence.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.Sequence.Length;
                }
                else
                {
                    validKeyframeRange.End = _eventEditors[i + 1].Evt.Start;
                }
                _eventEditors[i].Render(rect, SequenceEditor.ViewRange, SequenceEditor.PixelsPerFrame, validKeyframeRange);
            }

            switch (Event.current.type)
            {
            case EventType.ContextClick:
                if (trackHeaderRect.Contains(Event.current.mousePosition))
                {
                    OnHeaderContextClick();
                }
                else if (Rect.Contains(Event.current.mousePosition))
                {
                    OnBodyContextClick();
                }
                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);
                        }
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
//				if( EditorGUIUtility.hotControl == GuiId )
//				{
//					EditorGUIUtility.hotControl = 0;
//					_offsetAnim.value = _offsetAnim.target = Vector2.zero;
//
////					if( TimelineEditor ) TimelineEditor.StopTrackDrag();
//
//					SequenceEditor.Repaint();
//					Event.current.Use();
//				}
                break;

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

            if (Track.CanTogglePreview)
            {
                GUI.color = GetPreviewIconColor();                //FGUI.GetTextColor();

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

                GUI.DrawTexture(viewRect, _previewIcon);

                GUI.color = Color.white;
            }

            Handles.color = FGUI.GetLineColor();
            Handles.DrawLine(Rect.min, Rect.min + new Vector2(Rect.width, 0));
            Handles.DrawLine(Rect.max, Rect.max - new Vector2(Rect.width, 0));

            GUI.color = guiColor;
        }
Пример #6
0
        public override void Render(Rect rect, float headerWidth)
        {
            Rect = rect;

            HeaderWidth = headerWidth;

            Rect headerRect = rect;

            headerRect.width = headerWidth;

            Rect enableButtonRect = rect;

            enableButtonRect.xMax   = rect.xMin + headerWidth;
            enableButtonRect.xMin   = enableButtonRect.xMax - 16;
            enableButtonRect.height = 16;

            Rect trackHeaderRect = rect;

            trackHeaderRect.width = headerWidth;

            Color guiColor = GUI.color;

            bool selected = _isSelected;

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

            GUI.color = GetPreviewIconColor();

            if (!Track.enabled)
            {
                Color c = guiColor;
                c.a       = 0.5f;
                GUI.color = c;
            }

            if (FGUI.Button(enableButtonRect, _enableContent))
            {
                if (Event.current.shift) // turn all?
                {
                    SequenceEditor.EnableAllTracks(!Track.enabled);
                }
                else
                {
                    OnToggle(!Track.enabled);
                }
                FUtility.RepaintGameView();
                Event.current.Use();
            }

            Rect trackLabelRect = trackHeaderRect;

            trackLabelRect.xMin += 8;
            RenderHeader(trackLabelRect, new GUIContent(Track.name));

            rect.xMin = trackHeaderRect.xMax;

            if (rect.Contains(Event.current.mousePosition))
            {
                SequenceEditor.SetMouseHover(Event.current.mousePosition.x - rect.xMin, this);
            }

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

            _contentOffset = rect.min;

            GUI.BeginGroup(rect);

            rect.x = 0;
            rect.y = 0;

            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.Sequence.Length;
                }
                else
                {
                    validKeyframeRange.End = _eventEditors[i + 1].Evt.Start;
                }

                rect.xMin = SequenceEditor.GetXForFrame(_eventEditors[i].Evt.Start);
                rect.xMax = SequenceEditor.GetXForFrame(_eventEditors[i].Evt.End);
                _eventEditors[i].Render(rect, SequenceEditor.ViewRange, SequenceEditor.PixelsPerFrame, validKeyframeRange);
            }

            GUI.EndGroup();

            switch (Event.current.type)
            {
            case EventType.ContextClick:
                if (trackHeaderRect.Contains(Event.current.mousePosition))
                {
                    OnHeaderContextClick();
                }
                else if (Rect.Contains(Event.current.mousePosition))
                {
                    OnBodyContextClick();
                }
                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);
                        }
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                break;

            case EventType.MouseDrag:
                break;
            }

            Handles.color = FGUI.GetLineColor();
            Handles.DrawLine(Rect.min, Rect.min + new Vector2(Rect.width, 0));
            Handles.DrawLine(Rect.max, Rect.max - new Vector2(Rect.width, 0));

            GUI.color = guiColor;
        }
Пример #7
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;
            }
        }