Class PluginContext
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
Provides context for plugin installation and uninstallation operations.
public sealed class PluginContext : IPluginContext
- Inheritance
-
PluginContext
- Implements
-
IPluginContext
- Inherited Members
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());
// Access the world directly if needed (cast if concrete World is required)
context.World.SetSingleton(new PhysicsSettings { Gravity = -9.81f });
}
Remarks
The plugin context is passed to KeenEyes.IWorldPlugin.Install(KeenEyes.IPluginContext) and KeenEyes.IWorldPlugin.Uninstall(KeenEyes.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.
Properties
Plugin
Gets the plugin that this context is for.
public IWorldPlugin Plugin { get; }
Property Value
- IWorldPlugin
World
Gets the world that the plugin is being installed into or uninstalled from.
public World World { get; }
Property Value
Remarks
This property returns the concrete World type for full access to all world operations.
Methods
AddSystem(ISystem, SystemPhase, int)
Registers a system instance with the world at the specified phase and order.
public ISystem AddSystem(ISystem system, SystemPhase phase = SystemPhase.Update, int order = 0)
Parameters
systemISystemThe system instance to register.
phaseSystemPhaseThe execution phase for this system. Defaults to KeenEyes.SystemPhase.Update.
orderintThe 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.
public ISystem AddSystem(ISystem system, SystemPhase phase, int order, Type[] runsBefore, Type[] runsAfter)
Parameters
systemISystemThe system instance to register.
phaseSystemPhaseThe execution phase for this system.
orderintThe execution order within the phase. Lower values execute first.
runsBeforeType[]Types of systems that this system must run before.
runsAfterType[]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.
public SystemGroup AddSystemGroup(SystemGroup group, SystemPhase phase = SystemPhase.Update, int order = 0)
Parameters
groupSystemGroupThe system group to register.
phaseSystemPhaseThe execution phase for this group. Defaults to KeenEyes.SystemPhase.Update.
orderintThe 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.
public T AddSystem<T>(SystemPhase phase = SystemPhase.Update, int order = 0) where T : ISystem, new()
Parameters
phaseSystemPhaseThe execution phase for this system. Defaults to KeenEyes.SystemPhase.Update.
orderintThe execution order within the phase. Lower values execute first. Defaults to 0.
Returns
- T
The created system instance.
Type Parameters
TThe 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.
public T AddSystem<T>(SystemPhase phase, int order, Type[] runsBefore, Type[] runsAfter) where T : ISystem, new()
Parameters
phaseSystemPhaseThe execution phase for this system.
orderintThe execution order within the phase. Lower values execute first.
runsBeforeType[]Types of systems that this system must run before.
runsAfterType[]Types of systems that this system must run after.
Returns
- T
The created system instance.
Type Parameters
TThe system type to register.
GetCapability<T>()
Gets a capability from the plugin context.
public T GetCapability<T>() where T : class
Returns
- T
The capability implementation.
Type Parameters
TThe 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 executionIPersistenceCapability- Configure persistence settings
Use KeenEyes.IPluginContext.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.
public T GetExtension<T>() where T : class
Returns
- T
The extension instance.
Type Parameters
TThe extension type.
Exceptions
- InvalidOperationException
Thrown when the extension is not registered.
HasCapability<T>()
Checks if a capability is available in this context.
public bool HasCapability<T>() where T : class
Returns
- bool
True if the capability is available; false otherwise.
Type Parameters
TThe capability interface type.
RegisterComponent<T>(bool)
Registers a component type with the world.
public void RegisterComponent<T>(bool isTag = false) where T : struct, IComponent
Parameters
isTagboolWhether this component is a tag (zero-size) component.
Type Parameters
TThe 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.
public bool RemoveExtension<T>() where T : class
Returns
- bool
True if the extension was found and removed; false otherwise.
Type Parameters
TThe extension type to remove.
SetExtension<T>(T)
Sets an extension value that can be retrieved by other code.
public void SetExtension<T>(T extension) where T : class
Parameters
extensionTThe extension instance to store.
Type Parameters
TThe 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.
public bool TryGetCapability<T>(out T? capability) where T : class
Parameters
capabilityTWhen this method returns, contains the capability if available.
Returns
- bool
True if the capability is available; false otherwise.
Type Parameters
TThe capability interface type.
Remarks
Use this method when a capability is optional for your plugin's functionality. For required capabilities, use KeenEyes.IPluginContext.GetCapability<T>() which throws if unavailable.
TryGetExtension<T>(out T?)
Tries to get an extension registered with the world.
public bool TryGetExtension<T>(out T? extension) where T : class
Parameters
extensionTWhen this method returns, contains the extension if found.
Returns
- bool
True if the extension is registered; false otherwise.
Type Parameters
TThe extension type.