Refactor scripts: dedup remainder, remove dead code, perf hardening

Iteration 4 over Assets/Scripts (no component/file splits, no Unity assets touched):

Dedup:
- Route inline cursor-release, material guards, Ctrl-held and undo/redo
  input through existing InputUtil / SetMatFloat helpers
- Add ungated InputUtil.KeyPressedThisFrame; GameplayKeyPressed builds on it
- Unify FindDeep/FindDeepChild into GeometryUtil.FindDeep

Dead code / stale docs:
- Remove unused code-gen bake path (HsvColorPicker.Build, PaintHud factory)
- Drop unreferenced symbols (SubPhaseChanged event, LocalPhaseDuration,
  IsLocalSceneMain, MouseSensitivity.Changed, IsPaused, InSession,
  NetworkControlled, PreviousPose, JointCount, voxel-count accessors)
- Fix incorrect PlayerRole / PaintHud / Pick / PlayerPose docs

Perf / robustness (behaviour-neutral):
- ConcealmentMeter.Evaluate: reuse vertex/topology buffers, two-pointer
  crossing count
- BuildMeshCaches: alloc-free vertex copy, cached topology/UVs
- Guard all PlayerPaintSync LogSync sites behind logSync
- Cache LocalViewerIsHunter / controller / CanShoot / TypingGuard lookups;
  dedup LocalIsHunter with MatchHud
- Change-guard RefreshEmissionColor and HeroCutout.Disarm
- Cache scene/countdown string comparisons per frame
- Grow NonAlloc buffers and log-once on saturation

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-07-02 13:33:18 +02:00
1 parent 2243cc823e
commit 382bfb36df
32 files changed
+292 -348

No files matched your search

+14 -56
View File
@@ -11,10 +11,10 @@ using UnityEngine.InputSystem.UI;
/// <see cref="PaintMode"/> (follows the manager's ModeChanged) and binds its widgets directly to the
/// live <see cref="MeshPainter"/> fields, so edits apply immediately.
///
/// The layout (independently draggable sub-panels per channel + a global brush card) comes from an
/// authored prefab (<see cref="layoutPrefab"/>) or is generated in code as the fallback. Either way
/// the BINDINGS live in code and are (re)applied at runtime by <see cref="WirePanel"/> against the
/// same stable widget names - a prefab stores only the visual layout, never behaviour.
/// The layout (independently draggable sub-panels per channel + a global brush card) comes from the
/// authored prefab (<see cref="layoutPrefab"/>). The BINDINGS live in code and are (re)applied at
/// runtime by <see cref="WirePanel"/> against stable widget names - the prefab stores only the
/// visual layout, never behaviour.
/// </summary>
[DisallowMultipleComponent]
public partial class PaintHud : MonoBehaviour
@@ -25,10 +25,10 @@ public partial class PaintHud : MonoBehaviour
[Tooltip("Painter the HUD edits. Empty = the manager's painter, else found automatically.")]
public MeshPainter painter;
[Tooltip("Authored panel layout. If set it is instantiated and bound; empty = build the panel in code.")]
[Tooltip("Authored panel layout. Instantiated and bound at startup.")]
public GameObject layoutPrefab;
// Stable widget names shared by the code-gen builder, the baked prefab and the binder.
// Stable widget names shared by the baked prefab and the binder.
private const string PanelGeneral = "Panel_General";
private const string PanelSpray = "Panel_Spray";
private const string PanelAlbedo = "Panel_Albedo";
@@ -408,13 +408,13 @@ public partial class PaintHud : MonoBehaviour
/// </summary>
private void WireMaskSelector(Transform panel)
{
var selector = FindDeep(panel, MaskSelector);
var selector = GeometryUtil.FindDeep(panel, MaskSelector);
if (!selector) return;
var masks = painter ? painter.brushMasks : null;
for (int i = 0; ; i++)
{
var swatch = FindDeep(selector, MaskSwatchPrefix + i);
var swatch = GeometryUtil.FindDeep(selector, MaskSwatchPrefix + i);
if (!swatch) break;
bool has = masks != null && i < masks.Count && masks[i];
@@ -445,12 +445,12 @@ public partial class PaintHud : MonoBehaviour
private void RefreshMaskHighlights()
{
if (!_panel || !painter) return;
var selector = FindDeep(_panel.transform, MaskSelector);
var selector = GeometryUtil.FindDeep(_panel.transform, MaskSelector);
if (!selector) return;
for (int i = 0; ; i++)
{
var swatch = FindDeep(selector, MaskSwatchPrefix + i);
var swatch = GeometryUtil.FindDeep(selector, MaskSwatchPrefix + i);
if (!swatch) break;
var frame = swatch.GetComponent<Image>();
if (frame) frame.color = i == painter.activeBrushIndex ? MaskFrameSelected : MaskFrameUnselected;
@@ -477,7 +477,7 @@ public partial class PaintHud : MonoBehaviour
/// </summary>
private void MakeDraggable(Transform root, string panelName)
{
var panel = FindDeep(root, panelName) as RectTransform;
var panel = GeometryUtil.FindDeep(root, panelName) as RectTransform;
if (!panel) return;
var drag = panel.GetComponent<DraggablePanel>();
if (!drag) drag = panel.gameObject.AddComponent<DraggablePanel>();
@@ -507,7 +507,7 @@ public partial class PaintHud : MonoBehaviour
/// </summary>
private static void WirePanelFade(Transform root, string panelName, string toggleName)
{
var panel = FindDeep(root, panelName);
var panel = GeometryUtil.FindDeep(root, panelName);
if (!panel) return;
var group = panel.GetComponent<CanvasGroup>();
if (!group) group = panel.gameObject.AddComponent<CanvasGroup>();
@@ -522,7 +522,7 @@ public partial class PaintHud : MonoBehaviour
/// <summary>Finds a slider cell by name and the Slider inside it (null when either is missing).</summary>
private static Slider FindSlider(Transform panel, string name, out Transform cell)
{
cell = FindDeep(panel, name);
cell = GeometryUtil.FindDeep(panel, name);
return cell ? cell.GetComponentInChildren<Slider>() : null;
}
@@ -560,52 +560,10 @@ public partial class PaintHud : MonoBehaviour
private static T Find<T>(Transform panel, string name) where T : Component
{
var child = FindDeep(panel, name);
var child = GeometryUtil.FindDeep(panel, name);
return child ? child.GetComponent<T>() : null;
}
/// <summary>Depth-first search by name (widgets now live nested inside per-channel sub-panels).</summary>
private static Transform FindDeep(Transform root, string name)
{
if (root.name == name) return root;
for (int i = 0; i < root.childCount; i++)
{
var found = FindDeep(root.GetChild(i), name);
if (found) return found;
}
return null;
}
// --- Static UI factory (shared with HsvColorPicker) ---
public static RectTransform NewRect(string name, Transform parent)
{
var go = new GameObject(name, typeof(RectTransform));
go.transform.SetParent(parent, false);
return (RectTransform)go.transform;
}
public static Image AddImage(GameObject go, Color color)
{
var img = go.AddComponent<Image>();
img.color = color;
return img;
}
/// <summary>Adds a full-rect, non-raycasting overlay image (sprite assigned by the caller).</summary>
public static Image AddOverlay(RectTransform parent, string name)
{
var rt = NewRect(name, parent);
rt.anchorMin = Vector2.zero;
rt.anchorMax = Vector2.one;
rt.offsetMin = Vector2.zero;
rt.offsetMax = Vector2.zero;
var img = rt.gameObject.AddComponent<Image>();
img.type = Image.Type.Simple;
img.raycastTarget = false;
return img;
}
// Cached gradient sprites for the colour picker.
private static Sprite _satSprite, _valSprite, _hueSprite;