Persist HUD layout on drag-end instead of only on teardown

HUD panel positions and brush values were written only from
OnApplicationQuit/OnDestroy, which is not guaranteed in a build (Alt-F4,
process kill, crash), so layout work was lost. DraggablePanel now exposes
an IEndDragHandler callback that saves the layout the moment a panel is
dropped. Brush-value changes are detected against a disk baseline in
LateUpdate and flushed after a 0.5s debounce so per-frame slider drags
do not write every frame. The teardown save path is removed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-06-28 13:56:02 +02:00
1 parent 2a6fc163b1
commit f22ca4765f
3 files changed
+93 -23

No files matched your search

+3 -2
View File
@@ -162,6 +162,7 @@ public partial class PaintHud : MonoBehaviour
if (_hasCarry) ApplyCarry();
else RestoreHudState();
CaptureCarry(); // seed/refresh the mirror from the now-current painter
SnapshotSavedBaseline(); // values now match disk -> auto-save only fires on a real edit
UpdateButtonStates(); // enable Save now that a painter is bound
}
@@ -169,7 +170,6 @@ public partial class PaintHud : MonoBehaviour
private void OnDestroy()
{
if (painter) painter.Picked -= SyncFromPainter;
SaveHudOnTeardown();
}
private void OnModeChanged(GameMode mode)
@@ -409,13 +409,14 @@ public partial class PaintHud : MonoBehaviour
/// from any of its non-interactive surface (header, padding, labels, background); the component
/// ignores presses that start on a widget (toggle, slider, colour picker).
/// </summary>
private static void MakeDraggable(Transform root, string panelName)
private void MakeDraggable(Transform root, string panelName)
{
var panel = FindDeep(root, panelName) as RectTransform;
if (!panel) return;
var drag = panel.GetComponent<DraggablePanel>();
if (!drag) drag = panel.gameObject.AddComponent<DraggablePanel>();
drag.target = panel;
drag.Moved = OnPanelMoved; // persist the layout the moment a panel is dropped
}
private void EnsureFonts(Transform panel)