Click or drag to resize

IKasEventsOnLinkCreated Property

Triggers when a link between two parts has been successfully established.

Namespace:  KASAPIv2
Assembly:  KAS-API-v2 (in KAS-API-v2.dll) Version: KAS API v2
Syntax
C#
EventData<IKasLinkEvent> OnLinkCreated { get; }
Request Example View Source

Property Value

Type: EventDataIKasLinkEvent
Collection to add or remove a callback.
Remarks

The argument of the callback is a KAS event object that describes the link.

Consider using OnKASLinkedState(IKasLinkEvent, Boolean) when this state change is needed in scope of just one part.

Examples
public class KasEventsExample1: PartModule {
  public override void OnAwake() {
    base.OnAwake();
    KASAPI.KasEvents.OnStartLinking.Add(LinkStarted);
    KASAPI.KasEvents.OnStopLinking.Add(LinkStopped);
    KASAPI.KasEvents.OnLinkCreated.Add(LinkCreated);
    KASAPI.KasEvents.OnLinkBroken.Add(LinkBroken);
  }

  void OnDestroy() {
    KASAPI.KasEvents.OnStartLinking.Remove(LinkStarted);
    KASAPI.KasEvents.OnStopLinking.Remove(LinkStopped);
    KASAPI.KasEvents.OnLinkCreated.Remove(LinkCreated);
    KASAPI.KasEvents.OnLinkBroken.Remove(LinkBroken);
  }

  void LinkStarted(ILinkSource source) {
    DebugEx.Info("Link started by: {0}", source);
  }

  void LinkStopped(ILinkSource source) {
    DebugEx.Info("Link stopepd by: {0}", source);
  }

  void LinkCreated(IKasLinkEvent ev) {
    DebugEx.Info("Link created: {0} <=> {1}", ev.source, ev.target);
  }

  void LinkBroken(IKasLinkEvent ev) {
    DebugEx.Info("Link broken: {0} <=> {1}", ev.source, ev.target);
  }
}
See Also