/// <summary>Disables/enables all the colliders between the parts.</summary> /// <remarks>The ignore state is reset to <c>false</c> on every scene load.</remarks> /// <param name="part1">Source part.</param> /// <param name="part2">Target part.</param> /// <param name="ignore"> /// If <c>true</c> then the collisions between the parts will be ignored. Otherwise, the /// collisions will be handled. /// </param> /// <seealso href="https://docs.unity3d.com/ScriptReference/Collider.html"> /// Unity3D: Collider</seealso> /// <seealso href="https://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html"> /// Unity3D: Physics.IgnoreCollision</seealso> public static void SetCollisionIgnores(Part part1, Part part2, bool ignore) { Debug.LogFormat("Set collision ignores between {0} and {1} to {2}", DbgFormatter.PartId(part1), DbgFormatter.PartId(part2), ignore); SetCollisionIgnores( Hierarchy.GetPartModelTransform(part1), Hierarchy.GetPartModelTransform(part2), ignore); }
/// <summary>Updates data in all the open part menus.</summary> public static void LocalizePartMenus() { // The editor's tooltip caches the data, and we cannot update it. So just reset it. if (HighLogic.LoadedSceneIsEditor) { UIMasterController.Instance.DestroyCurrentTooltip(); } UnityEngine.Object.FindObjectsOfType(typeof(UIPartActionWindow)) .OfType <UIPartActionWindow>() .ToList() .ForEach(m => { Debug.LogFormat("Localize menu for part {0}", DbgFormatter.PartId(m.part)); m.titleText.text = m.part.partInfo.title; }); }
/// <summary>Creates a debug dialog for the parts.</summary> /// <remarks> /// Implement a code that would react on user interactions and invoke this method to show a debug /// dialog. The dialog can be bound to a specific part, in which case it only showns for that /// part, or the dialog may allow interactively selecting a part from the scene. /// </remarks> /// <param name="title">The titile of the dialog.</param> /// <param name="dialogWidth"> /// The width of the dialog. If omitted, then the code will decide. /// </param> /// <param name="valueColumnWidth"> /// The width of the value changing controls. If omitted, then the code will decide. /// </param> /// <param name="group"> /// The group of the controls to present. If empty, then all the controls are shown. /// </param> /// <param name="bindToPart"> /// The part to attach the dialog to. If set, then the dialog won't allow changing the part via /// GUI. Otherwise, there will be controls in the dialog that allow selection a part from the /// scene. /// </param> /// <returns>The created dialog.</returns> /// <seealso cref="DestroyPartDebugDialog"/> /// <seealso cref="DebugAdjustableAttribute"/> public static PartDebugAdjustmentDialog MakePartDebugDialog( string title, float?dialogWidth = null, float?valueColumnWidth = null, string group = "", Part bindToPart = null) { if (bindToPart != null) { title += " : " + DbgFormatter.PartId(bindToPart); } var dlg = dialogsRoot.AddComponent <PartDebugAdjustmentDialog>(); dlg.dialogTitle = title; dlg.dialogWidth = dialogWidth ?? dlg.dialogWidth; dlg.dialogValueSize = valueColumnWidth ?? dlg.dialogValueSize; dlg.controlsGroup = group; if (bindToPart != null) { dlg.lockToPart = true; dlg.SetPart(bindToPart); } DebugEx.Info("Created debug dialog: {0}", title); return(dlg); }
/// <summary>Shows a window that displays the winch controls.</summary> /// <param name="windowId">Window ID.</param> void ConsoleWindowFunc(int windowId) { if (guiActions.ExecutePendingGuiActions()) { if (parentPartTracking && Input.GetMouseButtonDown(0) && !windowRect.Contains(Mouse.screenPos)) { SetPart(Mouse.HoveredPart); parentPartTracking = false; } } string parentPartName = parentPart != null?DbgFormatter.PartId(parentPart) : "NONE"; if (!lockToPart) { if (GUILayout.Button(!parentPartTracking ? "Set part" : "Cancel set mode...")) { guiActions.Add(() => { parentPartTracking = !parentPartTracking; }); } if (parentPartTracking && Mouse.HoveredPart != null) { parentPartName = "Select: " + DbgFormatter.PartId(Mouse.HoveredPart); } GUILayout.Label(parentPartName, new GUIStyle(GUI.skin.box) { wordWrap = true }); } // Render the adjustable fields. if (parentPart != null && adjustableModules != null) { if (adjustableModules.Length > 0) { mainScrollView.BeginView(GUI.skin.box, Screen.height - 200); for (var i = 0; i < adjustableModules.Length; i++) { var isSelected = selectedModule == i; var module = adjustableModules[i]; var toggleCaption = (isSelected ? "\u25b2 " : "\u25bc ") + "Module: " + module.Key; if (GUILayout.Button(toggleCaption)) { var selectedModuleSnapshot = selectedModule == i ? -1 : i; // Make a copy for lambda! guiActions.Add(() => selectedModule = selectedModuleSnapshot); } if (isSelected) { foreach (var control in module.Value) { control.RenderControl( guiActions, GUI.skin.label, new[] { GUILayout.Width(dialogValueSize) }); } } } mainScrollView.EndView(); } else { GUILayout.Box("No adjustable members found"); } } if (GUILayout.Button("Close", GUILayout.ExpandWidth(false))) { guiActions.Add(() => DebugGui.DestroyPartDebugDialog(this)); } // Allow the window to be dragged by its title bar. GuiWindow.DragWindow(ref windowRect, titleBarRect); }
/// <summary>Shows a window that displays the winch controls.</summary> /// <param name="windowId">Window ID.</param> void ConsoleWindowFunc(int windowId) { MakeGuiStyles(); if (guiActions.ExecutePendingGuiActions()) { if (parentPartTracking) { SetPart(Mouse.HoveredPart); } if (parentPartTracking && Input.GetMouseButtonDown(0)) { parentPartTracking = false; } } using (new GUILayout.VerticalScope(GUI.skin.box)) { using (new GuiEnabledStateScope(!parentPartTracking)) { if (GUILayout.Button("Set part")) { guiActions.Add(() => parentPartTracking = true); } } using (new GuiEnabledStateScope(parentPartTracking)) { if (GUILayout.Button("Cancel set mode...")) { guiActions.Add(() => parentPartTracking = false); } } var parentPartName = "Part: " + (parentPart != null ? DbgFormatter.PartId(parentPart) : "NONE"); GUILayout.Label(parentPartName, guiNoWrapStyle); } if (parentPart != null && itemModule != null && (itemModule.equipable || itemModule.carriable)) { GUILayout.Label("KIS Item detected:"); using (new GUILayout.VerticalScope(GUI.skin.box)) { using (new GUILayout.HorizontalScope(GUI.skin.box)) { GUILayout.Label("Equip pos (metres):", guiCaptionStyle); GUILayout.FlexibleSpace(); itemModule.equipPos = itemPosition.UpdateFrame( itemModule.equipPos, guiValueStyle, new[] { GUILayout.Width(100) }); } using (new GUILayout.HorizontalScope(GUI.skin.box)) { GUILayout.Label("Equip dir (euler degrees):", guiCaptionStyle); GUILayout.FlexibleSpace(); itemModule.equipDir = itemDirection.UpdateFrame( itemModule.equipDir, guiValueStyle, new[] { GUILayout.Width(100) }); } } } if (GUILayout.Button("Close", GUILayout.ExpandWidth(false))) { guiActions.Add(() => isGUIOpen = false); } // Allow the window to be dragged by its title bar. GuiWindow.DragWindow(ref windowRect, titleBarRect); }