Docs: reduce over-documentation across gameplay scripts

Trim restated narration, dead commented-out code, and oversized class
headers; keep all why-comments (authority, timing, edge cases), tooltips,
and serialization caveats.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Fable 5 committed 2026-07-02 10:08:28 +02:00
1 parent 882d30797e
commit 066e308cde
21 files changed
+478 -902

No files matched your search

+30 -60
View File
@@ -7,21 +7,12 @@ public partial class PaintHud
{
// --- Persistence: panel positions + the widget-bound painter values ---
//
// Saved when state actually changes - a panel drop writes immediately (OnPanelMoved), brush-value
// edits are coalesced and flushed shortly after they settle (LateUpdate debounce) - and restored on
// the next start, so the HUD opens where you left it with the brush settings you last used. There is
// deliberately NO save on quit/teardown: standalone builds do not guarantee a clean shutdown
// (OnApplicationQuit is skipped on force-close / kill / crash), so a teardown-only save silently
// lost the whole session's layout in the build. This is small structured state (a handful of
// positions and scalars), so it goes to a human-readable JSON file - unlike the painter's bulk pixel
// maps (MeshPainter.Persistence) which use a raw byte dump. The two saves are independent: this one
// owns the HUD layout + brush values, the painter owns the canvas pixels.
//
// The brush values are also mirrored into an in-memory snapshot (_carry) on this persistent HUD, so
// they survive the avatar respawn that a scene switch (lobby -> map) triggers: the new painter gets
// the carried values instead of its prefab defaults. The save key is derived from the HUD's OWN
// scene (a stable persistent scene), not the active scene - the latter now changes across the
// additive lobby/map loads, which would split save and restore into different files.
// Saved when state actually changes (panel drop = instant, brush edits = debounced), restored on the
// next start. Deliberately NO save on quit/teardown: standalone builds don't guarantee a clean
// shutdown (OnApplicationQuit is skipped on force-close/kill/crash), which silently lost the whole
// session's layout in the build. Small structured state -> human-readable JSON, independent of the
// painter's bulk pixel maps (MeshPainter.Persistence). The brush values are also mirrored in-memory
// (_carry) so they survive the avatar respawn a scene switch triggers.
[Header("Persistence")]
[Tooltip("Save the panel positions and their values when you move a panel or change a brush value, " +
@@ -35,9 +26,8 @@ public partial class PaintHud
private const int HudFileVersion = 1;
// Auto-save bookkeeping. Panel drops save instantly; brush-value edits are debounced because sliders
// fire every frame while dragged - we push the due time forward and write once they settle. No
// teardown save, so persistence never depends on a clean quit.
// Auto-save bookkeeping. Brush edits are debounced (sliders fire every frame while dragged): the due
// time is pushed forward and written once they settle.
private const float HudSaveDebounce = 0.5f;
private readonly HudValues _savedValues = new HudValues(); // mirror of what is currently on disk
private readonly HudValues _lastSeenValues = new HudValues(); // painter values observed last frame (settle detection)
@@ -45,31 +35,25 @@ public partial class PaintHud
private bool _hudSavePending;
private float _hudSaveDueTime;
// In-memory mirror of the brush values, kept on this persistent HUD so they survive the avatar
// respawn a scene switch (lobby <-> map) triggers: the freshly spawned painter is seeded with these
// instead of its prefab defaults. Single instance with mutable fields -> no per-frame allocation.
// In-memory mirror seeding a freshly respawned painter (instead of its prefab defaults). Single
// instance with mutable fields -> no per-frame allocation.
private readonly HudValues _carry = new HudValues();
private bool _hasCarry;
// Camo knobs (HalfLambert / brightness / specular dampen) live on the player's PlayerCamoLit material
// instance, which only exists after the painter's Start. They are saved/restored with the brush values
// above, but can't be WRITTEN until the material is ready - so a restored (disk) or carried (respawn)
// value waits here and is applied in the LateUpdate ready-gate. _camoEverReady gates the carry/save so
// the not-yet-ready 0 the getter returns never overwrites the material's authored value.
// Camo knobs live on the material instance, which only exists after the painter's Start: a restored
// (disk) or carried (respawn) value waits here and is applied in the LateUpdate ready-gate.
// _camoEverReady gates carry/save so the not-yet-ready 0 never overwrites the authored value.
private Vector3 _pendingCamo;
private bool _hasPendingCamo;
private bool _camoEverReady;
// Painted-height knobs (occlusion threshold, normal intensity, parallax intensity) ride the exact same
// material-ready deferral as the camo knobs above: they become writable only after the painter's Start,
// so a restored/carried value waits here and is applied in the LateUpdate ready-gate (shared timing).
// Painted-height knobs ride the exact same material-ready deferral as the camo knobs above.
private Vector3 _pendingHeight;
private bool _hasPendingHeight;
// Authored defaults for the runtime reset (= "as if the saved layout file had been deleted"): the
// prefab's panel positions, captured before any saved layout is restored over them, and the painter's
// prefab/material default brush values, captured before carry/restore mutate the live painter. Camo is
// material-backed (readable only once IsReady), so it is filled in the LateUpdate ready-gate instead.
// Authored defaults for the runtime reset ("as if the save file had been deleted"): prefab panel
// positions + prefab/material default brush values, captured before restore/carry mutate them. Camo
// is material-backed (readable only once IsReady), so it is filled in the ready-gate instead.
private readonly Dictionary<string, Vector2> _authoredPanelPos = new Dictionary<string, Vector2>();
private bool _hasAuthoredLayout;
private readonly HudValues _defaults = new HudValues();
@@ -197,9 +181,8 @@ public partial class PaintHud
SyncFromPainter();
}
// Camo is material-backed and can't be written until the painter is ready -> stash the saved values
// for the LateUpdate ready-gate. hasCamoValues guards pre-camo save files: without it we would apply
// a 0 and clobber the material's authored camo.
// Camo is material-backed -> stash for the LateUpdate ready-gate. hasCamoValues guards pre-camo
// save files (applying their 0 would clobber the authored camo).
if (state.hasCamoValues && state.values != null)
{
_pendingCamo = new Vector3(state.values.camoHalfLambert,
@@ -208,8 +191,7 @@ public partial class PaintHud
_hasPendingCamo = true;
}
// Same deferral for the painted-height knobs; hasHeightValues guards pre-height save files so they
// keep the material's authored defaults instead of being slammed to a 0 threshold/flat relief.
// Same deferral + guard for the painted-height knobs.
if (state.hasHeightValues && state.values != null)
{
_pendingHeight = new Vector3(state.values.occlusionThreshold,
@@ -233,17 +215,13 @@ public partial class PaintHud
{
if (painter)
{
// Camo knobs are material-backed and only readable/writable after the painter's Start built the
// instance (binding ran earlier, in the avatar's OnNetworkSpawn). Apply the restored (disk) or
// carried (respawn) values to the material once it is ready, then seed the sliders from it. Done
// BEFORE the carry mirror + change detection below so the just-applied value is already the
// baseline and never re-triggers a redundant auto-save. With nothing pending (first session, no
// save file) the material keeps its authored camo and the sliders just reflect it.
// Apply restored/carried camo + height to the material once it is ready, then seed the
// sliders. Runs BEFORE the carry mirror + change detection below, so the just-applied value
// is already the baseline and never re-triggers a redundant auto-save.
if (!_camoSynced && painter.IsReady)
{
// Capture the material's authored camo as the reset default BEFORE any pending (restored or
// carried) camo is applied over it. Once per HUD: a later session/respawn keeps the very
// first authored value, so a reset always returns to the genuine material default.
// Capture the authored camo as the reset default BEFORE any pending value is applied over
// it - once per HUD, so a reset always returns to the genuine material default.
if (!_hasDefaultCamo)
{
_defaults.camoHalfLambert = painter.CamoHalfLambert;
@@ -283,16 +261,12 @@ public partial class PaintHud
}
// Mirror the live painter every frame; the next BindPainter (after a respawn) seeds the fresh
// painter from this snapshot instead of its prefab defaults. Captured while the painter lives,
// so it is immune to the destroy-pending timing of the despawn.
// painter from this snapshot. Captured while the painter lives - immune to despawn timing.
CaptureCarry();
// Debounced auto-save: (re)arm the settle timer only on frames where a value actually CHANGED
// since the last frame - not merely differs from disk. Sliders fire every frame while dragged,
// so this keeps the deadline ahead of the drag and writes once the values stop moving. Comparing
// against the on-disk baseline instead would push the deadline forward forever (the edit always
// differs from disk until it is written), so the save would never fire on its own - it only
// landed when something else, e.g. a panel drop, wrote the state directly.
// since the last frame - comparing against the on-disk baseline instead would push the
// deadline forward forever (an edit differs from disk until written), so it would never fire.
if (persistHud && _hasSavedBaseline && !ValuesEqual(painter, _lastSeenValues))
{
CopyValues(painter, _lastSeenValues);
@@ -404,9 +378,8 @@ public partial class PaintHud
v.sprayDotAlphaMin = from.sprayDotAlphaMin;
v.sprayDotAlphaMax = from.sprayDotAlphaMax;
// Camo is material-backed: the getters read 0 until the painter's material instance exists, so only
// mirror them once ready - otherwise preserve the desired values already in the target (the value a
// restore/carry put there, which the ready-gate still has to apply).
// Camo getters read 0 until the material exists - only mirror once ready, otherwise preserve the
// desired values already in the target (a restore/carry the ready-gate still has to apply).
if (from.IsReady)
{
v.camoHalfLambert = from.CamoHalfLambert;
@@ -506,10 +479,8 @@ public partial class PaintHud
[ContextMenu("Reset HUD Layout And Values")]
public void ResetHudToDefaults()
{
// Delete the saved layout so a restart opens at the authored defaults as well (the literal intent).
ClearSavedHudState();
// Panels -> authored prefab positions.
if (_panel && _hasAuthoredLayout)
{
var root = _panel.transform;
@@ -518,7 +489,6 @@ public partial class PaintHud
rt.anchoredPosition = kv.Value;
}
// Brush values -> painter prefab/material defaults, then push them to every widget.
if (painter && _hasDefaults)
{
// Reset clicked before the ready-gate captured the camo defaults? keep the live camo rather than