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:
@@ -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
|
||||
Reference in New Issue
Block a user