Game.Rendering.IGameCameraController
Assembly: Assembly-CSharp
Namespace: Game.Rendering
Type: Interface
Base: None (interface)
Summary:
Interface that defines the contract for a game camera controller used by the rendering system. Implementations expose position, pivot, rotation and zoom control, enable/disable flags for controller and input, access to the underlying Cinemachine virtual camera, and a reference-returned LensSettings for direct lens manipulation. Typical implementations bridge user input, game logic and a Cinemachine camera to drive the in-game camera.
Fields
- This interface declares no fields.
{{ The interface only defines properties and methods; any backing fields will be present in concrete implementations. }}
Properties
-
float zoom { get; set; }
{{ Current camera zoom level. The concrete controller should translate this value into Cinemachine/Unity camera field-of-view or orthographic size as appropriate. }} -
Vector3 pivot { get; set; }
{{ The pivot point around which the camera may orbit or perform rotations. Typically used as the focus point in world coordinates. }} -
Vector3 position { get; set; }
{{ World-space position of the camera or the Cinemachine virtual camera's position target. Setting this should move the camera to a specified location. }} -
Vector3 rotation { get; set; }
{{ Euler rotation for the camera in degrees (usually in world or local space depending on implementation). Implementations should document whether this represents camera pitch/yaw/roll and their order. }} -
bool controllerEnabled { get; set; }
{{ Master enable flag for the controller logic. When false, the controller should not drive camera movement/logic. }} -
bool inputEnabled { get; set; }
{{ Enables or disables processing of user input for camera control. Can be used to temporarily lock input while UI is active or during scripted camera moves. }} -
ICinemachineCamera virtualCamera { get; }
{{ Read-only reference to the underlying Cinemachine virtual camera used by the controller. Useful for reading runtime camera properties or interacting with Cinemachine-specific APIs. Note: this is an interface type from Cinemachine. }} -
ref LensSettings lens { get; }
{{ Returns a by-reference LensSettings structure (Cinemachine) so callers or implementors can directly read or modify lens parameters (e.g., field of view, near/far clip) without copying. Use with caution — modifying the returned ref affects the controller's lens immediately. }}
Constructors
- Interfaces do not declare constructors.
{{ Concrete implementations will provide constructors or Unity lifecycle methods (e.g., Awake/Start) as needed. }}
Methods
-
void TryMatchPosition(IGameCameraController other)
{{ Attempts to match the current controller's camera transform (position, rotation, pivot, zoom and/or lens) to the provided other controller. Intended for syncing two controllers (for example when switching camera modes) so the transition is seamless. Implementations should define what aspects are matched and whether smoothing is applied. }} -
void UpdateCamera()
{{ Called to update the camera state each frame (or on demand). Implementations should apply input, update Cinemachine targets, apply smoothing, handle collision/obstacle avoidance, and push computed values to the Unity/Cinemachine camera. If used in Unity, this is typically invoked from a manager or MonoBehaviour Update / LateUpdate. }}
Usage Example
using Cinemachine;
using UnityEngine;
using Game.Rendering;
// Minimal example implementation of IGameCameraController
public class SimpleGameCameraController : MonoBehaviour, IGameCameraController
{
public float zoom { get; set; }
public Vector3 pivot { get; set; }
public Vector3 position { get; set; }
public Vector3 rotation { get; set; }
public bool controllerEnabled { get; set; } = true;
public bool inputEnabled { get; set; } = true;
// assign in inspector or via code
[SerializeField] private CinemachineVirtualCameraBase _vcam;
public ICinemachineCamera virtualCamera => _vcam;
public ref LensSettings lens => ref _vcam.m_Lens; // example; actual access may vary with Cinemachine version
void Start()
{
// initialize values
pivot = Vector3.zero;
position = transform.position;
rotation = transform.eulerAngles;
zoom = 1f;
}
void LateUpdate()
{
if (!controllerEnabled) return;
UpdateCamera();
}
public void TryMatchPosition(IGameCameraController other)
{
if (other == null) return;
// simple immediate match
position = other.position;
rotation = other.rotation;
pivot = other.pivot;
zoom = other.zoom;
// apply immediately to transform / virtual camera
ApplyToCamera();
}
public void UpdateCamera()
{
if (inputEnabled)
{
// example input: zoom in/out with mouse wheel
zoom += Input.mouseScrollDelta.y * 0.1f;
zoom = Mathf.Clamp(zoom, 0.1f, 10f);
}
ApplyToCamera();
}
private void ApplyToCamera()
{
transform.position = position;
transform.eulerAngles = rotation;
// interact with Cinemachine if available
if (_vcam != null)
{
// example: adjust field of view via lens
lens.FieldOfView = Mathf.Lerp(30f, 90f, Mathf.InverseLerp(0.1f, 10f, zoom));
// ensure virtual camera target matches pivot, etc., depending on implementation
}
}
}
{{ Notes: Implementations may differ depending on Cinemachine and Unity versions used by Cities: Skylines 2. Be careful when returning refs (ref LensSettings) — modify via ref only when you understand the lifetime and threading model. Ensure any direct Cinemachine field access (like _vcam.m_Lens) matches the Cinemachine API available in your target assembly. }}