Game.CameraInput
Assembly: Assembly-CSharp
Namespace: Game
Type: class
Base: MonoBehaviour
Summary:
Component that reads and exposes camera-related input (move, fast move, rotate, zoom) from the input system. It binds ProxyAction objects from InputManager and provides simple properties (move, rotate, zoom) and boolean helpers (isMoving, any) to be consumed by a camera controller. The class also exposes public smoothing fields that can be used by the camera controller when applying the raw input values.
Fields
-
public float m_MoveSmoothing = 1E-06f
Used to control smoothing when applying movement input. The field is public so a camera controller or inspector can tune it; CameraInput itself does not perform smoothing internally. -
public float m_RotateSmoothing = 1E-06f
Smoothing factor for rotation input. Exposed for the camera controller to use when applying rotate values. -
public float m_ZoomSmoothing = 1E-06f
Smoothing factor for zoom input. Exposed for external code to apply smoothing when changing camera zoom. -
private ProxyAction m_MoveAction
Holds the ProxyAction for the regular "Move" camera action. Obtained from InputManager in Initialize(). -
private ProxyAction m_FastMoveAction
Holds the ProxyAction for the "Move Fast" camera action (e.g. when a speed modifier key is held). Used together with m_MoveAction to compute the effective movement vector. -
private ProxyAction m_RotateAction
Holds the ProxyAction for the "Rotate" camera action. -
private ProxyAction m_ZoomAction
Holds the ProxyAction for the "Zoom" camera action.
Properties
-
public UnityEngine.Vector2 move { get; private set; }
Current movement input vector. Obtained by combining m_MoveAction and m_FastMoveAction using MathUtils.MaxAbs(...) in Refresh() so the component exposes whichever has the larger absolute component per axis. -
public UnityEngine.Vector2 rotate { get; private set; }
Current rotation input vector read from m_RotateAction in Refresh(). -
public float zoom { get; private set; }
Current zoom input value read from m_ZoomAction in Refresh(). -
public bool isMoving { get; }
Returns true if the regular move action (m_MoveAction) is currently in progress. Useful to detect whether the player is actively panning the camera. -
public bool any { get; }
Returns true if any camera-related action is in progress (move, fast move, rotate or zoom). Implemented by checking each ProxyAction.IsInProgress().
Constructors
public CameraInput()
No explicit constructor logic is defined in the source. This is a MonoBehaviour-derived component and should be initialized by calling Initialize() (for binding the input actions) from Awake/Start or equivalent.
Methods
public void Initialize()
Binds the ProxyAction fields by finding actions on the InputManager. Specifically it calls:- InputManager.instance.FindAction("Camera", "Move")
- InputManager.instance.FindAction("Camera", "Move Fast")
- InputManager.instance.FindAction("Camera", "Rotate")
-
InputManager.instance.FindAction("Camera", "Zoom")
Call this once (e.g., in Awake or Start) before using Refresh() or reading the input properties. -
public void Refresh()
Reads current input values from the ProxyAction objects and updates the public properties: - move = MathUtils.MaxAbs(m_MoveAction.ReadValue
(), m_FastMoveAction.ReadValue ()) - rotate = m_RotateAction.ReadValue
() - zoom = m_ZoomAction.ReadValue
()
Should be called regularly (e.g., from Update) to keep the exposed properties up to date.
Usage Example
using UnityEngine;
using Game;
public class CameraInputExample : MonoBehaviour
{
private CameraInput camInput;
void Awake()
{
camInput = gameObject.AddComponent<CameraInput>();
// Optional: tweak smoothing values
camInput.m_MoveSmoothing = 0.08f;
camInput.m_RotateSmoothing = 0.05f;
camInput.m_ZoomSmoothing = 0.1f;
camInput.Initialize(); // bind input actions
}
void Update()
{
camInput.Refresh(); // read latest input
Vector2 move = camInput.move;
Vector2 rotate = camInput.rotate;
float zoom = camInput.zoom;
// Example: apply move to transform (simple immediate translation)
Vector3 translation = new Vector3(move.x, 0f, move.y) * Time.deltaTime * 10f;
transform.Translate(translation, Space.World);
// Use camInput.isMoving or camInput.any to check input state
if (camInput.isMoving) {
// perform logic while panning
}
}
}
Notes:
- ProxyAction and InputManager are part of the game's input framework. ProxyAction provides IsInProgress() and ReadValue