Click or drag to resize

ILinkSourceCancelLinking Method

Cancels the linking mode without creating a link.

Namespace:  KASAPIv2
Assembly:  KAS-API-v2 (in KAS-API-v2.dll) Version: KAS API v2
Syntax
C#
void CancelLinking()
Request Example View Source
Remarks
All the sources and targets, that got locked on the mode start, will be unlocked.
Examples
// Connects two parts assuming the source and the target parts own exactly one link module. 
public static bool ConnectParts(Part srcPart, Part tgtPart) {
  var source = srcPart.FindModuleImplementing<ILinkSource>();
  var target = tgtPart.FindModuleImplementing<ILinkTarget>();
  if (source == null || target == null || source.cfgLinkType != target.cfgLinkType) {
    Debug.LogError("Source and target cannot link");
    return false;
  }
  // GUILinkMode.API mode tells the implementation to not execute any user facing effects on the
  // link. See GUILinkMode for more details. 
  if (!source.StartLinking(GUILinkMode.API, LinkActorType.API) || !source.LinkToTarget(target)) {
    // Here we can only fail due to the constraints. E.g. the link mode is not supported, or the
    // joint module doesn't give the green light.
    Debug.LogError("Linking failed");
    source.CancelLinking();
    return false;
  }
  Debug.LogFormat("Established link with part: id={0}", source.linkPartId);
  return true;
}
See Also