コード例 #1
0
        public static DrawInfo Create(Rect drawRect, float layoutStartTime, float layoutEndTime, float timelineStartTime, float timelineEndTime)
        {
            DrawInfo drawInfo = new DrawInfo()
            {
                layout = new DrawRangeInfo()
                {
                    drawRect  = drawRect,
                    startTime = layoutStartTime,
                    endTime   = layoutEndTime
                }
            };

            timelineStartTime = math.clamp(timelineStartTime, layoutStartTime, layoutEndTime);
            timelineEndTime   = math.clamp(timelineEndTime, layoutStartTime, layoutEndTime);

            float timelineStartPos = drawInfo.GetPixelPosition(timelineStartTime);
            float timelineEndPos   = drawInfo.GetPixelPosition(timelineEndTime);

            drawInfo.timeline = new DrawRangeInfo()
            {
                drawRect  = new Rect(timelineStartPos, drawRect.y, timelineEndPos - timelineStartPos, drawRect.height),
                startTime = timelineStartTime,
                endTime   = timelineEndTime
            };

            return(drawInfo);
        }
コード例 #2
0
    public static void DrawLineAtTime(DrawInfo drawInfo, float timeInSeconds, Color color)
    {
        float position = drawInfo.GetPixelPosition(timeInSeconds);

        float textLineHeight = GUI.skin.font.lineHeight;

        Rect r = new Rect(position, 0.0f, 1, drawInfo.layout.drawRect.height - textLineHeight);

        GUI.color = color;
        GUI.DrawTexture(r, EditorGUIUtility.whiteTexture);
        GUI.color = Color.white;
    }
コード例 #3
0
    public static void DrawNotations(
        DrawInfo drawInfo,
        int sampleRate               = 60,
        float tickmarkHeight         = 32f,
        bool above                   = false,
        TimelineViewMode labelFormat = TimelineViewMode.seconds)
    {
        // first figure out what step I should use
        float majorStepSize = 200.0f;

        float width  = drawInfo.layout.drawRect.width;
        float height = drawInfo.layout.drawRect.height;

        float numSteps = Mathf.Ceil(width / majorStepSize);

        float scale     = drawInfo.layout.Duration;
        float scaleStep = scale / numSteps;

        // Get the time step
        float modScale     = scaleStep;
        float modScaleMult = 1.0f;

        while (modScale < 1.0f)
        {
            modScale     *= 10.0f;
            modScaleMult *= 10.0f;
        }
        while (modScale > 10.0f)
        {
            modScale     /= 10.0f;
            modScaleMult /= 10.0f;
        }

        // modify scale to be divisible by 1/2/4/5
        if (modScale > 5.0f)
        {
            modScale = 5.0f;
        }
        else if (modScale > 2.5f)
        {
            modScale = 2.5f;
        }
        else if (modScale > 2.0f)
        {
            modScale = 2.0f;
        }
        else
        {
            modScale = 1.0f;
        }

        modScale /= modScaleMult;

        // with fixed scale need to find our start point
        float startOffset = drawInfo.layout.startTime % modScale;
        float start       = drawInfo.layout.startTime - startOffset;

        float rangeEnd = drawInfo.layout.startTime + scale;

        float textLineHeight = GUI.skin.font.lineHeight;

        float tickmarkHeightSmall  = tickmarkHeight * 0.5f;
        float tickmarkHeightMedium = tickmarkHeight * 0.75f;
        float verticalPosition     = above ? height :  height - textLineHeight;

        // draw
        for (int i = -1;; ++i)
        {
            float point = start + modScale * i;
            if (point > rangeEnd)
            {
                break;
            }

            // draw minor steps
            for (int j = 1; j < 5; ++j)
            {
                float subPoint = point + (modScale / 5) * j;

                float position = drawInfo.GetPixelPosition(subPoint);

                float heightThis = (j == 2 ? tickmarkHeightSmall : tickmarkHeightMedium);

                Rect r = new Rect(position, verticalPosition - heightThis, 1, heightThis);

                GUI.color = k_MinorTickColor;
                GUI.DrawTexture(r, EditorGUIUtility.whiteTexture);
            }

            // draw major step
            {
                float position = drawInfo.GetPixelPosition(point);

                Rect r = new Rect(position, verticalPosition - tickmarkHeight, 1, tickmarkHeight);

                GUI.color = k_MajorTickColor;
                GUI.DrawTexture(r, EditorGUIUtility.whiteTexture);

                string label = string.Empty;
                int    frame = (int)(point * sampleRate);

                switch (labelFormat)
                {
                case TimelineViewMode.frames:
                    label = frame.ToString(CultureInfo.InvariantCulture);
                    break;

                case TimelineViewMode.secondsFrames:
                    label = TimelineUtility.TimeToTimeFrameStr(point, sampleRate);
                    break;

                default:
                    label = string.Format(scale < 0.1f ? "{0:0.000}" : "{0:0.00}", (float)point);
                    break;
                }

                var labelSize   = GUI.skin.GetStyle("label").CalcSize(new GUIContent(label));
                var labelOffset = labelSize.y - textLineHeight;

                float x = position - labelSize.x * 0.5f;
                float y;
                if (above)
                {
                    y = 0;
                }
                else
                {
                    y = verticalPosition - labelOffset * 0.5f; // Centered position below guide line
                }

                var w = labelSize.x + 2;
                var h = labelSize.y;

                GUI.color = k_MajorTickColor;
                GUI.Label(new Rect(x, y, w, h), label);
            }
        }
    }