237 lines
6.8 KiB
C#
237 lines
6.8 KiB
C#
using UnityEngine;
|
|
|
|
public class UtilitiesUnits : MonoBehaviour
|
|
{
|
|
public static int FahrenheitToCelsius(int fahrenheit)
|
|
{
|
|
return Mathf.RoundToInt(((float)fahrenheit - 32f) / 1.8f);
|
|
}
|
|
|
|
public static int CelsiusToFahrenheit(int celsius)
|
|
{
|
|
return Mathf.RoundToInt((float)celsius * 1.8f + 32f);
|
|
}
|
|
|
|
public static string GetWeightString(float weightKg, string format = "F2")
|
|
{
|
|
string empty = string.Empty;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return string.Empty + (weightKg * 2.205f).ToString(format) + " " + Utilities.GetTranslation("UNITS/POUNDS");
|
|
}
|
|
return string.Empty + weightKg.ToString(format) + " " + Utilities.GetTranslation("UNITS/KILOGRAMS");
|
|
}
|
|
|
|
public static string GetWeightGramString(float weightG, string format = "F2")
|
|
{
|
|
string empty = string.Empty;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return string.Empty + (weightG * 0.035f).ToString(format) + " " + Utilities.GetTranslation("UNITS/OUNCES");
|
|
}
|
|
return string.Empty + weightG.ToString(format) + " " + Utilities.GetTranslation("UNITS/GRAMS");
|
|
}
|
|
|
|
public static string GetLengthSimpleString(float lengthM, string format = "F2")
|
|
{
|
|
string empty = string.Empty;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return string.Empty + (lengthM * 3.281f).ToString(format);
|
|
}
|
|
return string.Empty + lengthM.ToString(format);
|
|
}
|
|
|
|
public static string GetLengthString(float lengthM, string format = "F2", bool withSpace = true)
|
|
{
|
|
string empty = string.Empty;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return string.Empty + (lengthM * 3.281f).ToString(format) + ((!withSpace) ? string.Empty : " ") + Utilities.GetTranslation("UNITS/FEET");
|
|
}
|
|
return string.Empty + lengthM.ToString(format) + ((!withSpace) ? string.Empty : " ") + Utilities.GetTranslation("UNITS/METERS");
|
|
}
|
|
|
|
public static string GetLengthMMString(float lengthMM, int digits = 2, bool withSpace = true)
|
|
{
|
|
string empty = string.Empty;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return string.Empty + (lengthMM * 0.0394f).ToString((digits != 2) ? "F2" : "F3") + ((!withSpace) ? string.Empty : " ") + Utilities.GetTranslation("UNITS/INCHES");
|
|
}
|
|
return string.Empty + lengthMM.ToString((digits != 2) ? "F1" : "F2") + ((!withSpace) ? string.Empty : " ") + Utilities.GetTranslation("UNITS/MILIMETERS");
|
|
}
|
|
|
|
public static string GetLengthCmString(float lengthCM, string format = "F1", bool withSpace = true)
|
|
{
|
|
string empty = string.Empty;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return string.Empty + (lengthCM * 0.394f).ToString(format) + ((!withSpace) ? string.Empty : " ") + Utilities.GetTranslation("UNITS/INCHES");
|
|
}
|
|
return string.Empty + lengthCM.ToString(format) + ((!withSpace) ? string.Empty : " ") + Utilities.GetTranslation("UNITS/CENTIMETERS");
|
|
}
|
|
|
|
public static string GetTemperatureString(int tempC)
|
|
{
|
|
string empty = string.Empty;
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return string.Empty + CelsiusToFahrenheit(tempC) + " " + Utilities.GetTranslation("UNITS/FAHRENHEIT");
|
|
}
|
|
return string.Empty + tempC + " " + Utilities.GetTranslation("UNITS/CELSIUS");
|
|
}
|
|
|
|
public static int GetUnitsCelsius(int tempCel)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return CelsiusToFahrenheit(tempCel);
|
|
}
|
|
return tempCel;
|
|
}
|
|
|
|
public static float GetUnitsKg(float weightKg)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return weightKg * 2.205f;
|
|
}
|
|
return weightKg;
|
|
}
|
|
|
|
public static float GetUnitsGram(float weightGram)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return weightGram * 0.035f;
|
|
}
|
|
return weightGram;
|
|
}
|
|
|
|
public static float GetUnitsMeter(float lengthMeter)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return lengthMeter * 3.281f;
|
|
}
|
|
return lengthMeter;
|
|
}
|
|
|
|
public static float GetUnitsWind(float lengthMeter)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return lengthMeter * 2.237f;
|
|
}
|
|
return lengthMeter;
|
|
}
|
|
|
|
public static float GetUnitsCm(float lengthCm)
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return lengthCm * 0.394f;
|
|
}
|
|
return lengthCm;
|
|
}
|
|
|
|
public static string GetUnitNameCelsius()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return Utilities.GetTranslation("UNITS/FAHRENHEIT");
|
|
}
|
|
return Utilities.GetTranslation("UNITS/CELSIUS");
|
|
}
|
|
|
|
public static string GetUnitNameKg()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return Utilities.GetTranslation("UNITS/POUNDS");
|
|
}
|
|
return Utilities.GetTranslation("UNITS/KILOGRAMS");
|
|
}
|
|
|
|
public static string GetUnitNameGram()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return Utilities.GetTranslation("UNITS/OUNCES");
|
|
}
|
|
return Utilities.GetTranslation("UNITS/GRAMS");
|
|
}
|
|
|
|
public static string GetUnitNameMeter()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return Utilities.GetTranslation("UNITS/FEET");
|
|
}
|
|
return Utilities.GetTranslation("UNITS/METERS");
|
|
}
|
|
|
|
public static string GetUnitNameWind()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return Utilities.GetTranslation("UNITS/MILES_PER_HOUR");
|
|
}
|
|
return Utilities.GetTranslation("UNITS/METERS_PER_SECOND");
|
|
}
|
|
|
|
public static string GetUnitNameCm()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return Utilities.GetTranslation("UNITS/INCHES");
|
|
}
|
|
return Utilities.GetTranslation("UNITS/CENTIMETERS");
|
|
}
|
|
|
|
public static string GetUnitNameMm()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
return Utilities.GetTranslation("UNITS/INCHES");
|
|
}
|
|
return Utilities.GetTranslation("UNITS/MILIMETERS");
|
|
}
|
|
|
|
public static string GetHookSizeString(int hookSize)
|
|
{
|
|
string text = "#";
|
|
if (hookSize <= 5)
|
|
{
|
|
switch (hookSize)
|
|
{
|
|
case 0:
|
|
text += 12;
|
|
break;
|
|
case 1:
|
|
text += 8;
|
|
break;
|
|
case 2:
|
|
text += 6;
|
|
break;
|
|
case 3:
|
|
text += 4;
|
|
break;
|
|
case 4:
|
|
text += 2;
|
|
break;
|
|
case 5:
|
|
text += 1;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
text += hookSize - 5;
|
|
text += "/0";
|
|
}
|
|
return text;
|
|
}
|
|
}
|