Ejemplo n.º 1
0
        public void OnGUI()
        {
            if (_timelineEditors == null)
            {
                return;
            }

            if (_timelineEditors.Count == 0)
            {
                if (_renderingOnEditorWindow)
                {
                    _renderingOnEditorWindow.ShowNotification(new GUIContent("Drag GameObjects Here"));
                }
            }

            _pixelsPerFrame = (_sequenceRect.width - _timelineHeaderWidth) / _viewRange.Length;

            if (_timelineEditorIds.Length != _timelineEditors.Count)
            {
                _timelineEditorIds     = new int[_timelineEditors.Count];
                _timelineEditorHeights = new float[_timelineEditors.Count];
            }

            int timelineHeaderResizerId = EditorGUIUtility.GetControlID(FocusType.Passive);

            float sequenceViewHeight = 0;

            for (int i = 0; i != _timelineEditors.Count; ++i)
            {
                _timelineEditorIds[i]     = EditorGUIUtility.GetControlID(FocusType.Passive);
                _timelineEditorHeights[i] = _timelineEditors[i].GetHeight();
                sequenceViewHeight       += _timelineEditorHeights[i];

                _timelineEditors[i].ReserveTrackGuiIds();
            }

            _scrollPos.y = GUI.VerticalScrollbar(_verticalScrollerRect, _scrollPos.y, Mathf.Min(_sequenceRect.height, sequenceViewHeight), 0, sequenceViewHeight);

            Rect scrolledViewRect = _viewRect;

//			scrolledViewRect.yMin -= _scrollPos.y;

            GUI.BeginGroup(scrolledViewRect);

            Rect timelineRect = _sequenceRect;

            timelineRect.y      = -_scrollPos.y;
            timelineRect.height = 0;

            Rect timelineDraggedRect = new Rect();

//			Debug.Log( "sequence: " + _sequenceRect + " scrubber: " + _timeScrubberRect + " width: " + _timelineHeaderWidth );

            Handles.color = FGUI.GetLineColor();

            for (int i = 0; i != _timelineEditors.Count; ++i)
            {
                timelineRect.yMin   = timelineRect.yMax;
                timelineRect.height = _timelineEditors[i].GetHeight();

                if (_timelineDragged != null)
                {
                    if (_timelineDragged == _timelineEditors[i])
                    {
                        timelineDraggedRect = timelineRect;
                        continue;
                    }
                    else if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()])
                    {
                        if (i < _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y < timelineRect.yMax)
                        {
                            _timelineEditors[i].SetOffset(new Vector2(0, _timelineDragged.GetHeight()));
                        }
                        else if (i > _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y > timelineRect.yMin)
                        {
                            _timelineEditors[i].SetOffset(new Vector2(0, -_timelineDragged.GetHeight()));
                        }
                        else
                        {
                            _timelineEditors[i].SetOffset(Vector2.zero);
                        }
                    }
                }

                _timelineEditors[i].Render(_timelineEditorIds[i], timelineRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame);
            }

            if (_timelineDragged != null)
            {
                if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()])
                {
                    timelineDraggedRect.y = Event.current.mousePosition.y;
                }
//				timelineRect.yMin = Event.current.mousePosition.y;
//				timelineRect.height = _timelineDragged.GetHeight();
                _timelineDragged.Render(_timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()], timelineDraggedRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame);
            }

            switch (Event.current.type)
            {
            case EventType.MouseDown:

//				bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt);
//
//				if( middleClick ) // middle button
                if (Event.current.button == 0)
                {
                    StartDragSelecting(Event.current.mousePosition);
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (_isDragSelecting)
                {
                    StopDragSelecting(Event.current.mousePosition);
                    Event.current.Use();
                }
                break;

            case EventType.Ignore:
                if (_isDragSelecting)
                {
                    StopDragSelecting(Event.current.mousePosition);
                }
                break;

            case EventType.Repaint:
                if (_isDragSelecting)
                {
                    OnDragSelecting(Event.current.mousePosition);
                }

                break;
            }

            GUI.EndGroup();

            if (_viewRange.End > _sequence.Length)
            {
                _viewRange.Start = 0;
                _viewRange.End   = _sequence.Length;
            }

            int newT = FGUI.TimeScrubber(_timeScrubberRect, _sequence.GetCurrentFrame(), _sequence.FrameRate, _viewRange);

            if (newT != _sequence.GetCurrentFrame())
            {
//				_sequence.SetCurrentFrameEditor( newT );
                SetCurrentFrame(newT);

                if (Application.isPlaying)
                {
                    Play(false);
                    Pause();
                }
//				Repaint();
//				SceneView.RepaintAll();
//				UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
//				FUtility.RepaintGameView();
            }

            _viewRange = FGUI.ViewRangeBar(_viewRangeRect, _viewRange, _sequence.Length);

            if (_timelineHeaderResizerRect.Contains(Event.current.mousePosition))
            {
                EditorGUIUtility.AddCursorRect(_timelineHeaderResizerRect, MouseCursor.ResizeHorizontal);
            }

            switch (Event.current.type)
            {
            case EventType.MouseDown:

                bool leftClick = Event.current.button == 0 && !Event.current.alt;
//				bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt);

                if (leftClick)                  // left button
                {
                    if (EditorGUIUtility.hotControl == 0 && _timelineHeaderResizerRect.Contains(Event.current.mousePosition))
                    {
                        EditorGUIUtility.hotControl = timelineHeaderResizerId;
                        Event.current.Use();
                    }
                    else if (_rect.Contains(Event.current.mousePosition))
                    {
                        DeselectAll();
                        Event.current.Use();
                    }
                }
//				else if( middleClick ) // middle button
//				{
//					StartDragSelecting( Event.current.mousePosition );
//					Event.current.Use();
//				}
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == timelineHeaderResizerId)
                {
                    _timelineHeaderWidth = (int)Mathf.Max(MINIMUM_HEADER_WIDTH, _timelineHeaderWidth + Event.current.delta.x);

                    RebuildLayout(_rect);
                    EditorWindow.GetWindow <FSequenceEditorWindow>().Repaint();
                    Event.current.Use();
                }

                if (_isDragSelecting)
                {
                    Repaint();
                }

                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == timelineHeaderResizerId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
//				if( _isDragSelecting )
//				{
//					StopDragSelecting( Event.current.mousePosition );
//					Event.current.Use();
//				}
                break;

            case EventType.Repaint:
                Rect dragArea = _timelineHeaderResizerRect;
                dragArea.xMax -= 10;
                dragArea.xMin  = dragArea.xMax - 16;
                GUIStyle dragStyle = FUtility.GetFluxSkin().GetStyle("HorizontalPanelSeparatorHandle");
                dragStyle.Draw(dragArea, GUIContent.none, 0);
//				GUI.DrawTexture( dragArea, EditorGUIUtility.whiteTexture );
                Handles.color = FGUI.GetLineColor();                // new Color(0.8f, 0.8f, 0.8f, 0.2f);
                Handles.DrawLine(new Vector3(_viewRect.xMin - 16, _sequenceRect.yMax, 0), new Vector3(_viewRect.xMax - RIGHT_BORDER, _sequenceRect.yMax, 0));
//				Handles.color = Color.black;
                break;

            case EventType.ScrollWheel:
                if (_viewRect.Contains(Event.current.mousePosition))
                {
                    _scrollPos.y += Event.current.delta.y * SCROLL_WHEEL_SPEED;
                    Event.current.Use();
                }
                break;
            }

#if FLUX_TRIAL
            GUIStyle watermarkLabel = new GUIStyle(GUI.skin.label);
            watermarkLabel.fontSize = 24;
            GUIContent watermark     = new GUIContent("..::FLUX TRIAL::..");
            Vector2    watermarkSize = watermarkLabel.CalcSize(watermark);
            Rect       watermarkRect = new Rect(_rect.width * 0.5f - watermarkSize.x * 0.5f, _rect.height * 0.5f - watermarkSize.y * 0.5f, watermarkSize.x, watermarkSize.y);

            GUI.color = new Color(1f, 1f, 1f, 0.4f);
            GUI.Label(watermarkRect, watermark, watermarkLabel);
#endif
        }
Ejemplo n.º 2
0
        public void OnGUI()
        {
            FSequence  sequence  = _window.GetSequenceEditor().GetSequence();
            FrameRange viewRange = _window.GetSequenceEditor().GetViewRange();

            GUI.contentColor = FGUI.GetTextColor();

            bool goToFirst    = false;
            bool goToPrevious = false;
            bool goToNext     = false;
            bool goToLast     = false;

            if (Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode == KeyCode.Comma)
                {
                    goToFirst    = Event.current.shift;
                    goToPrevious = !goToFirst;
                    Event.current.Use();
                    _window.Repaint();
                }

                if (Event.current.keyCode == KeyCode.Period)
                {
                    goToLast = Event.current.shift;
                    goToNext = !goToLast;
                    Event.current.Use();
                    _window.Repaint();
                }
            }

            if (GUI.Button(_firstFrameButtonRect, _firstFrame, EditorStyles.miniButtonLeft) || goToFirst)
            {
                GoToFrame(viewRange.Start);
            }

            if (GUI.Button(_previousFrameButtonRect, _previousFrame, EditorStyles.miniButtonMid) || goToPrevious)
            {
                GoToFrame(viewRange.Cull(sequence.GetCurrentFrame() - 1));
            }

            GUIStyle numberFieldStyle = new GUIStyle(EditorStyles.numberField);

            numberFieldStyle.alignment = TextAnchor.MiddleCenter;

//			Debug.Log("hot control: " + EditorGUIUtility.hotControl + " keyboard control: " + EditorGUIUtility.keyboardControl );

            if (sequence != null)
            {
                if (sequence.GetCurrentFrame() < 0)
                {
                    EditorGUI.BeginChangeCheck();
                    string frameStr = EditorGUI.TextField(_currentFrameFieldRect, string.Empty, numberFieldStyle);
                    if (EditorGUI.EndChangeCheck())
                    {
                        int newCurrentFrame = 0;
                        int.TryParse(frameStr, out newCurrentFrame);
                        newCurrentFrame = Mathf.Clamp(newCurrentFrame, 0, sequence.Length);
                        _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame);
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    int newCurrentFrame = Mathf.Clamp(EditorGUI.IntField(_currentFrameFieldRect, sequence.GetCurrentFrame(), numberFieldStyle), 0, sequence.Length);
                    if (EditorGUI.EndChangeCheck())
                    {
                        _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame);
                    }
                }
            }

            if (GUI.Button(_nextFrameButtonRect, _nextFrame, EditorStyles.miniButtonMid) || goToNext)
            {
                GoToFrame(viewRange.Cull(sequence.GetCurrentFrame() + 1));
            }

            if (GUI.Button(_lastFrameButtonRect, _lastFrame, EditorStyles.miniButtonRight) || goToLast)
            {
                GoToFrame(viewRange.End);
            }

//			if( GUI.Button( _playBackwardButtonRect, _window.IsPlaying ? "[] Stop" : "< Play", EditorStyles.miniButtonLeft) )
//			{
//				if( _window.IsPlaying )
//				{
//					_window.Stop();
//				}
//				else
//				{
//					_window.Play();
//				}
//			}

            if (GUI.Button(_stopButtonRect, _stop, EditorStyles.miniButtonLeft))
            {
                Stop();
            }

            if (GUI.Button(_playForwardButtonRect, _window.IsPlaying ? _pause : _playForward, EditorStyles.miniButtonRight))
            {
                if (_window.IsPlaying)
                {
                    Pause();
                }
                else
                {
                    Play();
                }
            }


            if (_showViewRange)
            {
                EditorGUI.PrefixLabel(_viewRangeLabelRect, _viewRangeLabel);

                EditorGUI.BeginChangeCheck();

                viewRange.Start = EditorGUI.IntField(_viewRangeStartRect, viewRange.Start, numberFieldStyle);

                EditorGUI.PrefixLabel(_viewRangeDashRect, _viewRangeDash);

                viewRange.End = EditorGUI.IntField(_viewRangeEndRect, viewRange.End, numberFieldStyle);

                if (EditorGUI.EndChangeCheck())
                {
                    _window.GetSequenceEditor().SetViewRange(viewRange);
                }
            }
        }