Beispiel #1
0
        protected override void FloatingOnGUI(int depth)
        {
            GUILayout.Box("", FloatingBackground, GUILayout.Width(FloatingWidth), GUILayout.Height(17.0f));

            if (Event.current.type == EventType.Repaint)
            {
                var lastRect = GUILayoutUtility.GetLastRect();
                lastRect.x            += GetXOffsetForDepth(depth);
                lastRect.width        -= GetXOffsetForDepth(depth);
                FloatingBackgroundRect = lastRect;
            }

            if (IsSelected)
            {
                GUI.Box(new Rect(0, FloatingBackgroundRect.y, FloatingBackgroundRect.width + FloatingBackgroundRect.x, FloatingBackgroundRect.height), "");
            }

            using (IsSelected == true ? new Shared.GUIChangeColor(AnimationCurveEditorUtility.GetCurveColor(CurveIndex)) : null)
            {
                var displayContent = new GUIContent(String.Format("{0}{1}", Prefix, PostFix), ColorIndicatorTexture);
                GUI.Label(FloatingBackgroundRect, displayContent);
            }
        }
Beispiel #2
0
        public void OnGUI()
        {
            if (Event.current.commandName == "UndoRedoPerformed")
            {
                return;
            }

            if (Curves == null || Curves.Count == 0)
            {
                GUILayout.Box("", TimelineBackground, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(MaxHeight));
                if (Event.current.type == EventType.Repaint)
                {
                    DisplayArea = GUILayoutUtility.GetLastRect();
                }
                GUI.Label(DisplayArea, "Press the Animate button to start animating properties!");
                return;
            }

            if (Curves.Any(curve => curve == null))
            {
                throw new NullReferenceException("One of the curves is null, this shouldn't happen");
            }

            if (EditorWindow == null)
            {
                throw new NullReferenceException("Editor Window must be assigned a value");
            }

            if (RebuildCurvesOnNextGUI)
            {
                CalculateBounds();
                RebuildCachedCurveInformation();

                // Sometimes, depending on the update order vs the serialization order, this can be null during Undo / Redo :/
                if (EditorWindow != null)
                {
                    EditorWindow.Repaint();
                }
            }
            RebuildCurvesOnNextGUI = false;

            foreach (var cachedRenderingData in cachedKeyframePositions)
            {
                if (SelectedObjects.Contains(cachedRenderingData.Key))
                {
                    cachedRenderingData.Value.IsKeyframeSelected = true;
                }
                else
                {
                    cachedRenderingData.Value.IsKeyframeSelected = false;
                }
            }

            if (cachedKeyframePositions == null || (cachedKeyframePositions.Count == 0 && Curves.Count > 0))
            {
                RebuildCachedCurveInformation();
            }

            GUILayout.Box("", TimelineBackground, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(MaxHeight));

            if (Event.current.type == EventType.Repaint)
            {
                var displayAreaRect     = GUILayoutUtility.GetLastRect();
                var previousDisplayArea = DisplayArea;

                DisplayArea = displayAreaRect;

                if (DisplayArea != previousDisplayArea)
                {
                    RebuildCachedCurveInformation();
                }
            }

            using (new GUIBeginArea(DisplayArea))
            {
                if (Event.current.type == EventType.Repaint)
                {
                    DrawGrid();
                }

                for (var n = 0; n < Curves.Count; n++)
                {
                    DrawCurve(Curves[n], AnimationCurveEditorUtility.GetCurveColor(n));
                }

                HandleEvent();
            }
        }