Click or drag to resize

ILinkSourceStartLinking Method

Starts the linking mode of this source.

Namespace:  KASAPIv2
Assembly:  KAS-API-v2 (in KAS-API-v2.dll) Version: KAS API v2
Syntax
C#
bool StartLinking(
	GUILinkMode mode,
	LinkActorType actor
)
Request Example View Source

Parameters

mode
Type: KASAPIv2GUILinkMode
Defines how the pending link should be displayed. See GUILinkMode for more details.
actor
Type: KASAPIv2LinkActorType
Specifies how the action has been initiated.

Return Value

Type: Boolean
true if the mode has successfully started.
Remarks

Only one source at the time can be linking. If the part has more sources or targets, they are expected to become Locked.

A module can refuse the mode by returning false.

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