Click or drag to resize

PartModuleUtils Class

Utility class to deals with the attributed fields and methods of the KPS part modules.
Inheritance Hierarchy
SystemObject
  KSPDev.PartUtilsPartModuleUtils

Namespace:  KSPDev.PartUtils
Assembly:  KSPDev_Utils.1.1 (in KSPDev_Utils.1.1.dll) Version: 1.1 for KSP v1.6+
Syntax
C#
public static class PartModuleUtils
Request Example View Source

The PartModuleUtils type exposes the following members.

Methods
  NameDescription
Public methodStatic memberAddEvent
Add an event into a part module.
Public methodStatic memberDropEvent
Removes the specified event from the part module.
Public methodStatic memberGetAction
Returns an action for the requested method.
Public methodStatic memberCode exampleGetEvent
Returns an event for the requested method.
Public methodStatic memberInjectEvent
Injects an event from one part to another.
Public methodStatic memberInvalidateContextMenu
Forces the context menu of the part to refresh itself.
Public methodStatic memberSetupAction
Applies a setup function on a KSP part module action.
Public methodStatic memberCode exampleSetupEvent
Applies a setup function on a KSP part module event.
Public methodStatic memberWithdrawEvent
Removes an event that was previously injected.
Top
Examples
class PartModuleUtils_SetupEvent : PartModule {
  [KSPEvent(guiName = "test", guiActive = true, active = false)]
  void TestEvent() {
    Debug.Log("Test event triggered");
  }

  void SetupEvents() {
    // This call will activate the event.
    PartModuleUtils.SetupEvent(this, TestEvent, x => x.active = true);
  }
}
Examples
class PartModuleUtils_GetEvent : PartModule {
  [KSPEvent(guiName = "test", guiActive = true, active = false)]
  void TestEvent() {
    Debug.Log("Test event triggered");
  }

  void SetupEvents() {
    var e = PartModuleUtils.GetEvent(this, TestEvent);
    e.active = true;  // Activates the event.
  }
}
See Also