diff --git a/Editor/MenuActions/Geometry/BevelEdges.cs b/Editor/MenuActions/Geometry/BevelEdges.cs index f098814f4..600c1e987 100644 --- a/Editor/MenuActions/Geometry/BevelEdges.cs +++ b/Editor/MenuActions/Geometry/BevelEdges.cs @@ -61,6 +61,16 @@ public override VisualElement CreateSettingsContent() PreviewActionManager.UpdatePreview(); } }); + + System.Action onDelayedPreviewChanged = () => + { + floatField.isDelayed = PreviewActionManager.delayedPreview; + }; + PreviewActionManager.delayedPreviewChanged += onDelayedPreviewChanged; + root.RegisterCallback(evt => + { + PreviewActionManager.delayedPreviewChanged -= onDelayedPreviewChanged; + }); root.Add(floatField); return root; diff --git a/Editor/MenuActions/Geometry/ExtrudeEdges.cs b/Editor/MenuActions/Geometry/ExtrudeEdges.cs index cc297f6f2..85f8a9634 100644 --- a/Editor/MenuActions/Geometry/ExtrudeEdges.cs +++ b/Editor/MenuActions/Geometry/ExtrudeEdges.cs @@ -53,6 +53,16 @@ public override VisualElement CreateSettingsContent() floatField.tooltip = "Extrude Amount determines how far an edge will be moved along it's normal when extruding. This value can be negative."; floatField.SetValueWithoutNotify(m_ExtrudeEdgeDistance); floatField.RegisterCallback>(OnExtrudeChanged); + + System.Action onDelayedPreviewChanged = () => + { + floatField.isDelayed = PreviewActionManager.delayedPreview; + }; + PreviewActionManager.delayedPreviewChanged += onDelayedPreviewChanged; + root.RegisterCallback(evt => + { + PreviewActionManager.delayedPreviewChanged -= onDelayedPreviewChanged; + }); root.Add(floatField); return root; diff --git a/Editor/MenuActions/Geometry/ExtrudeFaces.cs b/Editor/MenuActions/Geometry/ExtrudeFaces.cs index 47ad77030..218e41ad9 100644 --- a/Editor/MenuActions/Geometry/ExtrudeFaces.cs +++ b/Editor/MenuActions/Geometry/ExtrudeFaces.cs @@ -106,6 +106,16 @@ public override VisualElement CreateSettingsContent() }); root.Add(distanceField); + System.Action onDelayedPreviewChanged = () => + { + distanceField.isDelayed = PreviewActionManager.delayedPreview; + }; + PreviewActionManager.delayedPreviewChanged += onDelayedPreviewChanged; + root.RegisterCallback(evt => + { + PreviewActionManager.delayedPreviewChanged -= onDelayedPreviewChanged; + }); + return root; } diff --git a/Editor/MenuActions/Geometry/OffsetElements.cs b/Editor/MenuActions/Geometry/OffsetElements.cs index fbcb3e6d7..c4013f8b6 100644 --- a/Editor/MenuActions/Geometry/OffsetElements.cs +++ b/Editor/MenuActions/Geometry/OffsetElements.cs @@ -51,9 +51,9 @@ public override VisualElement CreateSettingsContent() var spaceField = new EnumField("Coordinate Space", coord); root.Add(spaceField); - spaceField.RegisterCallback>(evt => + spaceField.RegisterCallback>(evt => { - Enum.TryParse(evt.newValue, out CoordinateSpace newValue); + CoordinateSpace newValue = (CoordinateSpace)evt.newValue; if (s_CoordinateSpace.value == newValue) return; s_CoordinateSpace.SetValue(newValue); @@ -62,8 +62,7 @@ public override VisualElement CreateSettingsContent() var distField = new Vector3Field("Translate"); distField.SetValueWithoutNotify(dist); - if(PreviewActionManager.delayedPreview) - distField.Query().ForEach(ff => ff.isDelayed = true); + distField.Query().ForEach(ff => ff.isDelayed = PreviewActionManager.delayedPreview); root.Add(distField); distField.RegisterCallback>(evt => { @@ -71,6 +70,16 @@ public override VisualElement CreateSettingsContent() PreviewActionManager.UpdatePreview(); }); + Action onDelayedPreviewChanged = () => + { + distField.Query().ForEach(ff => ff.isDelayed = PreviewActionManager.delayedPreview); + }; + PreviewActionManager.delayedPreviewChanged += onDelayedPreviewChanged; + root.RegisterCallback(evt => + { + PreviewActionManager.delayedPreviewChanged -= onDelayedPreviewChanged; + }); + return root; } diff --git a/Editor/MenuActions/Geometry/SubdivideEdges.cs b/Editor/MenuActions/Geometry/SubdivideEdges.cs index 52a5b218c..46118748b 100644 --- a/Editor/MenuActions/Geometry/SubdivideEdges.cs +++ b/Editor/MenuActions/Geometry/SubdivideEdges.cs @@ -83,6 +83,15 @@ public override VisualElement CreateSettingsContent() m_SubdivCount.tooltip = tooltip; m_SubdivCount.RegisterCallback>(OnCountChanged); m_SubdivCount.style.width = 40; + Action onDelayedPreviewChanged = () => + { + m_SubdivCount.isDelayed = PreviewActionManager.delayedPreview; + }; + PreviewActionManager.delayedPreviewChanged += onDelayedPreviewChanged; + root.RegisterCallback(evt => + { + PreviewActionManager.delayedPreviewChanged -= onDelayedPreviewChanged; + }); line.Add(foldout); line.Add(m_Slider); line.Add(m_SubdivCount); diff --git a/Editor/MenuActions/Geometry/WeldVertices.cs b/Editor/MenuActions/Geometry/WeldVertices.cs index 0e5b7a8ff..009a7f8b4 100644 --- a/Editor/MenuActions/Geometry/WeldVertices.cs +++ b/Editor/MenuActions/Geometry/WeldVertices.cs @@ -69,6 +69,15 @@ public override VisualElement CreateSettingsContent() m_WeldDistance.SetValue(evt.newValue); PreviewActionManager.UpdatePreview(); }); + Action onDelayedPreviewChanged = () => + { + floatField.isDelayed = PreviewActionManager.delayedPreview; + }; + PreviewActionManager.delayedPreviewChanged += onDelayedPreviewChanged; + root.RegisterCallback(evt => + { + PreviewActionManager.delayedPreviewChanged -= onDelayedPreviewChanged; + }); root.Add(floatField); return root; } diff --git a/Editor/MenuActions/Selection/GrowSelection.cs b/Editor/MenuActions/Selection/GrowSelection.cs index ceda26f6f..fa646e6bc 100644 --- a/Editor/MenuActions/Selection/GrowSelection.cs +++ b/Editor/MenuActions/Selection/GrowSelection.cs @@ -85,7 +85,15 @@ public override VisualElement CreateSettingsContent() m_GrowSelectionAngleIterative.SetValue(evt.newValue); PreviewActionManager.UpdatePreview(); }); - + System.Action onDelayedPreviewChanged = () => + { + floatField.isDelayed = PreviewActionManager.delayedPreview; + }; + PreviewActionManager.delayedPreviewChanged += onDelayedPreviewChanged; + root.RegisterCallback(evt => + { + PreviewActionManager.delayedPreviewChanged -= onDelayedPreviewChanged; + }); return root; } diff --git a/Editor/Overlays/ActionSettings.cs b/Editor/Overlays/ActionSettings.cs index 14e3153cc..dadb3ca65 100644 --- a/Editor/Overlays/ActionSettings.cs +++ b/Editor/Overlays/ActionSettings.cs @@ -18,6 +18,7 @@ class PreviewActionManager : IDisposable [UserSetting("Mesh Editing", "Auto Update Action Preview", "Automatically update the action preview, without delay. This operation is costly and can cause lag when working with large selections.")] static Pref s_AutoUpdatePreview = new Pref("editor.autoUpdatePreview", false, SettingsScope.Project); internal static bool delayedPreview => !s_AutoUpdatePreview.value; + public static event Action delayedPreviewChanged; MenuAction m_CurrentAction; @@ -59,8 +60,10 @@ void Init(MenuAction action, bool preview) ProBuilderEditor.selectModeChanged += SelectModeChanged; SceneView.AddOverlayToActiveView(m_Overlay = new MenuActionSettingsOverlay()); + // Hack to ensure that the overlay is displayed in the sceneview even when the overlay was already displayed before + // Doing only displayed = true is not adding the overlay as it should in the view, only changing the display status is + m_Overlay.displayed = false; m_Overlay.displayed = true; - SceneView.RepaintAll(); } public void Dispose() @@ -104,12 +107,7 @@ internal static void SetPreviewUpdate(bool value) s_AutoUpdatePreview.value = value; - if (s_Instance == null) - return; - - SceneView.RemoveOverlayFromActiveView(s_Instance.m_Overlay); - SceneView.AddOverlayToActiveView(s_Instance.m_Overlay = new MenuActionSettingsOverlay()); - s_Instance.m_Overlay.displayed = true; + delayedPreviewChanged?.Invoke(); } internal static void EndPreview()