unity-dependency-injection
Unity Dependency Injection (DI)
A lightweight system to satisfy the "D" in SOLID. Allows classes to request dependencies via [Inject] without knowing who provides them.
Core Features
- Attribute-Based Injection: Use
[Inject]to mark fields and[Provide]to define sources. - Interface Focus: Encourages programming to abstractions, making systems hot-swappable.
- Automated Wiring: Scene-wide injection happens on Awake, ensuring dependencies are ready before Start.
- Diagnostic Logging: Tracks successful injections and warns about missing providers.
Core Files (Max 3)
DIAttributes.cs.txt: Contains the marker attributes for the compiler.DependencyInjector.cs.txt: The engine that finds and wires dependencies in the scene.DIExample.cs.txt: Shows how to decouple a Hero from an AbilitySystem.
Usage
1. Define an Interface
public interface IWeapon { void Fire(); }
2. Provide the Implementation
public class PlasmaRifle : MonoBehaviour, IWeapon {
[Provide] public IWeapon GetWeapon() => this;
public void Fire() { /* ... */ }
}
3. Inject into Client
public class Player : MonoBehaviour {
[Inject] private IWeapon currentWeapon;
void Start() => currentWeapon.Fire();
}
4. Setup
Place a DependencyInjector component in your scene or persistent prefab.
More from muharremtozan/unity-agent-skills
unity-so-prefab-manager
Manages the structured relationship between ScriptableObjects (Data) and Prefabs (Logic/Visuals) in Unity 6. Follows the 'SO-to-Mono' Bridge pattern to ensure instance independence (e.g., individual health for identical robots) while maintaining a clean, data-driven architecture. Use when: (1) Creating new unit/item types, (2) Wiring SO data to Prefab MonoBehaviours, (3) Resolving data-sharing bugs where changing one SO affects all instances.
16unity-fsm
Specialized skill for implementing a robust, extensible Finite State Machine in Unity using the State and Strategy patterns. Based on the pattern by Adam Myhre (3D Platformer). Use when creating complex AI, player controllers, or any system requiring structured state management.
11unity-code-reviewer
Professional Unity C# Code Reviewer. Detects anti-patterns, performance leaks, and enforces project-specific architecture.
10unity-assembly-management
Manage project boundaries using Assembly Definitions (.asmdef) for faster compile times and modular architecture. Based on the patterns by Adam Myhre. Enforces responsibility-based organization and handles Runtime/Editor/Tests splits.
9unity-event-bus
Advanced code-driven event bus with reflection-based bootstrapping. Provides zero-setup global messaging.
9unity-ui-data-binding
Implementation of MVVM-style Data Binding for Unity UI Toolkit using the [CreateProperty] attribute and BindableProperty wrappers.
9