ParagonSubsystem

Abstract component container that manages a Dictionary<Type, IParagonComponent> collection. Provides add, get, remove, and query operations for components, and initializes all components when Initialize() is called. The sealed generic variant ParagonSubsystem<TSystem> provides type-safe ownership.

Definition

Namespace: Paragon Assembly: Paragon.dll

Abstract Base

[Serializable]
public abstract class ParagonSubsystem : ParagonObject, IEnumerable<IParagonComponent>

Inherits: ParagonObject Implements: IEnumerable<IParagonComponent>

Generic Variant

public sealed class ParagonSubsystem<TSystem> : ParagonSubsystem
    where TSystem : class, IParagonSubsystem<TSystem>

Inherits: ParagonSubsystem

Remarks

ParagonSubsystem implements the composition-over-inheritance pattern for Paragon behaviours. Instead of building complex inheritance hierarchies, behaviours can attach modular components to a subsystem.

Components are stored in a Dictionary<Type, IParagonComponent>, keyed by the component's concrete type. This means:

  • Each component type can only exist once per subsystem

  • Component lookup is O(1) by type

  • Components are iterable via IEnumerable<IParagonComponent>

The generic variant ParagonSubsystem<TSystem> constrains the owner type using the curiously recurring template pattern (CRTP): TSystem : class, IParagonSubsystem<TSystem>. This ensures type-safe ownership — components know their owner's exact type.

Quick Lookup

Goal
How

Create a subsystem

new ParagonSubsystem<MyBehaviour>(owner)

Add a component

subsystem.AddComponent(component)

Get a component

subsystem.GetComponent<MyComponent>()

Try-get a component

subsystem.TryGetComponent<MyComponent>(out var c)

Check for component

subsystem.HasComponent<MyComponent>()

Remove a component

subsystem.RemoveComponent<MyComponent>(out var c)

Initialize all

subsystem.Initialize()

Iterate components

foreach (var c in subsystem) { ... }

Clear all components

subsystem.Clear()

Properties

Owner

The IParagonBehaviour that owns this subsystem.

Constructor

ParagonSubsystem (abstract base)

Parameter
Type
Description

owner

IParagonBehaviour

The behaviour that owns this subsystem

ParagonSubsystem<TSystem>

Parameter
Type
Description

owner

TSystem

The strongly-typed behaviour that owns this subsystem

Methods

Initialize

Initializes all components in the subsystem by calling Initialize() on each one.

circle-exclamation

AddComponent

Adds a component to the subsystem, keyed by its concrete type. Calls OnAdded() on the component.

Parameter
Type
Description

component

IParagonComponent

The component to add

circle-exclamation

GetComponent (by Type)

Returns the component of the specified type, or null if not found.

GetComponent<TComponent>

Returns the component of the specified type, or null if not found.

TryGetComponent (by Type)

Attempts to retrieve a component by type.

Returns: true if the component exists.

TryGetComponent<TComponent>

Attempts to retrieve a strongly-typed component.

Returns: true if the component exists and is of the correct type.

RemoveComponent (by Type)

Removes a component by type. Calls OnRemoved() on the component.

Returns: true if the component was found and removed.

RemoveComponent<TComponent>

Removes a strongly-typed component. Calls OnRemoved() on the component.

Returns: true if the component was found and removed.

HasComponent (by Type)

Checks whether a component of the given type exists.

HasComponent<TComponent>

Checks whether a component of the given type exists.

Clear

Removes all components from the subsystem without calling OnRemoved().

circle-exclamation

GetEnumerator

Enumerates all components in the subsystem.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Setting up a subsystem

Querying components

See Also

Last updated