/// <summary>
        /// Renders the time span data as a float field with a drop-down to select the time unit (milliseconds, seconds, minutes, hours)
        /// </summary>
        /// <param name="position">The rectangle depicting the available render area</param>
        /// <param name="property">The property containing the float value to be displayed as a time span</param>
        /// <param name="displayTimeSpanAttribute">The attribute that identifies the float as a time span value</param>
        /// <returns>A rectangle depicting the remaining available area</returns>
        protected virtual Rect DisplayTimeSpanWithSingleUnit(Rect position, SerializedProperty property, DisplayTimeSpanAttribute displayTimeSpanAttribute)
        {
            TimeSpan propertyTimeSpanValue = displayTimeSpanAttribute.UnderlyingValueType.GetTimeSpanValue(property.floatValue);

            float columnSpacing = 1f;

            float columnWidth = (position.width * 0.5f) - columnSpacing;

            Rect valueRect = new Rect(position);

            valueRect.width  = columnWidth;
            valueRect.height = EditorGUIUtility.singleLineHeight;

            Rect unitRect = new Rect(valueRect);

            unitRect.x = valueRect.xMax + columnSpacing;

            TimeIntervalType timeSpanUnit = displayTimeSpanAttribute.UnderlyingValueType;

            EditorGUI.LabelField(unitRect, timeSpanUnit.ToString());

            float currentValue = timeSpanUnit.GetFloatValue(propertyTimeSpanValue);

            currentValue = Mathf.Abs(EditorGUI.FloatField(valueRect, currentValue));

            TimeSpan currentTimespanValue = timeSpanUnit.GetTimeSpanValue(currentValue);

            property.floatValue = displayTimeSpanAttribute.UnderlyingValueType.GetFloatValue(currentTimespanValue);

            Rect returnRect = new Rect(position);

            returnRect.y      += EditorGUIUtility.singleLineHeight;
            returnRect.height -= EditorGUIUtility.singleLineHeight;

            return(returnRect);
        }
示例#2
0
 /// <summary>
 /// Converts the provided float value to its TimeSpan representation based on the
 /// currently selected IntervalType
 /// </summary>
 /// <param name="ThisIntervalType">The interval type that defines the conversion</param>
 /// <param name="FloatValue">The value to be converted</param>
 /// <returns>The TimeSpan representing the float value</returns>
 public static TimeSpan GetTimeSpanValue(this TimeIntervalType ThisIntervalType, float FloatValue)
 {
     return(ThisIntervalType.GetTimeSpanValue((Double)FloatValue));
 }