Skip to content

Game.CinemachineGameAxisProvider

Assembly: Assembly-CSharp (typical Unity game assembly)
Namespace: Game

Type: class

Base: UnityEngine.MonoBehaviour, Cinemachine.AxisState.IInputAxisProvider

Summary: A small adapter component that implements Cinemachine's AxisState.IInputAxisProvider by reading input from the game's InputManager actions. It maps the game's "Camera" actions ("Rotate" and "Zoom") to the axis indices used by Cinemachine so Cinemachine virtual cameras can receive player input via the game's input system.


Fields

  • private ProxyAction m_RotateAction
    Holds the ProxyAction returned by InputManager for the "Camera" -> "Rotate" action. Expected to provide a Vector2 value (x = horizontal rotation, y = vertical rotation).

  • private ProxyAction m_ZoomAction
    Holds the ProxyAction returned by InputManager for the "Camera" -> "Zoom" action. Expected to provide a float zoom value.

Properties

  • None.

Constructors

  • public CinemachineGameAxisProvider()
    Default MonoBehaviour constructor (no custom initialization here). Initialization is performed in Awake().

Methods

  • private void Awake()
    Finds and caches the input actions used for camera control:
  • m_RotateAction = InputManager.instance.FindAction("Camera", "Rotate");
  • m_ZoomAction = InputManager.instance.FindAction("Camera", "Zoom"); Note: InputManager.instance must be available when Awake runs; if InputManager is created later, consider initializing this component later or adding null checks.

  • public float GetAxisValue(int axis)
    Implements Cinemachine.AxisState.IInputAxisProvider.GetAxisValue. Returns an axis value based on the requested axis index:

  • axis == 0 -> returns m_RotateAction.ReadRawValue(disableAll: false).x (horizontal rotate)
  • axis == 1 -> returns m_RotateAction.ReadRawValue(disableAll: false).y (vertical rotate)
  • axis == 2 -> returns m_ZoomAction.ReadRawValue(disableAll: false) (zoom)
  • otherwise -> returns 0f

Behavior notes: - Uses ReadRawValue with disableAll: false to read values even if other input handling is present. - No null-checks are performed in the current implementation; if an action is missing, calling ReadRawValue may throw or return default value depending on ProxyAction implementation. Consider adding null checks or fallbacks for robustness.

Usage Example

Attach this component to a GameObject used by a Cinemachine virtual camera (or another object referenced by Cinemachine). In the Cinemachine component that accepts an IInputAxisProvider (for example when using a custom AxisState), assign this component as the input provider via the inspector or by script.

Example (attach component and let Cinemachine reference it via inspector):

// No additional scripting required in most cases. 
// Add CinemachineGameAxisProvider to the GameObject that the Cinemachine camera uses as input provider.

[Preserve]
private void Awake()
{
    // CinemachineGameAxisProvider will automatically find the "Camera" -> "Rotate" and "Zoom" actions.
}

Example (scripted assignment if needed):

// Suppose you have a Cinemachine component that exposes a field to set an IInputAxisProvider:
var axisProvider = cameraGameObject.GetComponent<Game.CinemachineGameAxisProvider>();
cinemachineComponent.inputAxisProvider = axisProvider; // pseudo-code; actual assignment depends on the Cinemachine component used

Notes and recommendations: - Ensure InputManager.instance and the "Camera" -> "Rotate"/"Zoom" actions exist before this component's Awake runs. - If you expect users to rebind actions at runtime, consider subscribing to action change events or re-querying InputManager when bindings change. - If you need additional axes, extend GetAxisValue to handle more indices and map them to appropriate actions.