MuharremTozan/Agentic-Duel / .agent/skills/unity-event-bus
unity-event-bus
VerifiedAdvanced code-driven event bus with reflection-based bootstrapping. Provides zero-setup global messaging.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.2 KB |
| assets/code/EventBusBootstrapper.cs.txt | markdown | 2.0 KB |
| assets/code/EventBusCore.cs.txt | markdown | 1.6 KB |
| assets/code/EventBusExample.cs.txt | markdown | 1.3 KB |
| assets/docs/Checklist.md.txt | markdown | 950 B |
| references/guide.md | markdown | 1.6 KB |
references/guide.md
View on GitHub# Advanced Event Bus Guide
The Advanced Event Bus is a global, type-safe messaging system for Unity. Unlike Event Channels (which use ScriptableObjects), the Event Bus uses **static generic indices** and **Reflection** to decouple components without any Inspector setup.
## 1. When to Use
- **System-to-System Communication**: High-frequency messaging between core managers.
- **Zero-Setup Architectures**: When you want to add events without creating `.asset` files.
- **Data-Heavy Events**: Sending complex structs through the system with zero garbage collection.
## 2. Core Concepts
- **IEvent**: The message (must be a `struct` or `class`).
- **EventBus<T>**: The static hub for a specific event type.
- **EventBinding<T>**: The connection between your code and the bus.
## 3. How to Implement
### Step 1: Define an Event
```csharp
public struct HealthChangedEvent : IEvent {
public float CurrentHealth;
}
```
### Step 2: Create and Register a Binding
Inside your MonoBehaviour's `OnEnable`:
```csharp
private EventBinding<HealthChangedEvent> _healthBinding;
void OnEnable() {
_healthBinding = new EventBinding<HealthChangedEvent>(e => Debug.Log(e.CurrentHealth));
EventBus<HealthChangedEvent>.Register(_healthBinding);
}
```
### Step 3: Raise the Event
```csharp
EventBus<HealthChangedEvent>.Raise(new HealthChangedEvent { CurrentHealth = 50f });
```
## 4. Performance & Cleanup
- **Structs**: Use `struct` for events to avoid Heap allocations (GC-friendly).
- **Auto-Cleanup**: The `EventBusBootstrapper` automatically clears all static references when you exit Play Mode in the Editor, preventing memory leaks in the Unity Editor.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |