add configuration options

This commit is contained in:
nothingTVatYT
2024-01-28 23:52:52 +01:00
parent 2625144945
commit 20dbe15651
2 changed files with 20 additions and 0 deletions

View File

@@ -6,4 +6,16 @@ public class Units
/// Factor of units per meter.
/// </summary>
public static readonly float Meters2Units = 100f;
// the next two bools could be cached values in the user preferences
/// <summary>
/// Set it to false to always show game units without any postfix
/// </summary>
public static bool UseUnitsFormatting = true;
/// <summary>
/// If set to true, the distance unit is chosen on the magnitude, otherwise it's meters
/// </summary>
public static bool AutomaticUnitsFormatting = true;
}

View File

@@ -1179,9 +1179,13 @@ namespace FlaxEditor.Utilities
/// <returns>the formatted string</returns>
public static string FormatFloat(float value, FlaxEngine.Utils.ValueCategory category)
{
if (!Units.UseUnitsFormatting)
return FormatFloat(value);
switch (category)
{
case FlaxEngine.Utils.ValueCategory.Distance:
if (!Units.AutomaticUnitsFormatting)
return (value / Units.Meters2Units).ToString("g7", CultureInfo.InvariantCulture) + "m";
var absValue = Mathf.Abs(value);
// in case a unit != cm this would be (value / Maters2Units * 100)
if (absValue < Units.Meters2Units)
@@ -1204,9 +1208,13 @@ namespace FlaxEditor.Utilities
/// <returns>the formatted string</returns>
public static string FormatFloat(double value, FlaxEngine.Utils.ValueCategory category)
{
if (!Units.UseUnitsFormatting)
return FormatFloat(value);
switch (category)
{
case FlaxEngine.Utils.ValueCategory.Distance:
if (!Units.AutomaticUnitsFormatting)
return (value / Units.Meters2Units).ToString("g17", CultureInfo.InvariantCulture) + "m";
var absValue = Mathf.Abs(value);
// in case a unit != cm this would be (value / Maters2Units * 100)
if (absValue < Units.Meters2Units)