Hygiene B4b: extract CameraResolver (dedup triplicated ResolveCamera)

The byte-identical ResolveCamera() (Camera.main -> PrototypeCameraRig fallback) in PlayerInputGatherSystem, BuildSendSystem, and AimReticleSystem now call one CameraResolver.Resolve(); camera-resolution policy lives in one place. Behaviour-identical; compiles clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-08 13:07:40 -07:00
parent b48fe5250c
commit 55e98a9275
5 changed files with 29 additions and 33 deletions
@@ -143,7 +143,7 @@ namespace ProjectM.Client
}
if (!SystemAPI.TryGetSingleton<BaseAnchor>(out var anchor)) { HideGhost(); return; }
if (_camera == null) _camera = ResolveCamera();
if (_camera == null) _camera = CameraResolver.Resolve();
if (_camera == null || mouse == null) { HideGhost(); return; }
// Cursor -> ground -> cell.
@@ -248,16 +248,7 @@ namespace ProjectM.Client
_ghost.SetActive(false);
}
UnityEngine.Camera ResolveCamera()
{
var cam = UnityEngine.Camera.main;
if (cam == null)
{
var rig = Object.FindAnyObjectByType<PrototypeCameraRig>();
if (rig != null) cam = rig.GetComponent<UnityEngine.Camera>();
}
return cam;
}
bool TryGetLocalPlayerCell(out int2 cell)
{
@@ -126,7 +126,7 @@ namespace ProjectM.Client
AimPresentation.Scheme = _scheme;
// Mouse cursor projection needs the camera; resolve/cache it (Camera.main or the rig's camera).
if (_camera == null) _camera = ResolveCamera();
if (_camera == null) _camera = CameraResolver.Resolve();
UnityEngine.Vector2 cursorScreen = mouse != null ? mouse.position.ReadValue() : default;
foreach (var (input, xform) in
@@ -173,15 +173,6 @@ namespace ProjectM.Client
}
}
private UnityEngine.Camera ResolveCamera()
{
var cam = UnityEngine.Camera.main;
if (cam == null)
{
var rig = UnityEngine.Object.FindAnyObjectByType<PrototypeCameraRig>();
if (rig != null) cam = rig.GetComponent<UnityEngine.Camera>();
}
return cam;
}
}
}
@@ -51,7 +51,7 @@ namespace ProjectM.Client
protected override void OnUpdate()
{
byte scheme = AimPresentation.Scheme;
if (_camera == null) _camera = ResolveCamera();
if (_camera == null) _camera = CameraResolver.Resolve();
bool haveTarget = false;
float3 ringPos = default;
@@ -157,16 +157,7 @@ namespace ProjectM.Client
}
}
UnityEngine.Camera ResolveCamera()
{
var cam = UnityEngine.Camera.main;
if (cam == null)
{
var rig = UnityEngine.Object.FindAnyObjectByType<PrototypeCameraRig>();
if (rig != null) cam = rig.GetComponent<UnityEngine.Camera>();
}
return cam;
}
protected override void OnDestroy()
{
@@ -0,0 +1,21 @@
namespace ProjectM.Client
{
/// <summary>
/// Resolves the gameplay camera for the client systems that cursor-raycast against the ground (input aim,
/// build placement, aim reticle): <see cref="UnityEngine.Camera.main"/>, falling back to the
/// <see cref="PrototypeCameraRig"/>'s Camera. Single source so the camera-resolution policy lives in one place.
/// </summary>
public static class CameraResolver
{
public static UnityEngine.Camera Resolve()
{
var cam = UnityEngine.Camera.main;
if (cam == null)
{
var rig = UnityEngine.Object.FindAnyObjectByType<PrototypeCameraRig>();
if (rig != null) cam = rig.GetComponent<UnityEngine.Camera>();
}
return cam;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 94961d35ebce5d34a80b77b53592b156