Refactor: dedupe input reads, material-property guards, button hooks

Extract byte-identical duplicated code into shared helpers (behaviour-neutral):
- New InputUtil.cs: single source for mouse-delta/scroll/cursor-lock, modifier
  and mouse-button reads, previously copied verbatim across camera controllers,
  MeshPainter, FirstPersonMode and PlayerCharacterController.
- GetMatFloat/SetMatFloat replace the 12x material-instance + HasProperty guard
  pattern for the camo/height float properties.
- Route two inline button hooks through the existing Hook() helper.

Bespoke variants deliberately kept local (FreeCam SprintHeld = LeftShift only,
MeshPainter.TryGetMouse with out-params).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-07-02 09:20:40 +02:00
1 parent 626dcc1bdf
commit 882d30797e
11 files changed
+158 -222

No files matched your search

+6 -33
View File
@@ -775,12 +775,12 @@ public class PlayerCharacterController : MonoBehaviour
// offset eases back to zero while moving and never detaches. On a WALL the turn is a held
// yaw offset from the wall normal (kept until leaving); on a CEILING the body is free like
// on the ground, so the drag rotates the transform directly. Either drag pauses the orbit.
bool offsetDrag = found && IsLeftMouseHeld();
bool yawDrag = found && IsRightMouseHeld();
bool offsetDrag = found && InputUtil.LeftMouseHeld();
bool yawDrag = found && InputUtil.RightMouseHeld();
if (offsetDrag || yawDrag)
{
_offsetDragging = true;
Vector2 drag = ReadMouseDelta();
Vector2 drag = InputUtil.ReadMouseDelta();
if (offsetDrag)
_wallOffset = Mathf.Clamp(_wallOffset - drag.y * wallOffsetSensitivity, -wallMaxInset, wallMaxOffset);
if (yawDrag)
@@ -948,14 +948,14 @@ public class PlayerCharacterController : MonoBehaviour
{
_offsetDragging = false;
bool offsetDrag = IsLeftMouseHeld();
bool yawDrag = IsRightMouseHeld();
bool offsetDrag = InputUtil.LeftMouseHeld();
bool yawDrag = InputUtil.RightMouseHeld();
bool hasMoveInput = (h * h + v * v) > 1e-4f;
if (offsetDrag || yawDrag)
{
_offsetDragging = true;
Vector2 drag = ReadMouseDelta();
Vector2 drag = InputUtil.ReadMouseDelta();
if (offsetDrag)
_groundOffset = Mathf.Clamp(
_groundOffset + drag.y * wallOffsetSensitivity, -wallMaxInset, wallMaxOffset);
@@ -1245,33 +1245,6 @@ public class PlayerCharacterController : MonoBehaviour
_mantleTimer = 0f;
}
bool IsLeftMouseHeld()
{
#if ENABLE_INPUT_SYSTEM
return Mouse.current != null && Mouse.current.leftButton.isPressed;
#else
return Input.GetMouseButton(0);
#endif
}
bool IsRightMouseHeld()
{
#if ENABLE_INPUT_SYSTEM
return Mouse.current != null && Mouse.current.rightButton.isPressed;
#else
return Input.GetMouseButton(1);
#endif
}
Vector2 ReadMouseDelta()
{
#if ENABLE_INPUT_SYSTEM
return Mouse.current != null ? Mouse.current.delta.ReadValue() : Vector2.zero;
#else
return new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * 10f;
#endif
}
/// <summary>
/// Collects contact normals during Move: wall/ceiling contacts feed the
/// wall-climb detector, the flattest upward contact becomes the ground normal.