Game.UI.InGame.CameraUISystem
Assembly: Game
Namespace: Game.UI.InGame
Type: class
Base: UISystemBase
Summary:
CameraUISystem is a UI-facing ECS system that exposes and controls which in-game entity the camera is following. It registers UI data bindings (a getter binding for the currently focused entity and a trigger binding to request focus changes) and coordinates with the CameraUpdateSystem to switch or synchronize camera controllers (orbit vs gameplay). It performs null checks to avoid operating when camera controllers are not available.
Fields
-
private const string kGroup = "camera"
Identifier/group name used when registering UI bindings. Both the getter and trigger bindings use this group ("camera"). -
private CameraUpdateSystem m_CameraUpdateSystem
Reference to the CameraUpdateSystem retrieved from the ECS world (via GetOrCreateSystemManaged). Used to read controllers (orbitCameraController, gamePlayController, activeCameraController) and to change which controller is active or matched. -
private GetterValueBinding<Entity> m_FocusedEntityBinding
Stores the GetterValueBinding that provides the currently focused Entity to UI consumers. This binding is created in OnCreate with the key ("camera", "focusedEntity") and a delegate to GetFocusedEntity, and is updated each OnUpdate.
Properties
- This type exposes no public properties.
Constructors
public CameraUISystem()
Default constructor. Marked with [Preserve] in the source, but performs no custom initialization beyond what the base does; primary initialization is done in OnCreate.
Methods
protected override void OnCreate()
: System.Void
Initializes UI bindings and caches the CameraUpdateSystem instance. Specifically:- Adds a GetterValueBinding
for ("camera", "focusedEntity") that calls GetFocusedEntity. - Adds a TriggerBinding
for ("camera", "focusEntity") that calls FocusEntity when the UI triggers it. - Retrieves/stores the CameraUpdateSystem via base.World.GetOrCreateSystemManaged
().
The method is annotated with [Preserve] in the source.
protected override void OnUpdate()
: System.Void
Called each frame to update the getter binding (m_FocusedEntityBinding.Update()) so the UI receives the latest focused entity value.
The method is annotated with [Preserve] in the source.
-
private Entity GetFocusedEntity()
: Entity
Getter used by the binding to return the currently followed entity. If the orbitCameraController is null (not available), returns Entity.Null; otherwise returns orbitCameraController.followedEntity. -
private void FocusEntity(Entity entity)
: System.Void
Trigger handler invoked by the "focusEntity" binding to change focus: - If a non-null entity is provided and an orbitCameraController exists and it is not already following that entity:
- Sets orbitCameraController.followedEntity to the provided entity.
- Calls orbitCameraController.TryMatchPosition(activeCameraController) to align its position to the previous active camera.
- Sets activeCameraController to the orbitCameraController (switches to orbit mode).
- If Entity.Null is provided and the current activeCameraController is the orbitCameraController:
- Calls gamePlayController.TryMatchPosition(orbitCameraController) to align gameplay camera to the orbit camera.
- Sets activeCameraController to the gamePlayController (switches back to gameplay controller).
The method performs null checks and only switches controllers when appropriate.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Create a getter binding that exposes the currently focused entity to the UI under "camera"/"focusedEntity".
AddBinding(m_FocusedEntityBinding = new GetterValueBinding<Entity>("camera", "focusedEntity", GetFocusedEntity));
// Create a trigger binding that allows UI to request focusing an entity via "camera"/"focusEntity".
AddBinding(new TriggerBinding<Entity>("camera", "focusEntity", FocusEntity));
// Cache the CameraUpdateSystem for controller access and switching.
m_CameraUpdateSystem = base.World.GetOrCreateSystemManaged<CameraUpdateSystem>();
}
Additional notes: - This system relies on CameraUpdateSystem and its fields: orbitCameraController, gamePlayController, and activeCameraController. Those controllers must implement TryMatchPosition and expose followedEntity for full functionality. - Bindings use the Colossal.UI.Binding API (GetterValueBinding and TriggerBinding) so UI code can read the current focused entity and request focus changes. - The system uses Entity.Null to represent "no focused entity" and guards against null controller references before manipulating camera controllers.