public TracingTimeline(VseGraphView vseGraphView, State vsWindowState, IMGUIContainer imguiContainer)
        {
            m_VseGraphView   = vseGraphView;
            m_VSWindowState  = vsWindowState;
            m_ImguiContainer = imguiContainer;
            m_TimeArea       = new TimeArea();
            m_Overlay        = new AnimEditorOverlay()
            {
                PlayHeadColor = new Color(0.2117647F, 0.6039216F, 0.8F)
            };
            m_State         = new TimelineState(m_TimeArea);
            m_Overlay.state = m_State;

            var         debugger = m_VSWindowState?.CurrentGraphModel?.Stencil?.Debugger;
            IGraphTrace trace    = debugger?.GetGraphTrace(m_VSWindowState?.CurrentGraphModel,
                                                           m_VSWindowState.CurrentTracingTarget);

            if (trace?.AllFrames != null && trace.AllFrames.Count > 0)
            {
                int firstFrame = trace.AllFrames[0].Frame;
                int lastFrame  = trace.AllFrames[trace.AllFrames.Count - 1].Frame;
                m_TimeArea.SetShownRange(
                    firstFrame - k_MinTimeVisibleOnTheRight,
                    lastFrame + k_MinTimeVisibleOnTheRight);
            }
        }
예제 #2
0
        float MousePositionToTime(Event evt)
        {
            float width = m_ContentRect.width;
            float time  = Mathf.Max(evt.mousePosition.x / width * state.VisibleTimeSpan + state.MinVisibleTime, 0);

            time = TimelineState.SnapToFrame(time, TimelineState.SnapMode.SnapToFrame);
            return(time);
        }
        public void OnGUI(Rect timeRect)
        {
            // sync timeline and tracing toolbar state both ways
            m_State.CurrentTime = TimelineState.FrameToTime(m_VSWindowState.CurrentTracingFrame);

            m_Overlay.HandleEvents();
            int timeChangedByTimeline = TimelineState.TimeToFrame(m_State.CurrentTime);

            // force graph update
            if (timeChangedByTimeline != m_VSWindowState.CurrentTracingFrame)
            {
                m_VSWindowState.CurrentTracingStep = -1;
            }
            m_VSWindowState.CurrentTracingFrame = timeChangedByTimeline;

            GUI.BeginGroup(timeRect);

            var         debugger = m_VSWindowState?.CurrentGraphModel?.Stencil?.Debugger;
            IGraphTrace trace    = debugger?.GetGraphTrace(m_VSWindowState?.CurrentGraphModel, m_VSWindowState.CurrentTracingTarget);

            if (trace?.AllFrames != null && trace.AllFrames.Count > 0)
            {
                float frameDeltaToPixel = m_TimeArea.FrameDeltaToPixel();
                int   firstFrame        = trace.AllFrames[0].Frame;
                int   lastFrame         = trace.AllFrames[trace.AllFrames.Count - 1].Frame;
                float start             = m_TimeArea.FrameToPixel(firstFrame);
                float width             = frameDeltaToPixel * Mathf.Max(lastFrame - firstFrame, 1);

                // draw active range
                EditorGUI.DrawRect(new Rect(start,
                                            timeRect.yMax - k_FrameRectangleHeight, width, k_FrameRectangleHeight), k_FrameHasDataColor);

                // draw per-node active ranges
                var framesPerNode = IndexFramesPerNode(ref s_FramesPerNodeCache, m_VSWindowState?.CurrentGraphModel.Stencil, trace, firstFrame, lastFrame, m_VSWindowState.CurrentTracingTarget, out bool invalidated);

                // while recording in unpaused playmode, adjust the timeline to show all data
                // same if the cached data changed (eg. Load a trace dump)
                if (EditorApplication.isPlaying && !EditorApplication.isPaused || invalidated)
                {
                    m_TimeArea.SetShownRange(
                        firstFrame - k_MinTimeVisibleOnTheRight,
                        lastFrame + k_MinTimeVisibleOnTheRight);
                }

                if (framesPerNode != null)
                {
                    INodeModel nodeModelSelected = m_VseGraphView.selection
                                                   .OfType <IHasGraphElementModel>()
                                                   .Select(x => x.GraphElementModel)
                                                   .OfType <INodeModel>()
                                                   .FirstOrDefault();

                    if (nodeModelSelected != null && framesPerNode.TryGetValue(nodeModelSelected.Guid, out List <(int InclusiveFirstFrame, int ExclusiveLastFrame)> frames))
                    {
                        foreach (var frameInterval in frames)
                        {
                            float xStart = m_TimeArea.FrameToPixel(frameInterval.InclusiveFirstFrame);
                            float xEnd   = m_TimeArea.FrameToPixel(frameInterval.ExclusiveLastFrame) - Mathf.Min(1, frameDeltaToPixel * 0.1f);
                            Rect  rect   = new Rect(
                                xStart,
                                timeRect.yMin,
                                xEnd - xStart,
                                timeRect.yMax);
                            EditorGUI.DrawRect(rect, k_FrameHasNodeColor);
                        }
                    }
                }
            }
            GUI.EndGroup();


            // time scales
            GUILayout.BeginArea(timeRect);
            m_TimeArea.Draw(timeRect);
            GUILayout.EndArea();

            // playing head
            m_Overlay.OnGUI(timeRect, timeRect);
        }