Click or drag to resize

ForceType Class

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

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 ForceType
Request Example View Source

The ForceType type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleForceType
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 force specification.
(Overrides ObjectToString.)
Top
Operators
Fields
  NameDescription
Public fieldStatic memberkiloNewton
Localized suffix for the "kilonewton" units. Scale x1.
Public fieldStatic memberKilonewtonLocTag
Localization tag for the "kilonewton" 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 ForceTypeDemo1 : PartModule {
  static readonly Message<ForceType> msg1 = new Message<ForceType>(
      "#TypeDemo_msg1", defaultTemplate: "Force is: <<1>>");

  // Depending on the current language in the system, this method will present different unit names. 
  void Show() {
    Debug.Log(msg1.Format(0.051));
    // Prints: "Force is: 0.051 kN"
    Debug.Log(msg1.Format(0.45));
    // Prints: "Force is: 0.45 kN"
    Debug.Log(msg1.Format(95.45));
    // Prints: "Force is: 95.5 kN"
    Debug.Log(msg1.Format(120.45));
    // Prints: "Force is: 120 kN"
    Debug.Log(msg1.Format(9535.45));
    // Prints: "Force is: 9536 kN"
  }
}
Examples
Debug.Log(ForceType.Format(0.051));
// Prints: "0.051 kN"
Debug.Log(ForceType.Format(0.45));
// Prints: "0.45 kN"
Debug.Log(ForceType.Format(95.45));
// Prints: "95.5 kN"
Debug.Log(ForceType.Format(120.45));
// Prints: "120 kN"
Debug.Log(ForceType.Format(9535.45));
// Prints: "9536 kN"
Examples
Debug.Log(ForceType.Format(1234.5678, format: "0.0000"));
// Prints: "1234.5678 kN"
Debug.Log(ForceType.Format(1234.5678, format: "0.00"));
// Prints: "1234.57 kN"
See Also

Reference

KSPDev.GUIUtils.TypeFormattersForceType