Exemplo n.º 1
0
        private void OnDragSelecting(Vector2 mousePos)
        {
            if (!_isDragSelecting)
            {
                return;
            }

            if (Event.current.shift)
            {
                EditorGUIUtility.AddCursorRect(_rect, MouseCursor.ArrowPlus);
            }
            else if (Event.current.control)
            {
                EditorGUIUtility.AddCursorRect(_rect, MouseCursor.ArrowMinus);
            }

            FrameRange selectedRange = new FrameRange();
            bool       isSelectingTimelines;

            Rect selectionRect = GetDragSelectionRect(_dragSelectingStartPos, mousePos, out selectedRange, out isSelectingTimelines);

            if (selectionRect.width == 0)
            {
                selectionRect.width = 1;
            }
            GUI.color = FGUI.GetSelectionColor();
            GUI.DrawTexture(selectionRect, EditorGUIUtility.whiteTexture);
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            Rect r = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);

            r.width -= EditorGUIUtility.labelWidth;

            EditorGUI.PrefixLabel(r, new GUIContent("Frame Rate"));

            r.width += EditorGUIUtility.labelWidth;

            EditorGUI.BeginChangeCheck();
            r.xMin += EditorGUIUtility.labelWidth;

            int frameRate = FGUI.FrameRatePopup(r, _sequence.FrameRate);

            if (EditorGUI.EndChangeCheck())
            {
                if (frameRate == -1)
                {
                    FChangeFrameRateWindow.Show(new Vector2(r.xMin - EditorGUIUtility.labelWidth, r.yMax), _sequence, FSequenceInspector.Rescale);
                    EditorGUIUtility.ExitGUI();
                }
                else
                {
                    Rescale(_sequence, frameRate, true);
                }
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Open In Flux Editor"))
            {
                FSequenceEditorWindow.Open(_sequence);
            }

            EditorGUILayout.Space();

            if (GUILayout.Button(_advancedInspector ? "Normal Inspector" : "Advanced Inspector"))
            {
                _advancedInspector = !_advancedInspector;
            }

            if (_advancedInspector)
            {
                EditorGUILayout.PropertyField(_timelineContainer);

                EditorGUI.BeginChangeCheck();
                bool showTimelines = EditorGUILayout.Toggle("Show Timelines", (_timelineContainer.objectReferenceValue.hideFlags & HideFlags.HideInHierarchy) == 0);
                if (EditorGUI.EndChangeCheck())
                {
                    if (showTimelines)
                    {
                        _timelineContainer.objectReferenceValue.hideFlags &= ~HideFlags.HideInHierarchy;
                    }
                    else
                    {
                        _timelineContainer.objectReferenceValue.hideFlags |= HideFlags.HideInHierarchy;
                    }
                }
            }

//			if( GUILayout.Button("Play") )
//				_sequence.Play();
        }
Exemplo n.º 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
        }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
0
        public void OnGUI()
        {
            FSequence sequence = _sequenceWindow.GetSequenceEditor().GetSequence();

            if (_selectedSequenceIndex < 0 && sequence != null)
            {
                for (int i = 0; i != _sequences.Length; ++i)
                {
                    if (_sequences[i] == sequence)
                    {
                        _selectedSequenceIndex = i;
                        break;
                    }
                }
            }


            GUI.contentColor = FGUI.GetTextColor();

            if (Event.current.type == EventType.MouseDown && Event.current.alt && _sequencePopupRect.Contains(Event.current.mousePosition))
            {
                Selection.activeObject = sequence;
                Event.current.Use();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.PrefixLabel(_sequenceLabelRect, _sequenceLabel);
            int newSequenceIndex = EditorGUI.Popup(_sequencePopupRect, _selectedSequenceIndex, _sequenceNames);

            if (EditorGUI.EndChangeCheck())
            {
                _selectedSequenceIndex = newSequenceIndex;
                _sequenceWindow.GetSequenceEditor().OpenSequence(_sequences[_selectedSequenceIndex]);
                _sequenceWindow.RemoveNotification();
                EditorGUIUtility.keyboardControl = 0;                 // deselect it
                EditorGUIUtility.ExitGUI();
            }

            if (GUI.Button(_sequenceAddButtonRect, new GUIContent((Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "Plus.png", typeof(Texture2D)), "Create New Sequence.."), EditorStyles.label))
            {
                FSequence newSequence = FSequenceEditorWindow.CreateSequence();
                _sequenceWindow.GetSequenceEditor().OpenSequence(newSequence);
                EditorGUIUtility.ExitGUI();
            }

            if (sequence == null)
            {
                return;
            }

            if (_sequenceSO == null || _sequenceSO.targetObject != sequence)
            {
                _sequenceSO         = new SerializedObject(sequence);
                _sequenceUpdateMode = _sequenceSO.FindProperty("_updateMode");
                _sequenceLength     = _sequenceSO.FindProperty("_length");
            }

            _sequenceSO.Update();

            if (_showUpdadeMode)
            {
                EditorGUI.PrefixLabel(_updateModeLabelRect, _updateModeLabel);
                EditorGUI.PropertyField(_updateModeFieldRect, _sequenceUpdateMode, GUIContent.none);
            }

            if (_showFramerate)
            {
                EditorGUI.PrefixLabel(_framerateLabelRect, _framerateLabel);
                EditorGUI.BeginChangeCheck();
                int newFrameRate = FGUI.FrameRatePopup(_framerateFieldRect, sequence.FrameRate);
                if (EditorGUI.EndChangeCheck())
                {
                    if (newFrameRate == -1)
                    {
                        FChangeFrameRateWindow.Show(new Vector2(_framerateLabelRect.xMin, _framerateLabelRect.yMax), sequence, FSequenceInspector.Rescale);
                    }
                    else
                    {
                        FSequenceInspector.Rescale(sequence, newFrameRate, true);
                    }
                }
            }

            if (_showLength)
            {
                EditorGUI.PrefixLabel(_lengthLabelRect, _lengthLabel);
                _sequenceLength.intValue = EditorGUI.IntField(_lengthFieldRect, _sequenceLength.intValue, _numberFieldStyle);
            }

            _sequenceSO.ApplyModifiedProperties();
        }
Exemplo n.º 6
0
        public static int TimeScrubber(Rect rect, int t, int frameRate, FrameRange range)
        {
            //		Rect actualRect = rect;
            //		actualRect.xMax -= 20; // buffer on the right

            Rect clickRect = rect;

            clickRect.yMin = clickRect.yMax - TIMELINE_SCRUBBER_HEIGHT;

            int length = range.Length;

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

            switch (Event.current.type)
            {
            case EventType.Repaint:
                int frames = range.Start;

                float width = rect.width;

                int maxFramesBetweenSteps = Mathf.Max(1, Mathf.FloorToInt(width / MIN_PIXELS_BETWEEN_FRAMES));

                int numFramesPerStep = Mathf.Max(1, length / maxFramesBetweenSteps);

                // multiple of 60 fps?
                if (numFramesPerStep < 30)
                {
                    if (numFramesPerStep <= 12)
                    {
                        if (numFramesPerStep != 5)
                        {
                            if (12 % numFramesPerStep != 0)
                            {
                                numFramesPerStep = 12;
                            }
                        }
                    }
                    else
                    {
                        numFramesPerStep = 30;
                    }
                }
                else if (numFramesPerStep < 60)
                {
                    numFramesPerStep = 60;
                }
                else
                {
                    int multiplesOf60 = numFramesPerStep / 60;
                    numFramesPerStep = (multiplesOf60 + 1) * 60;
                }

                int numFramesIter = numFramesPerStep < 30 ? 1 : numFramesPerStep / 10;

                Vector3 pt = new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0);

                Rect backgroundRect = clickRect;
                backgroundRect.xMin  = 0;
                backgroundRect.xMax += FSequenceEditor.RIGHT_BORDER;

//				GUI.color = new Color( 0.15f, 0.15f, 0.15f, 1f );//FGUI.GetTimelineColor();
//				GUI.DrawTexture( backgroundRect, EditorGUIUtility.whiteTexture );
//				GUI.color = Color.white;
                GUI.color = GetTextColor();                 // a little darker than it is originally to stand out
                GUI.Label(backgroundRect, GUIContent.none, FGUI.GetTimeScrubberStyle());

                Handles.color = GetLineColor();

                //			int framesBetweenSteps = maxFramesBetweenSteps / (maxFramesBetweenSteps * 10 / MIN_PIXELS_BETWEEN_FRAMES);
                //			float pixelsBetweenSteps = minPixelsBetweenSteps / framesBetweenSteps;
                //
                //			Debug.Log ( maxFramesBetweenSteps + " " + minPixelsBetweenSteps + " vs " + framesBetweenSteps + " " + pixelsBetweenSteps );

                GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel);
                labelStyle.normal.textColor = Color.white;
                labelStyle.alignment        = TextAnchor.UpperCenter;

                GUI.contentColor = FGUI.GetLineColor();

                frames = (frames / numFramesIter) * numFramesIter;
                while (frames <= range.End)
                {
                    pt.x = rect.x + (width * ((float)(frames - range.Start) / length));

                    if (pt.x >= rect.x)
                    {
                        if (frames % numFramesPerStep == 0)
                        {
                            Handles.DrawLine(pt, pt - new Vector3(0, rect.height - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0));

                            GUI.Label(new Rect(pt.x - 30, pt.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(frames, frameRate), labelStyle);
                        }
                        else
                        {
                            Vector3 smallTickPt = pt;
                            smallTickPt.y -= TIMELINE_SCRUBBER_TICK_HEIGHT;
                            Handles.DrawLine(smallTickPt, smallTickPt - new Vector3(0, TIMELINE_SCRUBBER_TICK_HEIGHT, 0));
                        }
                    }

                    frames += numFramesIter;
                }

                if (t >= 0 && range.Contains(t))
                {
                    Vector3 tStart = new Vector3(rect.x + (width * ((float)(t - range.Start) / length)), rect.yMin, 0);
                    Vector3 tEnd   = tStart;
                    tEnd.y = rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT;

                    Handles.color = Color.red;
                    Handles.DrawLine(tStart, tEnd);

                    GUI.contentColor = Color.red;
                    GUI.Label(new Rect(tEnd.x - 30, tEnd.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(t, frameRate), labelStyle);
                    GUI.contentColor = FGUI.GetTextColor();
                }

                GUI.color        = Color.white;
                GUI.contentColor = Color.white;

                Handles.color = GetLineColor();

                Handles.DrawLine(new Vector3(rect.x, rect.yMin, 0), new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_HEIGHT, 0));

                break;

            case EventType.MouseDown:
                if (EditorGUIUtility.hotControl == 0 && clickRect.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.hotControl = controlId;
                }
                goto case EventType.MouseDrag;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == controlId)
                {
                    Rect touchRect = rect;
                    touchRect.yMin = touchRect.yMax - TIMELINE_SCRUBBER_HEIGHT;
                    //			if( touchRect.Contains( Event.current.mousePosition ) )
                    {
                        //				Debug.Log( (Event.current.mousePosition.x - touchRect.xMin /
                        t = Mathf.Clamp(range.Start + Mathf.RoundToInt(((Event.current.mousePosition.x - touchRect.xMin) / touchRect.width) * range.Length), range.Start, range.End);
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == controlId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;
            }
            rect.height = TIMELINE_SCRUBBER_HEIGHT;

            return(t);
        }
Exemplo n.º 7
0
 public virtual Color GetColor()
 {
     return(FGUI.GetEventColor());
 }
Exemplo n.º 8
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
        }
Exemplo n.º 9
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
        }