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

+38 -14
View File
@@ -39,25 +39,41 @@ public partial class MeshPainter
}
}
/// <summary>Reads vertices/triangles/UVs of the collider mesh and computes culling data.</summary>
// BuildMeshCaches scratch: refilled per bake without allocating (with updateColliderEveryFrame this
// runs per frame while painting; mesh.vertices/.triangles/.uv return fresh arrays per call).
private readonly System.Collections.Generic.List<Vector3> _vertScratch = new System.Collections.Generic.List<Vector3>();
private int _meshCacheId; // mesh instance the topology/UV caches were built for (0 = none)
/// <summary>Reads vertices/triangles/UVs of the collider mesh and computes culling data.
/// Only the vertices change across re-bakes of the same mesh; topology/UVs are fetched once.</summary>
private void BuildMeshCaches()
{
Mesh m = _collider.sharedMesh;
if (!m) return;
_verts = m.vertices;
_tris = m.triangles;
_uvs = m.uv;
m.GetVertices(_vertScratch);
int vCount = _vertScratch.Count;
if (_verts == null || _verts.Length != vCount) _verts = new Vector3[vCount];
_vertScratch.CopyTo(_verts);
// Fallback to the original mesh UVs if the baked mesh dropped them.
if ((_uvs == null || _uvs.Length != _verts.Length) && _skinned && _skinned.sharedMesh)
_uvs = _skinned.sharedMesh.uv;
if (_meshCacheId != m.GetInstanceID())
{
_meshCacheId = m.GetInstanceID();
_tris = m.triangles;
_uvs = m.uv;
// Fallback to the original mesh UVs if the baked mesh dropped them.
if ((_uvs == null || _uvs.Length != vCount) && _skinned && _skinned.sharedMesh)
_uvs = _skinned.sharedMesh.uv;
}
if (_uvs == null || _uvs.Length != _verts.Length) return;
int triCount = _tris.Length / 3;
_triCenter = new Vector3[triCount];
_triRadius = new float[triCount];
if (_triCenter == null || _triCenter.Length != triCount)
{
_triCenter = new Vector3[triCount];
_triRadius = new float[triCount];
}
double sumArea3D = 0.0, sumAreaUv = 0.0;
@@ -209,7 +225,7 @@ public partial class MeshPainter
{
_materialInstance.EnableKeyword("_METALLICSPECGLOSSMAP");
_materialInstance.DisableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A");
if (_materialInstance.HasProperty(SmoothnessId)) _materialInstance.SetFloat(SmoothnessId, 1f);
SetMatFloat(SmoothnessId, 1f);
}
// Emission map x _EmissionColor (white * intensity). Clear the "emissive is black"
@@ -218,6 +234,7 @@ public partial class MeshPainter
{
_materialInstance.EnableKeyword("_EMISSION");
_materialInstance.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
_lastEmissionIntensity = float.NaN; // fresh material instance -> force the first write
RefreshEmissionColor();
}
@@ -226,7 +243,7 @@ public partial class MeshPainter
if (_materialInstance.HasProperty(OcclusionMapId))
{
_materialInstance.EnableKeyword("_OCCLUSIONMAP");
if (_materialInstance.HasProperty(OcclusionStrengthId)) _materialInstance.SetFloat(OcclusionStrengthId, 1f);
SetMatFloat(OcclusionStrengthId, 1f);
}
// Height: the same mask map is also bound to _ParallaxMap, so the painted occlusion (G) doubles
@@ -239,16 +256,23 @@ public partial class MeshPainter
{
_materialInstance.EnableKeyword("_PARALLAXMAP");
_materialInstance.EnableKeyword("_NORMALMAP");
if (_materialInstance.HasProperty(ParallaxId) && _materialInstance.GetFloat(ParallaxId) < 0.02f)
_materialInstance.SetFloat(ParallaxId, 0.02f);
if (GetMatFloat(ParallaxId, 0.02f) < 0.02f)
SetMatFloat(ParallaxId, 0.02f);
}
}
/// <summary>Pushes the global emission intensity to the material's _EmissionColor (live-tunable).</summary>
private float _lastEmissionIntensity = float.NaN;
/// <summary>Pushes the global emission intensity to the material's _EmissionColor (live-tunable).
/// Runs per frame, so it only writes the material when the intensity actually changed.</summary>
private void RefreshEmissionColor()
{
if (emissionIntensity == _lastEmissionIntensity) return;
if (_materialInstance && _materialInstance.HasProperty(EmissionColorId))
{
_materialInstance.SetColor(EmissionColorId, Color.white * Mathf.Max(0f, emissionIntensity));
_lastEmissionIntensity = emissionIntensity;
}
}
/// <summary>Eases the see-through X-ray glow's alpha toward its on/off target (<see cref="XRayRevealed"/>)