CompactUnitConversionCache Class

Summary

[Editor-Only] A system for formatting floats as strings that fit into a limited area and storing the results so they can be reused to minimise the need for garbage collection, particularly for string construction.
Assembly
Animancer.dll
Namespace
Animancer.Units.Editor
Base Types
  • Object
graph BT Type-->Base0["Object"] Type["CompactUnitConversionCache"] class Type type-node

Syntax

public class CompactUnitConversionCache

Remarks

This system only affects the display value. Once you select a field, it shows its actual value.

Example: With "x" as the suffix:
  • 1.111111 could instead show 1.111~x.
  • 0.00001234567 would normally show 1.234567e-05, but with this it instead shows 0~x because very small values generally aren't useful.
  • 99999999 shows 1e+08x because very large values are already approximations and trying to format them correctly would be very difficult.

Constructors

Name Summary
CompactUnitConversionCache(string) Creates a new Animancer.Units.Editor.CompactUnitConversionCache.

Fields

Name Constant Value Summary
_ApproximateSymbolWidth
The pixel width of the ~ character when drawn by UnityEditor.EditorStyles.numberField.
static
_DecimalSeparator
The character(s) used to separate decimal values in the current OS language.
static
_FieldPadding
Padding around the text in a UnityEditor.EditorStyles.numberField.
static
_SuffixWidth
The pixel width of the Animancer.Units.Editor.CompactUnitConversionCache.Suffix when drawn by UnityEditor.EditorStyles.numberField.
ApproximateSuffix
The Animancer.Units.Editor.CompactUnitConversionCache.Suffix with a ~ before it to indicate an approximation.
ConvertedSmallNegative
The value -0 with the Animancer.Units.Editor.CompactUnitConversionCache.ApproximateSuffix.
ConvertedSmallPositive
The value 0 with the Animancer.Units.Editor.CompactUnitConversionCache.ApproximateSuffix.
ConvertedZero
The value 0 with the Animancer.Units.Editor.CompactUnitConversionCache.Suffix.
LargeExponentialThreshold 9999999
Values larger than this can't be approximated.
static
SmallExponentialThreshold 0.0001
Values smaller than this become 0~ or -0~.
static
Suffix
The suffix added to the end of each value.

Properties

Name Value Summary
ShowApproximations bool
Should the fields show approximations if the value is too long for the GUI?
static

Methods

Name Value Summary
Convert(float, float) string
Returns a cached string representing the `value` trimmed to fit within the `width` (if necessary) and with the Animancer.Units.Editor.CompactUnitConversionCache.Suffix added on the end.
GetExponentialFormat(int) string
Returns a format string to include the specified number of `digits` in an exponential number.
static