ParagonSubsystemExtensions

Static extension methods for IParagonSubsystem<TBehaviour> that provide convenient access to the component subsystem API. All methods delegate to the corresponding ParagonSubsystem methods, allowing game code to call component operations directly on the behaviour.

Definition

Namespace: Paragon Assembly: Paragon.dll

public static class ParagonSubsystemExtensions

Remarks

These extensions exist to simplify the common pattern of accessing a behaviour's subsystem. They use the prefix Subcomponent (instead of Component) to avoid naming collisions with Unity's built-in GetComponent<T>(), TryGetComponent<T>(), etc.

All methods have the constraint where TBehaviour : class, IParagonSubsystem<TBehaviour>, matching the CRTP pattern of the subsystem system.

Quick Lookup

Goal
Extension Method
Delegates To

Initialize subsystem

behaviour.InitializeSubsystem()

Subsystem.Initialize()

Add a component

behaviour.AddSubcomponent(component)

Subsystem.AddComponent(component)

Get by type (runtime)

behaviour.GetSubcomponent(type)

Subsystem.GetComponent(type)

Get by type (generic)

behaviour.GetSubcomponent<TBehaviour, TComponent>()

Subsystem.GetComponent<TComponent>()

Try get by type (runtime)

behaviour.TryGetSubcomponent(type, out component)

Subsystem.TryGetComponent(type, out component)

Try get by type (generic)

behaviour.TryGetSubcomponent<TBehaviour, TComponent>(out component)

Subsystem.TryGetComponent(out component)

Check existence (runtime)

behaviour.HasSubcomponent(type)

Subsystem.HasComponent(type)

Check existence (generic)

behaviour.HasSubcomponent<TBehaviour, TComponent>()

Subsystem.HasComponent(typeof(TComponent))

Remove by type (runtime)

behaviour.RemoveSubcomponent(type, out component)

Subsystem.RemoveComponent(type, out component)

Remove by type (generic)

behaviour.RemoveSubcomponent<TBehaviour, TComponent>(out component)

Subsystem.RemoveComponent(out component)

Get all components

behaviour.GetAllSubcomponents()

Subsystem.Cast<IParagonComponent<TBehaviour>>()

Methods

InitializeSubsystem

Initializes all components in the behaviour's subsystem.

AddSubcomponent

Adds a component to the behaviour's subsystem.

Parameter
Type
Description

component

IParagonComponent<TBehaviour>

The component to add

GetSubcomponent (Type)

Gets a component by runtime type.

Parameter
Type
Description

type

Type

The component type to look up

Returns: The component instance, or null if not found.

GetSubcomponent<TBehaviour, TComponent>

Gets a component by generic type.

Returns: The component instance cast to TComponent, or null if not found.

TryGetSubcomponent (Type)

Attempts to get a component by runtime type.

Returns: true if the component was found.

TryGetSubcomponent<TBehaviour, TComponent>

Attempts to get a component by generic type.

Returns: true if the component was found.

HasSubcomponent (Type)

Checks if a component of the given type exists.

Returns: true if the component exists.

HasSubcomponent<TBehaviour, TComponent>

Checks if a component of the given generic type exists.

Returns: true if the component exists.

RemoveSubcomponent (Type)

Removes a component by runtime type.

Returns: true if the component was found and removed.

RemoveSubcomponent<TBehaviour, TComponent>

Removes a component by generic type.

Returns: true if the component was found and removed.

GetAllSubcomponents

Returns all components in the subsystem, cast to IParagonComponent<TBehaviour>.

Returns: An enumerable of all components.

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Typical Usage

See Also

Last updated