public void UpdatePointer() { // Stop pointer on map if (running && MapView.MapIsEnabled) { StopPointer(); return; } // Remove pointer if not running. if (!running) { DestroyPointer(); return; } // Hide pointer if the raycast do not hit anything. if (pointerTarget == PointerTarget.Nothing) { SetPointerVisible(false); return; } SetPointerVisible(true); // Custom rotation float rotDegree = 15; if (Input.GetKey(KeyCode.LeftShift)) { rotDegree = 1; } if (GameSettings.Editor_rollLeft.GetKeyDown()) { customRot -= new Vector3(0, -1, 0) * rotDegree; } if (GameSettings.Editor_rollRight.GetKeyDown()) { customRot += new Vector3(0, -1, 0) * rotDegree; } if (GameSettings.Editor_pitchDown.GetKeyDown()) { customRot -= new Vector3(1, 0, 0) * rotDegree; } if (GameSettings.Editor_pitchUp.GetKeyDown()) { customRot += new Vector3(1, 0, 0) * rotDegree; } if (GameSettings.Editor_yawLeft.GetKeyDown()) { customRot -= new Vector3(0, 0, 1) * rotDegree; } if (GameSettings.Editor_yawRight.GetKeyDown()) { customRot += new Vector3(0, 0, 1) * rotDegree; } if (GameSettings.Editor_resetRotation.GetKeyDown()) { customRot = new Vector3(0, 0, 0); } Quaternion rotAdjust = Quaternion.Euler(0, 0, customRot.z) * Quaternion.Euler(customRot.x, customRot.y, 0); // Move to position if (pointerTarget == PointerTarget.PartMount) { //Mount snap KIS_Shared.MoveAlign(pointer.transform, pointerNodeTransform, hoveredNode.nodeTransform); } else if (pointerTarget == PointerTarget.PartNode) { //Part node snap KIS_Shared.MoveAlign(pointer.transform, pointerNodeTransform, hoveredNode.nodeTransform, rotAdjust); } else { KIS_Shared.MoveAlign(pointer.transform, pointerNodeTransform, hit, rotAdjust); } // Move above if (allowOffset) { if (pointerTarget != PointerTarget.PartMount) { if (Input.GetKeyDown(offsetUpKey) && aboveDistance < maxOffsetDist) { aboveDistance += aboveOffsetStep; } if (Input.GetKeyDown(offsetDownKey) && aboveDistance > -maxOffsetDist) { aboveDistance -= aboveOffsetStep; } if (GameSettings.Editor_resetRotation.GetKeyDown()) { aboveDistance = 0; } pointer.transform.position = pointer.transform.position + (hit.normal.normalized * aboveDistance); } } //Check distance float sourceDist = 0; if (sourceTransform) { sourceDist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, sourceTransform.position); } float targetDist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, hit.point); //Set color Color color = colorOk; bool invalidTarget = false; bool notAllowedOnMount = false; bool cannotSurfaceAttach = false; bool invalidCurrentNode = false; bool itselfIsInvalid = !allowPartItself && KIS_Shared.IsSameHierarchyChild(partToAttach, hoveredPart); bool restrictedPart = allowedAttachmentParts != null && !allowedAttachmentParts.Contains(hoveredPart); switch (pointerTarget) { case PointerTarget.Static: case PointerTarget.StaticRb: invalidTarget = !allowStatic; break; case PointerTarget.KerbalEva: invalidTarget = !allowEva; break; case PointerTarget.Part: if (allowPart) { if (useAttachRules) { if (hoveredPart.attachRules.allowSrfAttach) { invalidCurrentNode = GetCurrentAttachNode().nodeType != AttachNode.NodeType.Surface; } else { cannotSurfaceAttach = true; } } } else { invalidTarget = true; } break; case PointerTarget.PartMount: if (allowMount) { ModuleKISPartMount pMount = hoveredPart.GetComponent <ModuleKISPartMount>(); var allowedPartNames = new List <string>(); pMount.GetMounts().TryGetValue(hoveredNode, out allowedPartNames); notAllowedOnMount = !allowedPartNames.Contains(partToAttach.partInfo.name); color = colorMountOk; } break; case PointerTarget.PartNode: invalidTarget = !allowStack; color = colorStack; break; } // Handle generic "not OK" color. if (sourceDist > maxDist || targetDist > maxDist) { color = colorDistNok; } else if (invalidTarget || cannotSurfaceAttach || invalidCurrentNode || itselfIsInvalid || restrictedPart) { color = colorNok; } color.a = 0.5f; foreach (MeshRenderer mr in allModelMr) { mr.material.color = color; } //On click. if (Input.GetMouseButtonDown(0)) { if (invalidTarget) { KIS_Shared.ShowRightScreenMessage("Target object is not allowed !"); audioBipWrong.Play(); } else if (itselfIsInvalid) { KIS_Shared.ShowRightScreenMessage("Cannot attach on itself !"); audioBipWrong.Play(); } else if (notAllowedOnMount) { KIS_Shared.ShowRightScreenMessage("This part is not allowed on the mount !"); audioBipWrong.Play(); } else if (cannotSurfaceAttach) { KIS_Shared.ShowRightScreenMessage("Target part do not allow surface attach !"); audioBipWrong.Play(); } else if (invalidCurrentNode) { KIS_Shared.ShowRightScreenMessage( "This node cannot be used for surface attach !"); audioBipWrong.Play(); } else if (sourceDist > maxDist) { KIS_Shared.ShowRightScreenMessage("Too far from source: {0:F3}m > {1:F3}m", sourceDist, maxDist); audioBipWrong.Play(); } else if (targetDist > maxDist) { KIS_Shared.ShowRightScreenMessage("Too far from target: {0:F3}m > {1:F3}m", targetDist, maxDist); audioBipWrong.Play(); } else if (restrictedPart) { KIS_Shared.ShowRightScreenMessage("Cannot attach to part: {0}", hoveredPart); audioBipWrong.Play(); } else { SendPointerClick(pointerTarget, pointer.transform.position, pointer.transform.rotation, hoveredPart, GetCurrentAttachNode().id, hoveredNode); } } }