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 ParagonSubsystemExtensionsRemarks
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
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.
component
IParagonComponent<TBehaviour>
The component to add
GetSubcomponent (Type)
Gets a component by runtime type.
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
Subsystem must exist All extension methods access behaviour.Subsystem without null checking. If HasSubsystem is false, these methods will throw NullReferenceException. Ensure the subsystem is created before calling any extension method.
Two type parameters required for generic overloads Due to C# generic inference limitations, the generic overloads require both TBehaviour and TComponent type parameters. The compiler cannot infer TBehaviour from the this parameter alone when TComponent is specified:
Examples
Typical Usage
See Also
IParagonSubsystem<TBehaviour> — the interface these extensions target
ParagonSubsystem — the underlying API
IParagonComponent<TBehaviour> — the component interface
Extensions Overview — subfolder overview
Last updated