Click or drag to resize

PartModuleUtilsGetEvent Method

Returns an event for the requested method.

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 BaseEvent GetEvent(
	PartModule partModule,
	Action eventFn
)
Request Example View Source

Parameters

partModule
Type: (Default Namespace)PartModule
The module to get the event for.
eventFn
Type: SystemAction
The signature of the event in scope of the module.

Return Value

Type: BaseEvent
An event, or null if nothing found for the method provided.
Remarks
This method requests a KPS event of the part's module by its signature instead of a string literal name. The same result could be achieved by accessing the Events field of the PartModule object. However, in case of using a string literal the refactoring and the source tracking tools won't be able to track the reference. The main goal of this method is to provide a compile time checking mechanism for the cases when the exact method is known at the compile time (e.g. in the class descendants).
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