コード例 #1
0
        /// <summary>
        /// Draws text displaying the value at the provided position.
        /// </summary>
        /// <param name="yPos">Position to draw the text at.</param>
        /// <param name="value">Value to display.</param>
        /// <param name="above">If true the text will be displayed above the provided position, otherwise below.</param>
        private void DrawValue(int yPos, float value, bool above)
        {
            int exponent         = MathEx.FloorToInt(MathEx.Log10(MathEx.Abs(value)));
            int maxDecimalPoints = MathEx.Max(0, 1 - exponent);

            string valueString = value.ToString("F" + maxDecimalPoints);

            Vector2I textBounds = GUIUtility.CalculateTextBounds(valueString, EditorBuiltin.DefaultFont,
                                                                 EditorStyles.DefaultFontSize);

            Vector2I textPosition = new Vector2I();

            textPosition.x = width - textBounds.x;

            if (above)
            {
                textPosition.y = yPos - textBounds.y;
            }
            else // Below
            {
                const int PADDING = 3; // So the text doesn't touch the tick
                textPosition.y = yPos + PADDING;
            }
            canvas.DrawText(valueString, textPosition, EditorBuiltin.DefaultFont, COLOR_TRANSPARENT_LIGHT_GRAY,
                            EditorStyles.DefaultFontSize);
        }
コード例 #2
0
        /// <summary>
        /// Draws text displaying the time at the provided position.
        /// </summary>
        /// <param name="xPos">Position to draw the text at.</param>
        /// <param name="seconds">Time to display, in seconds.</param>
        /// <param name="minutes">If true the time will be displayed in minutes, otherwise in seconds.</param>
        private void DrawTime(int xPos, float seconds, bool minutes)
        {
            TimeSpan timeSpan = TimeSpan.FromSeconds(seconds);

            string timeString;

            if (minutes)
            {
                timeString = timeSpan.TotalMinutes.ToString("#0") + ":" + timeSpan.Seconds.ToString("D2");
            }
            else
            {
                timeString = timeSpan.TotalSeconds.ToString("#0.00");
            }

            Vector2I textBounds = GUIUtility.CalculateTextBounds(timeString, EditorBuiltin.DefaultFont,
                                                                 EditorStyles.DefaultFontSize);

            Vector2I textPosition = new Vector2I();

            textPosition.x = xPos - textBounds.x / 2;
            textPosition.y = TEXT_PADDING;

            canvas.DrawText(timeString, textPosition, EditorBuiltin.DefaultFont, Color.LightGray,
                            EditorStyles.DefaultFontSize);
        }