Table of Contents

Interface IPluginContext

Namespace
KeenEyes
Assembly
KeenEyes.Abstractions.dll

Interface for plugin context that provides access to system registration and extension APIs.

public interface IPluginContext

Examples

public void Install(IPluginContext context)
{
    // Register systems - these are tracked for automatic cleanup
    context.AddSystem<PhysicsSystem>(SystemPhase.FixedUpdate);

    // Expose a custom API through extensions
    context.SetExtension(new PhysicsWorld());

    // Request capabilities for advanced functionality
    if (context.TryGetCapability<ISystemHookCapability>(out var hooks))
    {
        hookSubscription = hooks.AddSystemHook(
            beforeHook: (system, dt) => /* ... */,
            afterHook: (system, dt) => /* ... */
        );
    }
}

Remarks

The plugin context is passed to Install(IPluginContext) and Uninstall(IPluginContext) methods, providing access to the world and APIs for registering systems and extensions.

Systems registered through the context are tracked and automatically cleaned up when the plugin is uninstalled. Extensions set through the context are stored in the world and can be retrieved by other code.

Plugins that need advanced functionality should use capabilities via GetCapability<T>() or TryGetCapability<T>(out T) instead of casting World to concrete types. This enables better testability with mock implementations.

Properties

Plugin

Gets the plugin that this context is for.

IWorldPlugin Plugin { get; }

Property Value

IWorldPlugin

World

Gets the world that the plugin is being installed into or uninstalled from.

IWorld World { get; }

Property Value

IWorld

Methods

AddSystem(ISystem, SystemPhase, int)

Registers a system instance with the world at the specified phase and order.

ISystem AddSystem(ISystem system, SystemPhase phase = SystemPhase.Update, int order = 0)

Parameters

system ISystem

The system instance to register.

phase SystemPhase

The execution phase for this system. Defaults to Update.

order int

The execution order within the phase. Lower values execute first. Defaults to 0.

Returns

ISystem

The system instance for chaining.

AddSystem(ISystem, SystemPhase, int, Type[], Type[])

Registers a system instance with the world at the specified phase, order, and dependency constraints.

ISystem AddSystem(ISystem system, SystemPhase phase, int order, Type[] runsBefore, Type[] runsAfter)

Parameters

system ISystem

The system instance to register.

phase SystemPhase

The execution phase for this system.

order int

The execution order within the phase. Lower values execute first.

runsBefore Type[]

Types of systems that this system must run before.

runsAfter Type[]

Types of systems that this system must run after.

Returns

ISystem

The system instance for chaining.

AddSystemGroup(SystemGroup, SystemPhase, int)

Registers a system group with the world at the specified phase and order.

SystemGroup AddSystemGroup(SystemGroup group, SystemPhase phase = SystemPhase.Update, int order = 0)

Parameters

group SystemGroup

The system group to register.

phase SystemPhase

The execution phase for this group. Defaults to Update.

order int

The execution order within the phase. Lower values execute first. Defaults to 0.

Returns

SystemGroup

The system group for chaining.

AddSystem<T>(SystemPhase, int)

Registers a system with the world at the specified phase and order.

T AddSystem<T>(SystemPhase phase = SystemPhase.Update, int order = 0) where T : ISystem, new()

Parameters

phase SystemPhase

The execution phase for this system. Defaults to Update.

order int

The execution order within the phase. Lower values execute first. Defaults to 0.

Returns

T

The created system instance.

Type Parameters

T

The system type to register.

Remarks

Systems registered through this method are tracked and will be automatically removed and disposed when the plugin is uninstalled.

AddSystem<T>(SystemPhase, int, Type[], Type[])

Registers a system with the world at the specified phase, order, and dependency constraints.

T AddSystem<T>(SystemPhase phase, int order, Type[] runsBefore, Type[] runsAfter) where T : ISystem, new()

Parameters

phase SystemPhase

The execution phase for this system.

order int

The execution order within the phase. Lower values execute first.

runsBefore Type[]

Types of systems that this system must run before.

runsAfter Type[]

Types of systems that this system must run after.

Returns

T

The created system instance.

Type Parameters

T

The system type to register.

GetCapability<T>()

Gets a capability from the plugin context.

T GetCapability<T>() where T : class

Returns

T

The capability implementation.

Type Parameters

T

The capability interface type.

Remarks

Capabilities provide access to advanced functionality without requiring plugins to cast to concrete types. Common capabilities include:

  • ISystemHookCapability - Add hooks to system execution
  • IPersistenceCapability - Configure persistence settings

Use TryGetCapability<T>(out T) if the capability is optional for your plugin.

Exceptions

InvalidOperationException

Thrown when the capability is not available.

GetExtension<T>()

Gets an extension registered with the world.

T GetExtension<T>() where T : class

Returns

T

The extension instance.

Type Parameters

T

The extension type.

Exceptions

InvalidOperationException

Thrown when the extension is not registered.

HasCapability<T>()

Checks if a capability is available in this context.

bool HasCapability<T>() where T : class

Returns

bool

True if the capability is available; false otherwise.

Type Parameters

T

The capability interface type.

RegisterComponent<T>(bool)

Registers a component type with the world.

void RegisterComponent<T>(bool isTag = false) where T : struct, IComponent

Parameters

isTag bool

Whether this component is a tag (zero-size) component.

Type Parameters

T

The component type to register.

Remarks

Component types are typically registered automatically when first used, but plugins may need to register components explicitly if they use dynamic component access or need to ensure a component type is available.

RemoveExtension<T>()

Removes an extension from the world.

bool RemoveExtension<T>() where T : class

Returns

bool

True if the extension was found and removed; false otherwise.

Type Parameters

T

The extension type to remove.

SetExtension<T>(T, bool)

Sets an extension value that can be retrieved by other code.

void SetExtension<T>(T extension, bool owned = true) where T : class

Parameters

extension T

The extension instance to store.

owned bool

When true (the default) the world takes ownership of the instance and disposes it (if it implements IDisposable) when it is replaced, removed, or the world is disposed. Pass false when registering an instance the plugin does not own (for example a caller-supplied or shared object owned by another plugin) so it is never disposed by the world on removal.

Type Parameters

T

The extension type.

Remarks

Extensions allow plugins to expose custom APIs to application code. For example, a physics plugin might expose a PhysicsWorld extension that provides raycast and collision query methods.

TryGetCapability<T>(out T)

Tries to get a capability from the plugin context.

bool TryGetCapability<T>(out T capability) where T : class

Parameters

capability T

When this method returns, contains the capability if available.

Returns

bool

True if the capability is available; false otherwise.

Type Parameters

T

The capability interface type.

Remarks

Use this method when a capability is optional for your plugin's functionality. For required capabilities, use GetCapability<T>() which throws if unavailable.

TryGetExtension<T>(out T)

Tries to get an extension registered with the world.

bool TryGetExtension<T>(out T extension) where T : class

Parameters

extension T

When this method returns, contains the extension if found.

Returns

bool

True if the extension is registered; false otherwise.

Type Parameters

T

The extension type.