/// <summary>Handles keyboard input.</summary> private void UpdateKey() { if (isRunning) { if (KIS_Shared.IsKeyUp(KeyCode.Escape) || KIS_Shared.IsKeyDown(KeyCode.Return)) { DebugEx.Fine("Cancel key pressed, stop eva attach mode"); CancelPointer(this); } if (GameSettings.Editor_toggleSymMethod.GetKeyDown()) // "R" by default. { if (pointerTarget != PointerTarget.PartMount && attachNodes.Count() > 1) { if (attachNodeIndex < attachNodes.Count - 1) { attachNodeIndex++; } else { attachNodeIndex = 0; } DebugEx.Fine("Attach node index changed to: {0}", attachNodeIndex); ResetMouseOver(); SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null); } else { ScreenMessaging.ShowInfoScreenMessage(OnlyOneAttachNodeMsg); UISounds.PlayBipWrong(); } } } }
/// <summary>Handles keyboard input.</summary> private void UpdateKey() { if (isRunning) { if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Return)) { Logger.logInfo("Cancel key pressed, stop eva attach mode"); StopPointer(); SendPointerClick(PointerTarget.Nothing, Vector3.zero, Quaternion.identity, null, null); } if (GameSettings.Editor_toggleSymMethod.GetKeyDown()) // "R" by default. { if (pointerTarget != PointerTarget.PartMount && attachNodes.Count() > 1) { attachNodeIndex++; if (attachNodeIndex > (attachNodes.Count - 1)) { attachNodeIndex = 0; } Logger.logInfo("Attach node index changed to: {0}", attachNodeIndex); UpdatePointerAttachNode(); ResetMouseOver(); SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null); } else { ScreenMessaging.ShowInfoScreenMessage("This part has only one attach node!"); audioBipWrong.Play(); } } } }
/// <summary>Handles keyboard input.</summary> private void UpdateKey() { if (isRunning) { if (KIS_Shared.IsKeyUp(KeyCode.Escape) || KIS_Shared.IsKeyDown(KeyCode.Return)) { Debug.Log("Cancel key pressed, stop eva attach mode"); StopPointer(unlockUI: false); SendPointerClick(PointerTarget.Nothing, Vector3.zero, Quaternion.identity, null, null); // Delay unlocking to not let ESC be handled by the game. AsyncCall.CallOnEndOfFrame(this, UnlockUI); } if (GameSettings.Editor_toggleSymMethod.GetKeyDown()) // "R" by default. { if (pointerTarget != PointerTarget.PartMount && attachNodes.Count() > 1) { attachNodeIndex++; if (attachNodeIndex > (attachNodes.Count - 1)) { attachNodeIndex = 0; } Debug.LogFormat("Attach node index changed to: {0}", attachNodeIndex); UpdatePointerAttachNode(); ResetMouseOver(); SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null); } else { ScreenMessaging.ShowInfoScreenMessage("This part has only one attach node!"); audioBipWrong.Play(); } } } }
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 (KIS_Shared.IsKeyDown(offsetUpKey) && aboveDistance < maxOffsetDist) { aboveDistance += aboveOffsetStep; } if (KIS_Shared.IsKeyDown(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 && partToAttach != null && partToAttach.hasIndirectChild(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 = currentAttachNode.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 = partToAttach != null && !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 (var mr in allModelRenderers) { mr.material.color = color; } //On click. if (Input.GetMouseButtonDown(0)) { if (invalidTarget) { ScreenMessaging.ShowInfoScreenMessage(TargetObjectNotAllowedMsg); UISounds.PlayBipWrong(); } else if (itselfIsInvalid) { ScreenMessaging.ShowInfoScreenMessage(CannotAttachOnItselfMsg); UISounds.PlayBipWrong(); } else if (notAllowedOnMount) { ScreenMessaging.ShowInfoScreenMessage(NotAllowedOnTheMountMsg); UISounds.PlayBipWrong(); } else if (cannotSurfaceAttach) { ScreenMessaging.ShowInfoScreenMessage(TargetDoesntAllowSurfaceAttachMsg); UISounds.PlayBipWrong(); } else if (invalidCurrentNode) { ScreenMessaging.ShowInfoScreenMessage(NodeNotForSurfaceAttachMsg); UISounds.PlayBipWrong(); } else if (sourceDist > maxDist) { ScreenMessaging.ShowInfoScreenMessage(TooFarFromSourceMsg.Format(sourceDist, maxDist)); UISounds.PlayBipWrong(); } else if (targetDist > maxDist) { ScreenMessaging.ShowInfoScreenMessage(TooFarFromTargetMsg.Format(targetDist, maxDist)); UISounds.PlayBipWrong(); } else if (restrictedPart) { ScreenMessaging.ShowInfoScreenMessage( CannotAttachToPartMsg.Format(hoveredPart.partInfo.title)); UISounds.PlayBipWrong(); } else { SendPointerClick(pointerTarget, pointer.transform.position, pointer.transform.rotation, hoveredPart, currentAttachNode.id, hoveredNode); } } }