private void DrawAnimationTimeline(FrameDebugProviderInfo providerInfo, AnimationDebugRecord animStateRecord, TimelineWidget.DrawInfo drawInfo)
        {
            if (animStateRecord.AnimationRecords.Count == 0)
            {
                return;
            }

            // Animations
            for (int i = 0; i < animStateRecord.AnimationRecords.Count; ++i)
            {
                DrawAnimationWidget(providerInfo, animStateRecord, i, drawInfo);
            }
        }
        public void OnPostDraw()
        {
            if (m_SelectedAnimFrame.IsValid)
            {
                AnimationDebugRecord animStateRecord = Debugger.frameDebugger.FindAggregate <AnimationDebugRecord>(m_SelectedAnimFrame.providerIdentifier);
                if (animStateRecord == null)
                {
                    m_SelectedAnimFrame = AnimationFrameIdentifier.CreateInvalid();
                    return;
                }

                Assert.IsTrue(m_SelectedAnimFrame.animIndex < animStateRecord.AnimationRecords.Count);
                if (m_SelectedAnimFrame.animIndex >= animStateRecord.AnimationRecords.Count)
                {
                    m_SelectedAnimFrame = AnimationFrameIdentifier.CreateInvalid();
                    return;
                }

                AnimationRecord animRecord = animStateRecord.AnimationRecords[m_SelectedAnimFrame.animIndex];

                Assert.IsTrue(m_SelectedAnimFrame.animFrameIndex < animRecord.animFrames.Count);
                if (m_SelectedAnimFrame.animFrameIndex >= animRecord.animFrames.Count)
                {
                    m_SelectedAnimFrame = AnimationFrameIdentifier.CreateInvalid();
                    return;
                }

                AnimationFrameInfo animFrame = animRecord.animFrames[m_SelectedAnimFrame.animFrameIndex];

                string  label     = $"{animRecord.animName}\nFrame:{animFrame.animFrame:0.00}\nWeight:{animFrame.weight:0.00}";
                Vector2 labelSize = TimelineWidget.GetLabelSize(label);

                Rect toolTipRect = new Rect(Event.current.mousePosition.x + 20, Event.current.mousePosition.y, labelSize.x + 5.0f, labelSize.y + 5.0f);

                TimelineWidget.DrawRectangleWithDetour(toolTipRect, kTooltipBackgroundColor, kTooltipDetourColor);
                TimelineWidget.DrawLabel(toolTipRect, label, kTooltipTextColor);

                m_SelectedAnimFrame = AnimationFrameIdentifier.CreateInvalid();
            }
        }
        public void Draw(FrameDebugProviderInfo providerInfo, IFrameAggregate aggregate, TimelineWidget.DrawInfo drawInfo)
        {
            AnimationDebugRecord animDebugRecord = (AnimationDebugRecord)aggregate;

            DrawAnimationTimeline(providerInfo, animDebugRecord, drawInfo);
        }
 private float GetAnimStateTimelineHeight(AnimationDebugRecord animStateRecord)
 {
     return(animStateRecord.AnimationRecords.Count > 0 ? animStateRecord.NumLines * kAnimWidgetOffset : 0.0f);
 }
        private void DrawAnimationWidget(FrameDebugProviderInfo providerInfo, AnimationDebugRecord animStateRecord, int animIndex, TimelineWidget.DrawInfo drawInfo)
        {
            AnimationRecord animation = animStateRecord.AnimationRecords[animIndex];

            if (animation.endTime < drawInfo.timeline.startTime)
            {
                return;
            }

            if (animation.startTime > drawInfo.timeline.endTime)
            {
                return;
            }

            float startPosition = drawInfo.GetPixelPosition(animation.startTime);
            float endPosition   = drawInfo.GetPixelPosition(animation.endTime);

            Rect drawRect = drawInfo.timeline.drawRect;

            drawRect.y += animation.rank * kAnimWidgetOffset;
            Rect animRect = new Rect(startPosition, drawRect.y, endPosition - startPosition, kAnimWidgetHeight);

            TimelineWidget.DrawRectangleWithDetour(animRect, kAnimWidgetBackgroundColor, kAnimWidgetDetourColor);

            int barStartPosition = Missing.truncToInt(startPosition) + 1;
            int maxBarPosition   = Missing.truncToInt(endPosition);

            for (int i = 0; i < animation.animFrames.Count; ++i)
            {
                int barEndPosition = Missing.truncToInt(drawInfo.GetPixelPosition(animation.animFrames[i].endTime));
                if (barEndPosition > barStartPosition)
                {
                    float weight = animation.animFrames[i].weight;
                    if (weight < 1.0f)
                    {
                        Rect barRect = new Rect(barStartPosition, drawRect.y, barEndPosition - barStartPosition, (1.0f - weight) * kAnimWidgetHeight);
                        TimelineWidget.DrawRectangle(barRect, kAnimWidgetWeightColor);
                    }
                }
                barStartPosition = barEndPosition;
            }

            TimelineWidget.DrawLabelInsideRectangle(animRect, animation.animName, kAnimWidgetTextColor);

            // check if mouse is hovering the anim widget
            if (endPosition > startPosition && animRect.Contains(Event.current.mousePosition))
            {
                float mouseNormalizedTime = (Event.current.mousePosition.x - startPosition) / (endPosition - startPosition);
                float mouseTime           = animation.startTime + mouseNormalizedTime * (animation.endTime - animation.startTime);

                float curStartTime = animation.startTime;
                for (int i = 0; i < animation.animFrames.Count; ++i)
                {
                    float curEndTime = animation.animFrames[i].endTime;
                    if (curStartTime <= mouseTime && mouseTime <= curEndTime)
                    {
                        m_SelectedAnimFrame.providerIdentifier = providerInfo.uniqueIdentifier;
                        m_SelectedAnimFrame.animIndex          = animIndex;
                        m_SelectedAnimFrame.animFrameIndex     = i;
                        m_SelectedAnimFrame.mouseX             = Missing.truncToInt(Event.current.mousePosition.x);
                        return;
                    }
                    curStartTime = curEndTime;
                }
            }
        }