示例#1
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
        }
示例#2
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);
        }
示例#3
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
        }