![]() | ILinkSourceCancelLinking Method |
Namespace: KASAPIv2
// 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; }