![]() | ILinkSourceCheckCanLinkTo Method |
Namespace: KASAPIv2
bool CheckCanLinkTo( ILinkTarget target, bool checkStates = true, bool reportToGUI = false, bool reportToLog = true )
// Connects two parts assuming the source and the target parts own exactly one link module. // Does not attempt the link if it's obstructed to avoid a GUI error message. public static bool ConnectPartsWithCheck(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; } if (!source.CheckCanLinkTo(target, reportToLog: false)) { Debug.Log("Link is obstructed. Silently cancel the action"); return false; } if (!source.StartLinking(GUILinkMode.API, LinkActorType.API) || !source.LinkToTarget(target)) { Debug.LogError("Linking failed"); source.CancelLinking(); return false; } return true; }