Click or drag to resize

ILinkTargetlinkSource Property

Source that maintains the link.

Namespace:  KASAPIv2
Assembly:  KAS-API-v2 (in KAS-API-v2.dll) Version: KAS API v2
Syntax
C#
ILinkSource linkSource { get; set; }
Request Example View Source

Property Value

Type: ILinkSource
Source or null if nothing is linked.
Remarks

Setting of this property changes the target state:

  • A non-null value changes the state to Linked.
  • null value changes the state to Available.

Assigning the same value to this property doesn't trigger a state change event.

Note, that not any state transition is possible. If the transition is invalid then an exception is thrown.

It's discouraged to assign this property from a code other than an implementation of ILinkSource.

Examples
// Returns the linked part of the target, if any. It assumes there is exactly one target module
// on the part.
public static Part FindSourceFromTarget(Part tgtPart) {
  var source = tgtPart.FindModulesImplementing<ILinkTarget>()
      .FirstOrDefault(s => s.linkSource != null);
  if (source == null) {
    Debug.Log("Target is not connected");
    return null;
  }
  return source.linkSource.part;
}
See Also