Dependency Package
On GitHUb
If you’re tired to drag and drop every bit of component references in the editor, this package is for you.
Simplified dependency injection for Unity utilizing source generation making it as performant as possible.
You can find game objects through names or tags, components, list or array of components, and have many other decorators to find the targeted component you need.
I’m looking forward any and all feedback or if you have any idea for useful additions to this package, feel free to discuss it below, I will consider every ideas.
You can install through GitHub here: Lurking Ninja’s Dependency
Basic usage is super simple, just decorate your fields and properties:
using LurkingNinja.Attributes;
using UnityEngine;
namespace DoTest
{
[GenerateOnValidate]
public partial class DiTest : MonoBehaviour
{
[Get][SerializeField]
private BoxCollider[] get_BoxColliders;
[Get][field: SerializeField]
private SphereCollider GetOnProperty_SphereCollider { get; set; }
[FindWithTag("MainCamera")][SerializeField]
private Camera getByTag_MainCamera;
[GetInChildren][IncludeInactive][SerializeField]
private AudioSource getInChild_AudioSource;
[GetInChildren][IncludeInactive][IgnoreSelf][SerializeField]
private AudioSource[] getInChildren_AudioSource;
}
}
And enjoy the inspector fill itself up with references:
The latest version on GitHub
Changelog
All notable changes to this project will be documented in this file.
[0.0.5] - 2024-01-10
- [Add] attribute
TODO
- Reintroduce asset referencing (GetInAssets)
- Develop filtering
- Add C# class ([Depends] - [Provides]) dependency injection
- Check if we can have a [Require] attribute for entries (throwing warning or error in console).
[0.0.4] - 2024-01-09 - Release (Download)
Changed
- Documentation updated
TODO
- Reintroduce asset referencing (GetInAssets)
- Develop filtering
- Add C# class ([Depends] - [Provides]) dependency injection
[0.0.3] - 2024-01-09
Added
- DiTestHelpers
- StableSort
- Tests added
TODO
- Reintroduce asset referencing (GetInAssets)
- Develop filtering
- Update documentation
[0.0.2] - 2024-01-08
Added
- Find
- FindWithTag
- GenerateAwake
- GenerateInitializers
- GenerateOnValidate
- InjectInEditor
- InjectInRuntime
Removed
- GetByName - use the combination of Find and Get
- GetByTag - use the combination of FindWithTag and Get
- GetInAssets - will be introduced on another way in the future
- InjectInPlay - replaced with InjectInRuntime
- Placeholder files in package folder
TODO
- Reintroduce asset referencing (GetInAssets)
- Develop filtering
- Add bool SortByInstanceId optional parameter to Find
- Update documentation
- Move test over to public
[0.0.1] - 2024-01-03 - Release (Download)
Added
- Get attribute
- GetByName attribute
- GetByTag attribute
- GetInAssets attribute
- GetInChildren attribute
- GetInParent attribute
- IgnoreSelf attribute
- IncludeInactive attribute
- InjectInPlay attribute
- SkipNullCheck attribute
TODO
- FindWithTag attribute