Click or drag to resize

MassType Class

Localized message formatting class for a numeric value that represents a mass. The resulted message may have a unit specification.
Inheritance Hierarchy
SystemObject
  KSPDev.GUIUtils.TypeFormattersMassType

Namespace:  KSPDev.GUIUtils.TypeFormatters
Assembly:  KSPDev_Utils.2.0 (in KSPDev_Utils.2.0.dll) Version: 2.0 for KSP v1.8+
Syntax
C#
public sealed class MassType
Request Example View Source

The MassType type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleMassType
Constructs an object from a numeric value.
Top
Methods
  NameDescription
Public methodStatic memberCode exampleFormat
Formats the value into a human friendly string with a unit specification.
Public methodToString
Returns a string formatted as a human friendly distance specification.
(Overrides ObjectToString.)
Top
Operators
Fields
  NameDescription
Public fieldStatic membergram
Localized suffix for the "gram" units. Scale 0.000001.
Public fieldStatic memberGramLocTag
Localization tag for the "gram" units.
Public fieldStatic memberkilogram
Localized suffix for the "kilogram" untis. Scale 0.001
Public fieldStatic memberKilogramLocTag
Localization tag for the "kilogram" units.
Public fieldStatic memberton
Localized suffix for the "ton" untis. Scale 1.0.
Public fieldStatic memberTonLocTag
Localization tag for the "ton" units.
Public fieldvalue
A wrapped numeric value.
Top
Remarks

Use it as a generic parameter when creating a LocalizableMessage descendants.

The class uses the unit name localizations from the stock module ModuleEnviroSensor. In case of this module is deprecated or the tags are changed, the default English values will be used for the unit names.

Examples
public class MassTypeDemo1 : PartModule {
  static readonly Message<MassType> msg1 = new Message<MassType>(
      "#TypeDemo_msg1", defaultTemplate: "Mass is: <<1>>");

  // Depending on the current language in the system, this method will present different unit names. 
  void Show() {
    Debug.Log(msg1.Format(1.0));
    // Prints: "Mass is: 1.0 t"
    Debug.Log(msg1.Format(1.567));
    // Prints: "Mass is: 1.57 t"
    Debug.Log(msg1.Format(10.0));
    // Prints: "Mass is: 10 t"
    Debug.Log(msg1.Format(10.56));
    // Prints: "Mass is: 10.6 t"
    Debug.Log(msg1.Format(100.0));
    // Prints: "Mass is: 100 t"
    Debug.Log(msg1.Format(100.5));
    // Prints: "Mass is: 101 t"

    Debug.Log(msg1.Format(0.1234567));
    // Prints: "Mass is: 124 kg"
    Debug.Log(msg1.Format(0.0123456));
    // Prints: "Mass is: 12.4 kg"
    Debug.Log(msg1.Format(0.0012345));
    // Prints: "Mass is: 1.24 kg"

    Debug.Log(msg1.Format(0.0001234567));
    // Prints: "Mass is: 124 g"
    Debug.Log(msg1.Format(0.0000123456));
    // Prints: "Mass is: 12.4 g"
    Debug.Log(msg1.Format(0.0000012356));
    // Prints: "Mass is: 1.24 g"
    Debug.Log(msg1.Format(0.0000001235));
    // Prints: "Mass is: 0.124 g"
  }
}
Examples
Debug.Log(MassType.Format(1.0));
// Prints: "1.0 t"
Debug.Log(MassType.Format(1.567));
// Prints: "1.57 t"
Debug.Log(MassType.Format(10.0));
// Prints: "10 t"
Debug.Log(MassType.Format(10.56));
// Prints: "10.6 t"
Debug.Log(MassType.Format(100.0));
// Prints: "100 t"
Debug.Log(MassType.Format(100.5));
// Prints: "101 t"

Debug.Log(MassType.Format(0.1234567));
// Prints: "124 kg"
Debug.Log(MassType.Format(0.0123456));
// Prints: "12.4 kg"
Debug.Log(MassType.Format(0.0012345));
// Prints: "1.24 kg"

Debug.Log(MassType.Format(0.0001234567));
// Prints: "124 g"
Debug.Log(MassType.Format(0.0000123456));
// Prints: "12.4 g"
Debug.Log(MassType.Format(0.0000012356));
// Prints: "1.24 g"
Debug.Log(MassType.Format(0.0000001235));
// Prints: "0.124 g"
Examples
Debug.Log(DistanceType.Format(0.12345678, scale: 1));
// Prints: "0.124 t"
Debug.Log(DistanceType.Format(0.12345678, scale: 0.001));
// Prints: "124 kg"
Debug.Log(DistanceType.Format(0.12345678, scale: 0.0001));
// Scale 0.0001, so it's roudned up to 0.001
// Prints: "124 kg"
Debug.Log(DistanceType.Format(0.12345678, scale: 0.000001));
// Prints: "123457 g"
Debug.Log(DistanceType.Format(0.12345678, scale: 0.0000001));
// Scale 0.0000001, so it's roudned up to 0.000001
// Prints: "123457 g"
Examples
Debug.Log(MassType.Format(0.12345678, format: "0.0000"));
// Prints: "0.1235 t"
Debug.Log(MassType.Format(0.12345678, format: "0.00"));
// Prints: "0.12 t"
Debug.Log(MassType.Format(0.12345678, format: "0.0000", scale: 0.001));
// Prints: "123.4568 kg"
Debug.Log(MassType.Format(0.12345678, format: "0.0000", scale: 0.000001));
// Prints: "123456.7800 g"
See Also

Reference

KSPDev.GUIUtils.TypeFormattersMassType