Simplify HUD layout save path to a fixed PaintHud.json

Drop the scene-derived hudSaveId/key mechanism and save the HUD layout to a
single PaintHud.json under persistentDataPath.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-07-03 14:52:22 +02:00
1 parent 6ef4f56394
commit f586ef7a15
1 file changed
+2 -16
@@ -20,10 +20,6 @@ public partial class PaintHud
"defaults every session.")]
public bool persistHud = true;
[Tooltip("Save file identifier. Empty = derived from the HUD's own scene name. Set explicitly to keep " +
"the layout stable across scene renames or to share one layout between scenes.")]
public string hudSaveId = "";
private const int HudFileVersion = 1;
// Auto-save bookkeeping. Brush edits are debounced (sliders fire every frame while dragged): the due
@@ -60,21 +56,11 @@ public partial class PaintHud
private bool _hasDefaults; // non-camo defaults captured (first bind, before restore/carry)
private bool _hasDefaultCamo; // camo defaults captured (first ready-gate, before any pending camo apply)
private static string HudSaveDir => Path.Combine(Application.persistentDataPath, "MeshPaint");
private string HudSavePath()
{
// Derive from the HUD's OWN scene (a stable persistent scene), not the active scene: the latter
// now changes across the additive lobby/map loads, so a key from it would split save and restore
// into different files and silently lose the saved layout.
string key = string.IsNullOrEmpty(hudSaveId)
? SanitizeHudKey(gameObject.scene.name + "_hud")
: SanitizeHudKey(hudSaveId);
return Path.Combine(HudSaveDir, key + ".hudlayout");
return Path.Combine(Application.persistentDataPath, "PaintHud.json");
}
private static string SanitizeHudKey(string s) => MeshPainter.SanitizeFileKey(s);
[Serializable]
private class HudState
{
@@ -145,7 +131,7 @@ public partial class PaintHud
state.hasHeightValues = _camoEverReady;
}
Directory.CreateDirectory(HudSaveDir);
Directory.CreateDirectory(Application.persistentDataPath);
File.WriteAllText(HudSavePath(), JsonUtility.ToJson(state, true));
// Refresh the on-disk baseline so the debounce does not immediately re-save unchanged values.